Clear Filters
Clear Filters

histfit (histogram and normal function)

17 views (last 30 days)
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

Accepted Answer

Wayne King
Wayne King on 19 Jan 2012
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.

More Answers (4)

Image Analyst
Image Analyst on 19 Jan 2012
You mean like the plot() function? That can draw a line or curve.

Wayne King
Wayne King on 19 Jan 2012
Hi Silvia, histfit() with the 'normal' option does not use data which follows a Gaussian distribution, it uses the data you give it. If your data is non-Gaussian than the overlying fitted normal density will clearly not do a good job approximating your data histogram. For example:
x = chi2rnd(2,100,1);
histfit(x,[],'normal')
Note that in this case:
histfit(x,[],'gamma');
Does a much better job (of course).
Is this what you're asking?

Silvia
Silvia on 19 Jan 2012
So, If I understand histfit() uses my data (dataX), if my data is non-gaussian (normal) then 'histfit(dataX,[],'normal')won't do a good job. Nut now I have two questions: 1)Is there any function to know if my data is normal?? 2)In case is not normal can I make it normal?? and use histfit with that data??
3)I ask these questions because there is a lot of properties, I mean: weibull, lognormal,exponential .... and I don't know which is better for my data. Thank you very much

Brian Wilson
Brian Wilson on 19 Jan 2012
Hi Silvia,
if you have the statistics toolbox there are a bunch of helpful functions.
Try normplot and it plots the sorted data against the normal distribution CDF. The helpful feature here is that the scale is nonlinear so that the CDF looks like a straight line. you can then look to see how well your data fits the straight line.
There is also normfit with a bunch of metrics. Take a look at the documentation.

Community Treasure Hunt

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

Start Hunting!