Sample independence testΒΆ

In this example we are going to perform tests to assess whether two 1-d samples are independent or not.

Several methods can be used:

  • Pearson test (for continuous values)
  • Spearman test (for continuous values)
  • Chi2 test (for discrete values)
In [2]:
from __future__ import print_function
import openturns as ot

continuous samples

In [3]:
# Create continuous samples
sample1 = ot.Normal().getSample(100)
sample2 = ot.Normal().getSample(100)
In [9]:
# Using the Pearson test
ot.HypothesisTest.Pearson(sample1, sample2, 0.90)

class=TestResult name=Unnamed type=TwoSamplePearson binaryQualityMeasure=true p-value threshold=0.1 p-value=0.521269 description=[]

In [11]:
# Using the Spearman test
ot.HypothesisTest.Spearman(sample1, sample2, 0.90)

class=TestResult name=Unnamed type=TwoSampleSpearman binaryQualityMeasure=true p-value threshold=0.1 p-value=0.719843 description=[]

discrete samples

In [4]:
# Create discrete samples
sample1 = ot.Poisson(0.2).getSample(100)
sample2 = ot.Poisson(0.2).getSample(100)
In [6]:
# Using the Chi2 test
ot.HypothesisTest.ChiSquared(sample1, sample2, 0.90)

class=TestResult name=Unnamed type=TwoSampleChiSquared binaryQualityMeasure=true p-value threshold=0.1 p-value=0.878545 description=[]