({{, (RefLink[CorrelationTest, paclet:ref/CorrelationTest])[{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])},…}]
tests whether the correlation coefficient for a bivariate population is zero.}, {, (RefLink[CorrelationTest, paclet:ref/CorrelationTest])[{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])},…},(Subscript[ρ, 0])]
tests whether the correlation coefficient is (Subscript[ρ, 0]).}, {, (RefLink[CorrelationTest, paclet:ref/CorrelationTest])[{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])},…},{{(Subscript[u, 1]),(Subscript[v, 1])},{(Subscript[u, 2]),(Subscript[v, 2])},…}]
tests whether the correlation coefficients for two populations are equal.}, {, (RefLink[CorrelationTest, paclet:ref/CorrelationTest])[…,"property"]
returns the value of "property".}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[CorrelationTest, paclet:ref/CorrelationTest]) tests the null hypothesis (Subscript[H, 0]) against the alternative hypothesis (Subscript[H, a]):

where (Subscript[ρ, x,y]) is the population correlation coefficient for {{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])},…}.

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 data {{(Subscript[x, 1]),(Subscript[y, 1])},…} and {{(Subscript[u, 1]),(Subscript[v, 1])},…} can be any real-valued bivariate matrices.

The argument (Subscript[ρ, 0]) can be any real number such that -1<(Subscript[ρ, 0])<1.,

(RefLink[CorrelationTest, paclet:ref/CorrelationTest])[{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])},…},(Subscript[ρ, 0])] will choose the most powerful test that applies to the data.

(RefLink[CorrelationTest, paclet:ref/CorrelationTest])[…,(RefLink[All, paclet:ref/All])] will choose all tests that apply to the data.

(RefLink[CorrelationTest, paclet:ref/CorrelationTest])[…,"test"] reports the p-value according to "test".

The following tests can be used:

The "PearsonCorrelation" test assumes the data was drawn from a normal distribution.

(RefLink[CorrelationTest, paclet:ref/CorrelationTest])[…,"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[CorrelationTest, paclet:ref/CorrelationTest])[…,"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 correlation, 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[CorrelationTest, paclet:ref/CorrelationTest]) include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (32)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Test whether the population correlation coefficient is zero:

m=RandomVariate[BinormalDistribution[.05],1000];

ListPlot[m]

CorrelationTest[m]

Test whether the population correlation coefficient is 0.25:

m=RandomVariate[BinormalDistribution[.05],1000];

CorrelationTest[m,.25]

Compare two correlation coefficients:

m1=RandomVariate[BinormalDistribution[.5],1000];
m2=RandomVariate[BinormalDistribution[-.5],850];

ListPlot[{m1,m2}]

CorrelationTest[m1,m2]

Report the test statistics and p-values in a table:

CorrelationTest[m1,m2,{"TestDataTable",All}]

OpenersExampleSection1(Spacer1)Scope  (13)

OpenersExampleSubsection0(Spacer1)Testing  (9)

Test whether the population correlation coefficient is zero:

m1=RandomVariate[BinormalDistribution[0],1000];
m2=RandomVariate[BinormalDistribution[-.8],1000];

The p-values are typically large when the true correlation is near zero:

Correlation[BinormalDistribution[0]][[1,2]]

CorrelationTest[m1]

The p-values are typically small when the true correlation is not zero:

Correlation[BinormalDistribution[-.8]][[1,2]]

CorrelationTest[m2]

Test whether the population correlation coefficient is 0.5:

m1=RandomVariate[BinormalDistribution[.5],1000];
m2=RandomVariate[BinormalDistribution[0],1000];

The p-values are typically large when the true correlation is near the hypothesized value:

Correlation[BinormalDistribution[.5]][[1,2]]

CorrelationTest[m1,.5]

The p-values are typically small when the true correlation is far from the hypothesized value:

Correlation[BinormalDistribution[-0]][[1,2]]

CorrelationTest[m2,.5]

Compare correlation coefficients from two samples:

m1=RandomVariate[BinormalDistribution[-.5],1000];
m2=RandomVariate[BinormalDistribution[0],185];
m3=RandomVariate[BinormalDistribution[-.5],200];

The p-values are typically large when the correlations are similar:

CorrelationTest[m1,m3,"TestStatistic"]

The p-values are typically small when the correlations are dissimilar:

CorrelationTest[m1,m2]

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

m=RandomVariate[BinormalDistribution[0],100];

CorrelationTest[m,0,Automatic]

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

CorrelationTest[m,0,"AutomaticTest"]

Perform a particular test:

m=RandomVariate[BinormalDistribution[0],100];

CorrelationTest[m,0,"PearsonCorrelation"]

Any number of tests can be performed simultaneously:

CorrelationTest[m,0,{"PearsonCorrelation","SpearmanRank"}]

Perform all tests appropriate to the data simultaneously:

m=RandomVariate[BinormalDistribution[0],100];

CorrelationTest[m,0,All]

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

CorrelationTest[m,0,"AllTests"]

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

m=RandomVariate[BinormalDistribution[0],100];

ℋ=CorrelationTest[m,0,"HypothesisTestData"];

