File: plot_kolmogorov_test.py

package info (click to toggle)
openturns 1.26-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,708 kB
  • sloc: cpp: 261,605; python: 67,030; ansic: 4,378; javascript: 406; sh: 185; xml: 164; makefile: 101
file content (97 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
Use the Kolmogorov/Lilliefors test
==================================
"""

# %%
# In this example we are going to perform a Kolmogorov or a Lilliefors goodness-of-fit test for a 1-d continuous distribution.

# %%
import openturns as ot


# %%
# Create the data.

# %%
distribution = ot.Normal()
sample = distribution.getSample(50)

# %%
# Case 1 : the distribution parameters are known.
# -----------------------------------------------
#
# In the case where the parameters of the distribution are known,
# we must use the `Kolmogorov` static method and the distribution to be tested.

# %%
result = ot.FittingTest.Kolmogorov(sample, distribution, 0.01)
print("Conclusion=", result.getBinaryQualityMeasure(), "P-value=", result.getPValue())

# %%
# Test succeeded ?

# %%
result.getBinaryQualityMeasure()

# %%
# P-Value associated to the risk

# %%
result.getPValue()

# %%
# Threshold associated to the test.

# %%
result.getThreshold()

# %%
# Observed value of the statistic.

# %%
result.getStatistic()

# %%
# Case 2 : the distribution parameters are estimated from the sample.
# -------------------------------------------------------------------
#
# In the case where the parameters of the distribution are estimated from the sample,
# we must use the `Lilliefors` static method and the distribution factory to be tested.

# %%
ot.ResourceMap.SetAsUnsignedInteger("FittingTest-LillieforsMaximumSamplingSize", 1000)

# %%
distributionFactory = ot.NormalFactory()

# %%
dist, result = ot.FittingTest.Lilliefors(sample, distributionFactory, 0.01)
print("Conclusion=", result.getBinaryQualityMeasure(), "P-value=", result.getPValue())

# %%
dist

# %%
# Test succeeded ?

# %%
result.getBinaryQualityMeasure()

# %%
# P-Value associated to the risk

# %%
result.getPValue()

# %%
# Threshold associated to the test.

# %%
result.getThreshold()

# %%
# Observed value of the statistic.

# %%
result.getStatistic()