statsmodels.stats.diagnostic.kstest_fit

statsmodels.stats.diagnostic.kstest_fit(x, dist='norm', pvalmethod='table')[source]

Test assumed normal or exponential distribution using Lilliefors’ test.

Lilliefors’ test is a Kolmogorov-Smirnov test with estimated parameters.

Parameters:
xarray_like, 1d

Data to test.

dist{‘norm’, ‘exp’}, optional

The assumed distribution.

pvalmethod{‘approx’, ‘table’}, optional

The method used to compute the p-value of the test statistic. In general, ‘table’ is preferred and makes use of a very large simulation. ‘approx’ is only valid for normality. if dist = ‘exp’ table is always used. ‘approx’ uses the approximation formula of Dalal and Wilkinson, valid for pvalues < 0.1. If the pvalue is larger than 0.1, then the result of table is returned.

Returns:
ksstatfloat

Kolmogorov-Smirnov test statistic with estimated mean and variance.

pvaluefloat

If the pvalue is lower than some threshold, e.g. 0.05, then we can reject the Null hypothesis that the sample comes from a normal distribution.

Notes

‘table’ uses an improved table based on 10,000,000 simulations. The critical values are approximated using log(cv_alpha) = b_alpha + c[0] log(n) + c[1] log(n)**2 where cv_alpha is the critical value for a test with size alpha, b_alpha is an alpha-specific intercept term and c[1] and c[2] are coefficients that are shared all alphas. Values in the table are linearly interpolated. Values outside the range are be returned as bounds, 0.990 for large and 0.001 for small pvalues.

For implementation details, see lilliefors_critical_value_simulation.py in the test directory.


Last update: Oct 29, 2024