The properties available for extraction:

ℋ["Properties"]

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

m=RandomVariate[BinormalDistribution[0],100];

ℋ=CorrelationTest[m,0,"HypothesisTestData"]

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

ℋ["PValue","PearsonCorrelation"]

ℋ["TestStatistic","PearsonCorrelation"]

Extract any number of properties simultaneously:

m=RandomVariate[BinormalDistribution[0],100];

ℋ=CorrelationTest[m,0,"HypothesisTestData"];

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

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

OpenersExampleSubsection1(Spacer1)Reporting  (4)

Tabulate the results from a selection of tests:

m=RandomVariate[BinormalDistribution[0],100];

ℋ=CorrelationTest[m,0,"HypothesisTestData"];

A full table of all appropriate test results:

ℋ["TestDataTable",All]

Retrieve the entries from a test table for customized reporting:

m=RandomVariate[BinormalDistribution[0],100];

ℋ=CorrelationTest[m,0,"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:

m=RandomVariate[BinormalDistribution[0],100];

ℋ=CorrelationTest[m,0,"HypothesisTestData"];

ℋ["PValueTable"]

The p-value from the table:

ℋ["PValue"]

A table of p-values from all appropriate tests:

ℋ["PValueTable",All]

Tabulate test statistics for a test or group of tests:

m=RandomVariate[BinormalDistribution[0],100];

ℋ=CorrelationTest[m,0,"HypothesisTestData"];

ℋ["TestStatisticTable"]

The test statistic from the table:

ℋ["TestStatistic"]

A table of test statistics from all appropriate tests:

ℋ["TestStatisticTable",All]

OpenersExampleSection2(Spacer1)Options  (8)

OpenersExampleSubsection2(Spacer1)AlternativeHypothesis  (2)

A two-sided test is performed by default:

m=RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100];

CorrelationTest[m,AlternativeHypothesis->"Unequal"]

CorrelationTest[m,AlternativeHypothesis->Automatic]

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

m=RandomVariate[CopulaDistribution[{"Clayton",3},{NormalDistribution[],NormalDistribution[]}],100];

A two-sided test:

CorrelationTest[m,AlternativeHypothesis->"Unequal"]

The two one-sided alternatives:

CorrelationTest[m,AlternativeHypothesis->"Less"]

CorrelationTest[m,AlternativeHypothesis->"Greater"]

OpenersExampleSubsection3(Spacer1)SignificanceLevel  (3)

Set the significance level for diagnostic tests:

m=BlockRandom[SeedRandom[2];RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100]];

CorrelationTest[m,0,"PearsonCorrelation",SignificanceLevel->.0001]

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

CorrelationTest[m,0,"PearsonCorrelation"]

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

m=BlockRandom[SeedRandom[2];RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100]];

CorrelationTest[m,0,"AutomaticTest",SignificanceLevel->.0001]

A nonparametric test would have been chosen by default:

CorrelationTest[m,0,"AutomaticTest",SignificanceLevel->.1]

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

m=BlockRandom[SeedRandom[2];RandomVariate[CopulaDistribution[{"Clayton",2},{NormalDistribution[],NormalDistribution[]}],100]];

ℋ1=CorrelationTest[m,0,"HypothesisTestData",SignificanceLevel->.05];

ℋ2=CorrelationTest[m,0,"HypothesisTestData",SignificanceLevel->.000005];

ℋ1["TestConclusion"]//TraditionalForm

ℋ2["TestConclusion"]//TraditionalForm

ℋ1["ShortTestConclusion"]

ℋ2["ShortTestConclusion"]

OpenersExampleSubsection4(Spacer1)VerifyTestAssumptions  (3)

By default, normality is tested when appropriate:

m=BlockRandom[SeedRandom[2];RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100]];

CorrelationTest[m,0,"PearsonCorrelation",VerifyTestAssumptions->Automatic]

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

m=BlockRandom[SeedRandom[2];RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100]];

Verify all assumptions:

CorrelationTest[m,0,"PearsonCorrelation",VerifyTestAssumptions->All]

Check no assumptions:

CorrelationTest[m,0,"PearsonCorrelation",VerifyTestAssumptions->None]

Diagnostics can be controlled independently:

m=BlockRandom[SeedRandom[2];RandomVariate[CopulaDistribution[{"Clayton",1},{NormalDistribution[],NormalDistribution[]}],100]];

Check for normality:

CorrelationTest[m,0,"PearsonCorrelation",VerifyTestAssumptions->"Normality"]

Explicitly set the diagnostic result:

CorrelationTest[m,0,"PearsonCorrelation",VerifyTestAssumptions->{"Normality"->True}]

CorrelationTest[m,0,"PearsonCorrelation",VerifyTestAssumptions->{"Normality"->False}]

OpenersExampleSection3(Spacer1)Properties & Relations  (5)

The p-value is computed using the Fisher z transformation of the sample correlation r:

fisherZTransform[r_,ρ0_,n_]:=(ArcTanh[r]-ArcTanh[ρ0]-((ρ0)/(2 (n-1)))) (Sqrt[n-3])

