File: t_HypothesisTest_correlation.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 (67 lines) | stat: -rwxr-xr-x 2,562 bytes parent folder | download | duplicates (2)
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
#! /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 = ot.Point(dim, 2.0)
sigma = ot.Point(dim, 3.0)
distribution = ot.Normal(mean, sigma, R)

size = 100
sample = distribution.getSample(size)
sampleX = ot.Sample(size, dim - 1)
sampleY = ot.Sample(size, 1)
for i in range(size):
    sampleY[i, 0] = sample[i, 0]
    for j in range(1, dim):
        sampleX[i, j - 1] = sample[i, j]

sampleZ = ot.Sample(size, 1)
for i in range(size):
    sampleZ[i, 0] = sampleY[i, 0] * sampleY[i, 0]

selection = ot.Indices(5)
selection.fill()
print("selection = ", selection)

# PartialPearson : Independence Pearson test between 2 samples : firstSample of dimension n and secondSample of dimension 1.
# If firstSample[i] is the numerical sample extracted from firstSample (ith coordinate of each point of the numerical sample),
# PartialPearson performs the Independence Pearson test simultaneously on firstSample[i] and secondSample, for i in the selection.
# For all i, it is supposed that the couple (firstSample[i] and secondSample) is issued from a gaussian  vector.
# Probability of the H0 reject zone : 0.10

print(
    "PartialPearsonXY=",
    ot.HypothesisTest.PartialPearson(sampleX, sampleY, selection, 0.10),
)

selection2 = ot.Indices(1, 0)
sampleX0 = ot.Sample(size, 1)
for i in range(size):
    sampleX0[i, 0] = sampleX[i, 0]

# The three tests must be equal
print(
    "PartialPearsonX0Y=",
    ot.HypothesisTest.PartialPearson(sampleX, sampleY, selection2, 0.10),
)
print("PearsonX0Y=", ot.HypothesisTest.Pearson(sampleX0, sampleY, 0.10))
print("FullPearsonX0Y=", ot.HypothesisTest.FullPearson(sampleX0, sampleY, 0.10))

# FullPearson : Independence Pearson test between 2 samples : firstSample of dimension n and secondSample of dimension 1.
# If firstSample[i] is the numerical sample extracted from firstSample (ith coordinate of each point of the numerical sample),
# FullPearson performs the Independence Pearson test simultaneously on firstSample[i] and secondSample.
# For all i, it is supposed that the couple (firstSample[i] and secondSample) is issued from a gaussian  vector.
# Probability of the H0 reject zone : 0.10
print("FullPearsonXY=", ot.HypothesisTest.FullPearson(sampleX, sampleY, 0.10))

# Expected result is SpecFunc::Infinity
fullPearsonYY = ot.HypothesisTest.FullPearson(sampleY, sampleY, 0.10)[0]
testStatistic = fullPearsonYY.getStatistic()
assert testStatistic == ot.SpecFunc.Infinity