Lilliefors

Lilliefors(sample, factory, level=0.05)

Perform a Lilliefors goodness-of-fit test for 1-d continuous distributions.

Refer to Kolmogorov-Smirnov fitting test.

Parameters
sample2-d sequence of float

Tested sample.

modelDistributionFactory

Tested distribution factory.

levelfloat, 0 \leq \alpha \leq 1, optional (default level = 0.05).

This is the risk \alpha of committing a Type I error, that is an incorrect rejection of a true null hypothesis.

Returns
fitted_distDistribution

Estimated distribution (if model is of type DistributionFactory).

test_resultTestResult

Test result.

Raises
TypeError :

If the distribution is not continuous or if the sample is multivariate.

Notes

The distribution is estimated using the given factory based on the given sample and the distribution of the test statistics is estimated using a Monte Carlo approach. This algorithm is known as Lilliefors’s test [Lilliefors1967]. The Monte Carlo algorithm can be configured with the following keys in ResourceMap:

  • FittingTest-LillieforsMinimumSamplingSize defining the minimum number of samples to generate in order to estimate the p-value. Default value is 10.

  • FittingTest-LillieforsMaximumSamplingSize defining the maximum number of samples to generate in order to estimate the p-value. Default value is 100000.

  • FittingTest-LillieforsPrecision defining the target standard deviation for the p-value estimate. Default value is 0.01.

Examples

>>> import openturns as ot
>>> ot.RandomGenerator.SetSeed(0)
>>> distribution = ot.Normal()
>>> sample = distribution.getSample(30)
>>> factory = ot.NormalFactory()
>>> ot.ResourceMap.SetAsScalar('FittingTest-LillieforsPrecision', 0.05)
>>> ot.ResourceMap.SetAsUnsignedInteger('FittingTest-LillieforsMinimumSamplingSize', 100)
>>> ot.ResourceMap.SetAsUnsignedInteger('FittingTest-LillieforsMaximumSamplingSize', 1000)
>>> fitted_dist, test_result = ot.FittingTest.Lilliefors(sample, factory)
>>> fitted_dist
class=Normal name=Normal dimension=1 mean=class=Point name=Unnamed dimension=1 values=[-0.0944924] sigma=class=Point name=Unnamed dimension=1 values=[0.989808] correlationMatrix=class=CorrelationMatrix dimension=1 implementation=class=MatrixImplementation name=Unnamed rows=1 columns=1 values=[1]
>>> test_result
class=TestResult name=Unnamed type=Lilliefors Normal binaryQualityMeasure=true p-value threshold=0.05 p-value=0.59 statistic=0.106933 description=[Normal(mu = -0.0944924, sigma = 0.989808) vs sample Normal]
>>> pvalue = test_result.getPValue()
>>> pvalue
0.59
>>> D = test_result.getStatistic()
>>> D
0.1069...
>>> quality = test_result.getBinaryQualityMeasure()
>>> quality
True