File: t_HypothesisTest_correlation.py

package info (click to toggle)
openturns 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,588 kB
  • ctags: 26,495
  • sloc: cpp: 144,032; python: 26,855; ansic: 7,868; sh: 419; makefile: 263; yacc: 123; lex: 44
file content (109 lines) | stat: -rwxr-xr-x 5,406 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
98
99
100
101
102
103
104
105
106
107
108
109
#! /usr/bin/env python

from __future__ import print_function
from openturns import *


dim = 10
R = CorrelationMatrix(dim)
for i in range(dim):
    for j in range(i):
        R[i, j] = (i + j + 1.0) / (2.0 * dim)
mean = NumericalPoint(dim, 2.0)
sigma = NumericalPoint(dim, 3.0)
distribution = Normal(mean, sigma, R)

size = 100
sample = distribution.getSample(size)
sampleX = NumericalSample(size, dim - 1)
sampleY = NumericalSample(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 = NumericalSample(size, 1)
for i in range(size):
    sampleZ[i, 0] = sampleY[i, 0] * sampleY[i, 0]

selection = 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 : 1-0.90

print('PartialPearsonXY=', HypothesisTest.PartialPearson(
    sampleX, sampleY, selection, 0.90))

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

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

# 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 : 1-0.90
print('FullPearsonXY=', HypothesisTest.FullPearson(
    sampleX, sampleY, 0.90))
print('FullPearsonYY=', HypothesisTest.FullPearson(
    sampleY, sampleY, 0.90))

# PartialSpearman 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), PartialSpearman performs the Independence Spearman test simultaneously on firstSample[i] and secondSample, for i in the selection.
# Probability of the H0 reject zone : 1-0.90

# The three tests must be equal
print('PartialSpearmanX0Y=', HypothesisTest.PartialSpearman(
    sampleX, sampleY, selection2, 0.90))
print('SpearmanX0Y=', HypothesisTest.Spearman(sampleX0, sampleY, 0.90))
print('FullSpearmanX0Y=', HypothesisTest.FullSpearman(
    sampleX0, sampleY, 0.90))

print('PartialSpearmanXY=', HypothesisTest.PartialSpearman(
    sampleX, sampleY, selection, 0.90))

# FullSpearman : Spearman 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), FullSpearman performs the Independence Spearman test simultaneously on all firstSample[i] and secondSample.
# Probability of the H0 reject zone : 1-0.90

print('FullSpearmanYZ=', HypothesisTest.FullSpearman(
    sampleY, sampleZ, 0.90))
print('FullSpearmanYY=', HypothesisTest.FullSpearman(
    sampleY, sampleY, 0.90))

# Regression 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), PartialRegression performs the Regression test
# simultaneously on all firstSample[i] and secondSample, for i in the
# selection. The Regression test tests ifthe regression model between two
# scalar numerical samples is significant. It is based on the deviation
# analysis of the regression. The Fisher distribution is used.

# The two tests must be equal
print('PartialRegressionX0Y=', HypothesisTest.PartialRegression(
    sampleX, sampleY, selection2, 0.90))
print('FullRegressionX0Y=', HypothesisTest.FullRegression(
    sampleX0, sampleY, 0.90))

print('PartialRegressionXY=', HypothesisTest.PartialRegression(
    sampleX, sampleY, selection, 0.90))

# Regression 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), FullRegression performs the Regression test
# simultaneously on all firstSample[i] and secondSample. The Regression
# test tests if the regression model between two scalar numerical samples
# is significant. It is based on the deviation analysis of the regression.
# The Fisher distribution is used.

print('FullRegressionXZ=', HypothesisTest.FullRegression(
    sampleX, sampleY, 0.90))
print('FullRegressionZZ=', HypothesisTest.FullRegression(
    sampleZ, sampleZ, 0.90))