Histogram Fitting in Matlab

1 回表示 (過去 30 日間)
Umang Patel
Umang Patel 2019 年 10 月 10 日
編集済み: Umang Patel 2019 年 10 月 11 日
Hello,
How to do histogram fitting?

採用された回答

Jeff Miller
Jeff Miller 2019 年 10 月 11 日
First, I suggest you change the histogram plot so that the frequencies are represented by the areas of the different bars rather than the heights (this is more standard when the bars are different widths), like this:
A = histogram('BinEdges',bin_e,'BinCounts',MessData.profile(i).strip_current(idx),'Normalization','PDF');
Second, you can estimate distribution parameters from unequal bin widths with the Cupid toolbox. For example, add the following code after the modified histogram statement in your loop:
probs = MessData.profile(i).strip_current(idx); % I guess these are frequencies
probs = probs / sum(probs); % normalize to probabilities
bintops = bin_e(2:end); % EstChiSq just wants the tops of the different bins.
myNormal = Normal(0,1);
myNormal.EstChiSq(bintops,probs)
thisrangemin = myNormal.InverseCDF(0.001);
thisrangemax = myNormal.InverseCDF(0.999);
x = linspace(thisrangemin,thisrangemax,100);
pdf = myNormal.PDF(x);
hold on
plot(x,pdf); % Superimpose predicted curve on histogram
I attach the result for one of your datasets.
  2 件のコメント
Jeff Miller
Jeff Miller 2019 年 10 月 11 日
This error indicates that you did not install the Cupid toolbox:
Undefined function or variable 'Normal'.
You must do that to use the solution I suggested. Sorry if that wasn't clear in my original post.
Jeff Miller
Jeff Miller 2019 年 10 月 11 日
The parameter searching routine starts with the current values. For example, when you use
myNormal = Normal(0,1);
the parameter search always starts with mean 0 and standard deviation 1. If this mean and sd are very far off for the dataset that you are trying to fit, then the search routine will not converge properly on the best estimates. So, you need to look a little bit at your data and pick more realistic starting parameter values for your search. For example, you might use something like:
guessMu = (bintops(1) + bintops(end)) / 2;
guessSD = (bintops(end) - bintops(1)) / 5;
myNormal = Normal(guessMu,guessSD);

サインインしてコメントする。

その他の回答 (1 件)

J. Alex Lee
J. Alex Lee 2019 年 10 月 10 日
If you have access to the underlying data...
...and you have a model for the distribution, then you can just do parameter estimation based on the data. A common distribution should have well-established parameter estimation techniques. (your example looks normal, so mean() and std() would work well).
...and you have a model for the distribution but not a way to estimate parameters for it, you can try to force your histogram-generating function to use equal bin sizes, then proceed to do your curve fitting.
If you don't have access to the underlying data...
...maybe you can weight your residuals inversely to the bin widths?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by