I am trying to model a dataset of mine with a lognormal distribution using Matlab. I estimated the parameters via 'lognfit' and my generated datapoints with the fitted distribution look quite good compared to the observed data.
To further verify, I wanted to use chi2gof to test the goodness-of-fit. Everything seems to work fine and the null hypothesis is not rejected but the p-value is NaN.
I am using the approach applied to the the Weibull distribution under http://www.mathworks.de/de/help/stats/chi2gof.html
So you can reproduce my result, this is an example that does not work.
>> test = lognrnd(-3.6299, 1.30985, 100, 1);
>> b = fitdist(test, 'Lognormal')
b =
LognormalDistribution
Lognormal distribution
mu = -3.62425 [-3.86888, -3.37962]
sigma = 1.2329 [1.08249, 1.43223]
>> [h, p, st] = chi2gof(test,'CDF', b)
h = 0
p = NaN
st =
chi2stat: 0.0183
df: 0
edges: [0.0015 0.2151 2.1372]
O: [94 6]
E: [93.6703 6.3297]
Also transforming the data to normal distributed datapoints and checking for a normal distribution results in a p-value of NaN.
I am thankful for any help!
Best regards
EDIT:
I was just able to make the transforming-to-normal approach to work:
Would still be nice to know if this approach is valid and why the original approach does not work.
>> test = lognrnd(-3.6299, 1.30985, 100, 1);
>> test = log(test);
>> b = fitdist(test, 'normal')
b =
NormalDistribution
Normal distribution
mu = -3.68114 [-3.92861, -3.43368]
sigma = 1.24717 [1.09502, 1.44881]
>> [h, p, st] = chi2gof(test, 'CDF', b)
h = 0
p = 0.5330
st =
chi2stat: 4.1149
df: 5
edges: [-6.1930 -5.5713 -4.9497 -4.3281 -3.7064 -3.0848 -2.4632 -1.8415 0.0234]
O: [8 7 18 16 17 20 8 6]
E: [6.4814 8.9730 14.7440 18.9931 19.1820 15.1883 9.4282 7.0101]