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
|
#! /usr/bin/env python
import openturns as ot
ot.TESTPREAMBLE()
dim = 10
R = ot.CorrelationMatrix(dim)
for i in range(dim):
for j in range(i):
R[i, j] = (i + j + 1.0) / (2.0 * dim)
mean = [2.0] * dim
sigma = [3.0] * dim
distribution = ot.Normal(mean, sigma, R)
size = 100
sample = distribution.getSample(size)
sampleY = sample.getMarginal(0)
sampleZ = ot.Sample(size, 1)
for i in range(size):
sampleZ[i, 0] = sampleY[i, 0] * sampleY[i, 0]
discreteSample1 = ot.Poisson(0.1).getSample(size)
discreteSample2 = ot.Geometric(0.4).getSample(size)
# ChiSquared Independence test : test if two samples (of sizes not necessarily equal) are independent ?
# Care : discrete samples only
# H0 = independent samples
# p-value threshold : probability of the H0 reject zone : 0.10
# p-value : probability (test variable decision > test variable decision evaluated on the samples)
# Test = True <=> p-value > p-value threshold
print(
"ChiSquared=",
ot.HypothesisTest.ChiSquared(discreteSample1, discreteSample2, 0.10),
)
print(
"ChiSquared2=",
ot.HypothesisTest.ChiSquared(discreteSample1, discreteSample1, 0.10),
)
# Pearson Test : test if two gaussian samples are independent (based on the evaluation of the linear correlation coefficient)
# H0 : independent samples (linear correlation coefficient = 0)
# Test = True <=> independent samples (linear correlation coefficient = 0)
# p-value threshold : probability of the H0 reject zone : 0.10
# p-value : probability (test variable decision > test variable decision evaluated on the samples)
# Test = True <=> p-value > p-value threshold
print("Pearson=", ot.HypothesisTest.Pearson(sampleY, sampleZ, 0.10))
ot.RandomGenerator.SetSeed(0)
sample1 = ot.Normal().getSample(20)
sample2 = ot.Normal(0.1, 1.1).getSample(30)
resultTwoSamplesKolmogorov = ot.HypothesisTest.TwoSamplesKolmogorov(sample1, sample2)
print(resultTwoSamplesKolmogorov)
|