({{, (RefLink[IndependenceTest, paclet:ref/IndependenceTest])[(Subscript[v, 1]),(Subscript[v, 2])]
tests whether the vectors (Subscript[v, 1]) and (Subscript[v, 2]) are independent.}, {, (RefLink[IndependenceTest, paclet:ref/IndependenceTest])[(Subscript[m, 1]),(Subscript[m, 2])]
tests whether the matrices (Subscript[m, 1]) and (Subscript[m, 2]) are independent.}, {, (RefLink[IndependenceTest, paclet:ref/IndependenceTest])[…,"property"]
returns the value of "property".}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[IndependenceTest, paclet:ref/IndependenceTest]) performs a hypothesis test on (Subscript[v, 1]) and (Subscript[v, 2]) with null hypothesis (Subscript[H, 0]) that the vectors are independent, and alternative hypothesis (Subscript[H, a]) that they are not.

By default, a probability value or p-value is returned.

A small p-value suggests that it is unlikely that (Subscript[H, 0]) is true.

The arguments (Subscript[v, 1]) and (Subscript[v, 2]) can be any real-valued vectors or matrices of equal length.

(RefLink[IndependenceTest, paclet:ref/IndependenceTest])[(Subscript[v, 1]),(Subscript[v, 2])] will choose the most powerful test that applies to (Subscript[v, 1]) and (Subscript[v, 2]).

(RefLink[IndependenceTest, paclet:ref/IndependenceTest])[(Subscript[v, 1]),(Subscript[v, 2]),(RefLink[All, paclet:ref/All])] will choose all tests that apply to (Subscript[v, 1]) and (Subscript[v, 2]).

(RefLink[IndependenceTest, paclet:ref/IndependenceTest])[(Subscript[v, 1]),(Subscript[v, 2]),"test"] reports the p-value according to "test".

Some of the available tests assume normality for the (Subscript[v, i]). Some tests are restricted to vectors. Most tests are restricted to tests of monotonic or linear independence.

The following tests can be used:

(RefLink[IndependenceTest, paclet:ref/IndependenceTest])[(Subscript[v, 1]),(Subscript[v, 2]),"HypothesisTestData"] returns a (RefLink[HypothesisTestData, paclet:ref/HypothesisTestData]) object htd that can be used to extract additional test results and properties using the form htd["property"].

(RefLink[IndependenceTest, paclet:ref/IndependenceTest])[(Subscript[v, 1]),(Subscript[v, 2]),"property"] can be used to directly give the value of "property".

Properties related to the reporting of test results include:

The following options can be used:

For tests of independence, a cutoff α is chosen such that (Subscript[H, 0]) is rejected only if p<α. The value of α used for the "TestConclusion" and "ShortTestConclusion" properties is controlled by the (RefLink[SignificanceLevel, paclet:ref/SignificanceLevel]) option. This value α is also used in diagnostic tests of normality. By default, α is set to 0.05.

Named settings for (RefLink[VerifyTestAssumptions, paclet:ref/VerifyTestAssumptions]) in (RefLink[IndependenceTest, paclet:ref/IndependenceTest]) include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (34)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Test whether two vectors are independent:

v1=RandomVariate[NormalDistribution[],(10^3)];
v2=RandomVariate[NormalDistribution[],(10^3)];

ListPlot[Transpose[{v1,v2}]]

ℋ=IndependenceTest[v1,v2,{"TestDataTable",All}]

Test whether two matrices are independent:

BlockRandom[
SeedRandom[2];
data1=RandomVariate[BinormalDistribution[.5],100];
data2=RandomVariate[BinormalDistribution[.5],100];
]

At the 0.05 level, there is insufficient evidence to reject independence:

IndependenceTest[data1,data2,{"TestDataTable",All}]

OpenersExampleSection1(Spacer1)Scope  (12)

OpenersExampleSubsection0(Spacer1)Testing  (8)

Test whether two vectors are independent:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

{v3,v4}=Transpose[RandomVariate[BinormalDistribution[.7],100]];

The p-values are typically large when the vectors are independent:

IndependenceTest[v1,v2]

The p-values are typically small when there are dependencies:

IndependenceTest[v3,v4]

Test whether two matrices are independent:

Σ1={{12.8,0.3,3.,-1.5,5.1},{0.3,2.4,0.9,-0.3,-0.8},{3.,0.9,6.5,0.8,1.3},{-1.5,-0.3,0.8,1.4,2.},{5.1,-0.8,1.3,2.,11.1}};

data1=RandomVariate[MultinormalDistribution[{0,0,0,0,0},Σ1],100];

The p-values are typically small for dependent matrices:

IndependenceTest[data1[[All,1;;2]],data1[[All,3;;5]]]

The p-values are typically large when matrices are independent:

Σ2=IdentityMatrix[5];

data2=RandomVariate[MultinormalDistribution[{0,0,0,0,0},Σ2],100];

IndependenceTest[data2[[All,1;;2]],data2[[All,3;;5]]]

Using (RefLink[Automatic, paclet:ref/Automatic]) applies the most powerful appropriate test for linear independence:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

IndependenceTest[v1,v2,Automatic]

The property "AutomaticTest" can be used to determine which test was chosen:

IndependenceTest[v1,v2,"AutomaticTest"]

Perform a particular test for independence:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

IndependenceTest[v1,v2,"PearsonCorrelation"]

Any number of tests can be performed simultaneously:

IndependenceTest[v1,v2,{"PearsonCorrelation","KendallTau","WilksW"}]

Perform all tests appropriate to the data simultaneously:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

IndependenceTest[v1,v2,All]

Use the property "AllTests" to identify which tests were used:

IndependenceTest[v1,v2,"AllTests"]

Create a (RefLink[HypothesisTestData, paclet:ref/HypothesisTestData]) object for repeated property extraction:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

ℋ=IndependenceTest[v1,v2,"HypothesisTestData"];

The properties available for extraction:

ℋ["Properties"]

Extract some properties from the (RefLink[HypothesisTestData, paclet:ref/HypothesisTestData]) object:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

ℋ=IndependenceTest[v1,v2,"HypothesisTestData"];

The p-value and test statistic from the "PearsonCorrelation" test:

ℋ["PValue","PearsonCorrelation"]

ℋ["TestStatistic","PearsonCorrelation"]

Extract any number of properties simultaneously:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

ℋ=IndependenceTest[v1,v2,"HypothesisTestData"];

The p-value and test statistic from a Spearman rank test:

ℋ[{"PValue","SpearmanRank"},{"TestStatistic","SpearmanRank"}]

OpenersExampleSubsection1(Spacer1)Reporting  (4)

Tabulate the results from a selection of tests:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

ℋ=IndependenceTest[v1,v2,"HypothesisTestData"];

A full table of all appropriate test results:

ℋ["TestDataTable",All]

A table of selected test results:

ℋ["TestDataTable",{"KendallTau","SpearmanRank"}]

Retrieve the entries from a test table for customized reporting:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

ℋ=IndependenceTest[v1,v2,"HypothesisTestData"];

res=ℋ["TestData",All];

tests=ℋ["AllTests"]

The p-values are above 0.05, so there is not enough evidence to reject (Subscript[H, 0 ]) at that level:

Show[BarChart[res[[All,2]],ChartLabels->Placed[tests,Center],BarOrigin->Left],Graphics[{Dashed,InfiniteLine[{{.05,0},{.05,1}}]}]]

Tabulate p-values for a test or group of tests:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

ℋ=IndependenceTest[v1,v2,"HypothesisTestData"];

ℋ["PValueTable","KendallTau"]

The p-value from the table:

ℋ["PValue","KendallTau"]

A table of p-values from all appropriate tests:

ℋ["PValueTable",All]

A table of p-values from a subset of tests:

ℋ["PValueTable",{"KendallTau","SpearmanRank","HoeffdingD"}]

Report the test statistic from a test or group of tests:

{v1,v2}=Transpose[RandomVariate[BinormalDistribution[0],100]];

ℋ=IndependenceTest[v1,v2,"HypothesisTestData"];

ℋ["TestStatisticTable"]

The test statistic from the table:

ℋ["TestStatistic"]

A table of test statistics from all appropriate tests:

ℋ["TestStatisticTable",All]

OpenersExampleSection2(Spacer1)Options  (15)

OpenersExampleSubsection2(Spacer1)AlternativeHypothesis  (3)

A two-sided test is performed by default:

{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100];

IndependenceTest[v1,v2,AlternativeHypothesis->"Unequal"]

IndependenceTest[v1,v2,AlternativeHypothesis->Automatic]

Perform a two-sided test or a one-sided alternative:

{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",3},{NormalDistribution[],NormalDistribution[]}],100];

A two-sided test:

IndependenceTest[v1,v2,AlternativeHypothesis->"Unequal"]

The two one-sided alternatives:

IndependenceTest[v1,v2,AlternativeHypothesis->"Less"]

IndependenceTest[v1,v2,AlternativeHypothesis->"Greater"]

Some tests are inherently two-sided:

{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",3},{NormalDistribution[],NormalDistribution[]}],100];

IndependenceTest[v1,v2,"HoeffdingD",AlternativeHypothesis->"Greater"]

This is due to the shape of the null distribution:

data=RandomVariate[BinormalDistribution[0],{1000,100}];

t=IndependenceTest[Sequence@@Transpose[#],{"TestStatistic","HoeffdingD"}]&/@data;

Histogram[t]

OpenersExampleSubsection3(Spacer1)MaxIterations  (1)

Set the maximum number of iterations to use for multivariate nonparametric tests:

data1=RandomVariate[BinormalDistribution[.5],25];
data2=RandomVariate[BinormalDistribution[.5],25];

IndependenceTest[data1,data2,"KendallTau",MaxIterations->1000]

IndependenceTest[data1,data2,"SpearmanRank",MaxIterations->1000]

IndependenceTest[data1,data2,"BlomqvistBeta",MaxIterations->1000]

Setting the value too low may result in failed convergence but produce faster timings:

IndependenceTest[data1,data2,"KendallTau",MaxIterations->10]

OpenersExampleSubsection4(Spacer1)Method  (4)

By default, p-values are computed using asymptotic test statistic distributions:

{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100];

IndependenceTest[v1,v2,Method->Automatic]

IndependenceTest[v1,v2,Method->"Asymptotic"]

The p-value can be obtained using permutation methods:

{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",3},{NormalDistribution[],NormalDistribution[]}],10];

IndependenceTest[v1,v2,Method->"Permutation"]

Set the number of permutations to use:

{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",3},{NormalDistribution[],NormalDistribution[]}],10];

IndependenceTest[v1,v2,Method->{"Permutation","MonteCarloSamples"->(10^4)}]

By default, (10^3) random permutations are used:

IndependenceTest[v1,v2,Method->{"Permutation","MonteCarloSamples"->(10^3)}]

IndependenceTest[v1,v2,Method->{"Permutation","MonteCarloSamples"->Automatic}]

Set the seed used for generating random permutations:

{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",3},{NormalDistribution[],NormalDistribution[]}],10];

IndependenceTest[v1,v2,Method->{"Permutation","RandomSeed"->0}]

IndependenceTest[v1,v2,Method->{"Permutation","RandomSeed"->9}]

OpenersExampleSubsection5(Spacer1)SignificanceLevel  (3)

Set the significance level for diagnostic tests:

BlockRandom[SeedRandom[2];{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100];];

IndependenceTest[v1,v2,"WilksW",SignificanceLevel->.0001]

By default, 0.05 is used. The message shows 0.025 because two tests were performed:

IndependenceTest[v1,v2,"WilksW"]

Setting the significance level may alter which test is automatically chosen:

BlockRandom[SeedRandom[2];{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100];];

IndependenceTest[v1,v2,"AutomaticTest",SignificanceLevel->.0001]

A nonparametric test would have been chosen by default:

IndependenceTest[v1,v2,"AutomaticTest",SignificanceLevel->0.05]

The significance level is also used for "TestConclusion" and "ShortTestConclusion":

BlockRandom[SeedRandom[3];{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",3},{NormalDistribution[],NormalDistribution[]}],100];];

ℋ1=IndependenceTest[v1,v2,"HypothesisTestData",SignificanceLevel->.05];

ℋ2=IndependenceTest[v1,v2,"HypothesisTestData",SignificanceLevel->.000005];

ℋ1["TestConclusion"]//TraditionalForm

ℋ2["TestConclusion"]//TraditionalForm

ℋ1["ShortTestConclusion"]

ℋ2["ShortTestConclusion"]

OpenersExampleSubsection6(Spacer1)VerifyTestAssumptions  (4)

By default, normality is tested when appropriate:

BlockRandom[SeedRandom[2];{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100];];

IndependenceTest[v1,v2,"PillaiTrace",VerifyTestAssumptions->Automatic]

Diagnostics can be controlled as a group using (RefLink[All, paclet:ref/All]) or (RefLink[None, paclet:ref/None]):

BlockRandom[SeedRandom[2];{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100];];

Verify all assumptions:

IndependenceTest[v1,v2,"PillaiTrace",VerifyTestAssumptions->All]

Check no assumptions:

IndependenceTest[v1,v2,"PillaiTrace",VerifyTestAssumptions->None]

Diagnostics can be controlled independently:

BlockRandom[SeedRandom[2];{v1,v2}=Transpose@RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100];];

Check for normality:

IndependenceTest[v1,v2,"PillaiTrace",VerifyTestAssumptions->"Normality"]

Explicitly set the diagnostic result:

IndependenceTest[v1,v2,"PillaiTrace",VerifyTestAssumptions->{"Normality"->True}]

IndependenceTest[v1,v2,"PillaiTrace",VerifyTestAssumptions->{"Normality"->False}]

It is often useful to bypass diagnostic tests for simulation purposes:

BlockRandom[SeedRandom[2];data=RandomVariate[BinormalDistribution[0],{100,35}]];

AbsoluteTiming[T=Quiet@IndependenceTest[Sequence@@Transpose[#],{"TestStatistic","WilksW"}]&/@data;]

The assumptions of the test hold by design, so a great deal of time can be saved:

AbsoluteTiming[T2=Quiet@IndependenceTest[Sequence@@Transpose[#],{"TestStatistic","WilksW"},VerifyTestAssumptions->None]&/@data;]

The results are identical:

SmoothHistogram[{T,T2}]

OpenersExampleSection3(Spacer1)Properties & Relations  (4)

The test chosen depends on normality assumptions and the dimensionality of the data:

BlockRandom[
SeedRandom[4];
x=RandomVariate[NormalDistribution[],100];
y=RandomVariate[CauchyDistribution[0,1],100];
z=RandomVariate[BinormalDistribution[0],100];
];

Comparison of normally distributed vectors:

IndependenceTest[z[[All,1]],z[[All,2]],"AutomaticTest"]

The second vector is not from a normal distribution:

IndependenceTest[x,y,"AutomaticTest"]

Matrix comparison of normally distributed data:

IndependenceTest[x,z,"AutomaticTest"]

Matrix comparison of data that is not normally distributed:

IndependenceTest[y,z,"AutomaticTest"]

To test particular values of correlation or rank correlation, use (RefLink[CorrelationTest, paclet:ref/CorrelationTest]):

data=RandomVariate[BinormalDistribution[.5],1000];

Correlation[data][[1,2]]

SpearmanRho[data][[1,2]]

CorrelationTest[data,.5,{"TestDataTable",All}]

(RefLink[HoeffdingDTest, paclet:ref/HoeffdingDTest]) should be used if nonlinear dependency is expected:

x=RandomReal[{-1,1},100];
y=(x^2)+RandomReal[{-.1,.1},100];

The data is clearly dependent:

ListPlot[Transpose[{x,y}]]

(RefLink[IndependenceTest, paclet:ref/IndependenceTest]) does not detect this by default:

IndependenceTest[x,y]

Measures of monotone dependence are selected by default:

IndependenceTest[x,y,"AutomaticTest"]

(RefLink[HoeffdingD, paclet:ref/HoeffdingD]) is sensitive to many types of dependence:

IndependenceTest[x,y,"HoeffdingD"]

HoeffdingDTest[x,y]

(RefLink[IndependenceTest, paclet:ref/IndependenceTest]) works with the values only when the input is a (RefLink[TimeSeries, paclet:ref/TimeSeries]):

ts1=TimeSeries[];

ts2=TimeSeries[];

IndependenceTest[ts1,ts2]

IndependenceTest[ts1["Values"],ts2["Values"]]

OpenersExampleSection4(Spacer1)Neat Examples  (1)

The distributions of some test statistics:

data=RandomVariate[BinormalDistribution[0.],{3000,50}];

ℋ=MapThread[IndependenceTest[#1,#2,"HypothesisTestData",VerifyTestAssumptions->None]&,{data[[All,All,1]],data[[All,All,2]]}];

T=Transpose@Table[h["TestStatistic",i],{h,ℋ},{i,tests={"BlomqvistBeta","GoodmanKruskalGamma","HoeffdingD","KendallTau","PearsonCorrelation","PillaiTrace","SpearmanRank","WilksW"}}];

Table[SmoothHistogram[T[[i]],PlotLabel->tests[[i]],Filling->Axis,ImageSize->200],{i,8}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[HypothesisTestData, paclet:ref/HypothesisTestData])  ▪  (RefLink[DistributionFitTest, paclet:ref/DistributionFitTest])  ▪  (RefLink[LocationTest, paclet:ref/LocationTest])  ▪  (RefLink[VarianceTest, paclet:ref/VarianceTest])  ▪  (RefLink[BlomqvistBeta, paclet:ref/BlomqvistBeta])  ▪  (RefLink[CorrelationTest, paclet:ref/CorrelationTest])  ▪  (RefLink[GoodmanKruskalGamma, paclet:ref/GoodmanKruskalGamma])  ▪  (RefLink[HoeffdingD, paclet:ref/HoeffdingD])  ▪  (RefLink[KendallTau, paclet:ref/KendallTau])  ▪  (RefLink[Correlation, paclet:ref/Correlation])  ▪  (RefLink[PillaiTrace, paclet:ref/PillaiTrace])  ▪  (RefLink[SpearmanRho, paclet:ref/SpearmanRho])  ▪  (RefLink[WilksW, paclet:ref/WilksW])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Hypothesis Tests, paclet:guide/HypothesisTests])}, {▪(RefLinkPlain[Probability & Statistics with Quantities, paclet:guide/ProbabilityWithQuantities])}})}})