m=BlockRandom[SeedRandom[10];RandomVariate[BinormalDistribution[.5],100]];

The Fisher z transformation with (Subscript[ρ, 0])==0.25`:

z1=fisherZTransform[Correlation[Sequence@@(m\[Transpose])],0.25,100]

Probability[Abs[x]>Abs[z1],x\[Distributed]NormalDistribution[]]

CorrelationTest[m,.25,"PearsonCorrelation"]

The same transformation is used for "SpearmanRank":

m2=BlockRandom[SeedRandom[10];RandomVariate[CauchyDistribution[0,1],{100,2}]];

z2=fisherZTransform[SpearmanRho[Sequence@@(m2\[Transpose])],0.25,100]

Probability[Abs[x]>Abs[z2],x\[Distributed]NormalDistribution[]]

CorrelationTest[m2,.25,"SpearmanRank"]

A similar transformation is used when comparing correlations:

fisherZTransform[r1_,r2_,n1_,n2_]:=(ArcTanh[r1]-ArcTanh[r2])/(Sqrt[(1/(n1-3))+(1/(n2-3))])

m1=BlockRandom[SeedRandom[1];RandomVariate[BinormalDistribution[.5],100]];

m2=BlockRandom[SeedRandom[1];RandomVariate[BinormalDistribution[-.5],35]];

The statistics are equivalent:

z=fisherZTransform[Correlation[Sequence@@(m1\[Transpose])],Correlation[Sequence@@(m2\[Transpose])],100,35]

Probability[Abs[x]>Abs[z],x\[Distributed]NormalDistribution[]]

CorrelationTest[m1,m2]

The transformed statistic has an asymptotic standard normal distribution under (Subscript[H, 0]):

data=BlockRandom[SeedRandom[2];RandomVariate[BinormalDistribution[0],{1000,50}]];

fisherZTransform[r_,ρ0_,n_]:=(ArcTanh[r]-ArcTanh[ρ0]-((ρ0)/(2 (n-1)))) (Sqrt[n-3])

t=CorrelationTest[#,0,"TestStatistic",VerifyTestAssumptions->None]&/@data;

z=fisherZTransform[#,0,50]&/@t;

QuantilePlot[z]

DistributionFitTest[z,NormalDistribution[0,1]]

Use (RefLink[IndependenceTest, paclet:ref/IndependenceTest]) to test for independence between vectors and matrices:

m=BlockRandom[SeedRandom[1];RandomVariate[BinormalDistribution[.5],100]];

IndependenceTest[Sequence@@(m\[Transpose]),"TestDataTable"]

The correlation test works with the time stamps and the values when the input is a (RefLink[TimeSeries, paclet:ref/TimeSeries]):

ts=TimeSeries[];

ts["ValueDimensions"]

CorrelationTest[ts]

This is equivalent to:

CorrelationTest[Transpose@{ts["Times"],ts["Values"]}]

OpenersExampleSection4(Spacer1)Possible Issues  (3)

(RefLink[CorrelationTest, paclet:ref/CorrelationTest]) should not be used to test causation:

BlockRandom[
SeedRandom[1];
d1=RandomVariate[NormalDistribution[],100];
d2=RandomVariate[NormalDistribution[],100];
]

The high degree of correlation results from sorting:

CorrelationTest[Transpose[{Sort@d1,Sort@d2}],0,"TestDataTable"]

Causation does not necessarily imply high correlation, either:

d3=d1^2;

CorrelationTest[Transpose[{d1,d3}],0,"TestDataTable"]

The correlation test will not recognize multivariate (RefLink[TimeSeries, paclet:ref/TimeSeries]):

ts=TimeSeries[];

CorrelationTest[ts]

Test individual components:

CorrelationTest/@ts["PathComponents"]

Test only the values:

CorrelationTest/@ts["ValueList"]

The correlation test will not thread over paths of (RefLink[TemporalData, paclet:ref/TemporalData]):

td=TemporalData[];

CorrelationTest[td]

Test pathwise each component against times:

CorrelationTest[td["PathComponent",1]]

CorrelationTest[td["PathComponent",2]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BlomqvistBetaTest, paclet:ref/BlomqvistBetaTest])  ▪  (RefLink[Correlation, paclet:ref/Correlation])  ▪  (RefLink[GoodmanKruskalGammaTest, paclet:ref/GoodmanKruskalGammaTest])  ▪  (RefLink[HoeffdingDTest, paclet:ref/HoeffdingDTest])  ▪  (RefLink[IndependenceTest, paclet:ref/IndependenceTest])  ▪  (RefLink[KendallTauTest, paclet:ref/KendallTauTest])  ▪  (RefLink[PearsonCorrelationTest, paclet:ref/PearsonCorrelationTest])  ▪  (RefLink[PillaiTraceTest, paclet:ref/PillaiTraceTest])  ▪  (RefLink[SpearmanRankTest, paclet:ref/SpearmanRankTest])  ▪  (RefLink[WilksWTest, paclet:ref/WilksWTest])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Hypothesis Tests, paclet:guide/HypothesisTests])}})}})