MATLAB: Histfit (histogram and normal function)

histfit (histogram and normal function)

Good afternoon,
I have an histogram with data which I think it is not normal and I want to draw the normal density probability function over my histogram but the function I know 'histfit' uses normal data. Is there other functions which allow you to draw this curve with non normal data? or have I to convert my data to normal data? Thank you very much

Best Answer

Hi Silvia, You're correct. There are a number of ways you can assess fit. For example, you can use kstest() with a specified probability distribution to construct a hypothesis test.
PD = ProbDistUnivParam('gamma',[1/2 2]); %chisquare 1 dof
x = chi2rnd(1,100,1);
[h,p] = kstest(x,PD);
You can use fitdist() to estimate the parameters of the distribution from your data.
In this case:
Pd = fitdist(x,'gamma');
To know which distribution is "best". Well that's tougher. I mean often you have a model for your data which indicates which is probably the right family. Other times it's more empirical, you're looking at histograms or estimates of the probablity density, see ksdensity(), and then based on that you can select a model.