fitting a histogram with Gaussian and getting best fit data for mean and st dev from the fitted curve

I'm trying to obtain the mean (mu) and stand dev (sigma) for a Gaussian curve drawn to fit the histogram of a data set (see attached, "histogram sample.xlsx). I can generate a histogram with Guassian curve using, for instance,
>> pd = fitdist(x,'Normal')
pd =
NormalDistribution
Normal distribution
mu = 0.0266749 [0.0162315, 0.0371183]
sigma = 0.0945052 [0.0876766, 0.102496]
However, those values (mu, sigma) appear to be the values for the underlying complete data set, NOT for the Gaussian fit. The mean, stand deviation for the Gaussian fit are smaller, of course. Question: how to extract the mu and sigma for the fitted curve instead of the raw data.
For example, Graphpad Prism (a convenient statistics software) also gives mu = 0.0266749 and sigma = 0.0945052 for the same dataset:
Graphpad also fits a Gaussian and provies a best fit values for mu and sigma for the fitted curve, mu = 0.006117 and sigma = 0.04694:
I'd like to be able to extract these same data (best fit values) using MatLab but I don't know how to. Any help?

7 commentaires

In what sense do you want "best fit"?
Fitting moments is something that could be done.
I guess, I'd consider fitting mean and variance as parameters for a Gaussian.
By "best fit", I mean what are the values of mu and sigma for the fitted Gaussian curve, as in the GraphPad example (red curve). I'm not sure how else to explain this. The mu and sigma for the fitted red Gaussian curve are clearly (and appropriately) smaller than mu and sigma for the entire data set, I presume because the Gaussian curve de-emphasizes the outliers to the right (>bin 0.2 for example).
Do you have the curve fitting toolbox?
You can use the counts and bin centers to fit the Gaussian function to your data. The formula for it can be found on Wikipedia. You could use the first results of mean and sigma as your initial guess.
>> The mean, stand deviation for the Gaussian fit are smaller, of course.
?
Sorry, not sure why they would be smaller.
"Best fit" Gaussian, I guess would match in mean and standard deviation.
Minimum least means squares?
Minimum <some other critierion>?
Minimum absolute deviation.
KS best fit?
Rik, I can get the relevant toolbox if I don't already have it. But is there a MatLab function or script you can suggest rather than try to plug in something from Wikipedia?
If you have x-y data, you can fit it to the Gaussian function:
fun=@(x,scale,mu,sd) scale/sqrt(2*pi*sd^2)*exp(-(x-mu).^2/(2*sd^2));

Connectez-vous pour commenter.

Réponses (0)

Question posée :

le 7 Jan 2019

Commenté :

Rik
le 7 Jan 2019

Community Treasure Hunt

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

Start Hunting!

Translated by