Histograms are widely used in exploratory data analysis. In some applications, such as Monte Carlo simulations, sometimes the data or the distribution manifest with corresponding weights, for example in the analysis of umbrella sampling results. In those situations weights of each data point should be taken into account in constructing histograms out of data points. If you are programming with R, weights package would help you to do this. Recently, I have added small utility function in mathworks file exchange called Generate Weighted Histograms to plot weighted histograms. In this post, I would like to demonstrate how these function can be used. Let's generate some synthetic data, which contains values and corresponding weights and find the weighted histogram.
1 2 3 4 5 6 7 | % Generate synthetic data myData.values = rand(100,1); myData.weights = rand(100,1); % Generate weighted histogram [histw, vinterval] = histwc(myData.values, myData.weights, 10); % Visualize bar(vinterval, histw) |
This trivial example demonstrate the usage of histwc function. One can adjust the bins as the third argument of the function.
No comments:
Post a Comment