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

OpenersNotesSection(Spacer1)Details and Options

(RefLink[PearsonCorrelationTest, paclet:ref/PearsonCorrelationTest]) performs a hypothesis test on (Subscript[v, 1]) and (Subscript[v, 2]) with null hypothesis (Subscript[H, 0]) that the vectors are linearly 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 of equal length.

(RefLink[PearsonCorrelationTest, paclet:ref/PearsonCorrelationTest]) is based on the Pearson product-moment correlation r computed by (RefLink[Correlation, paclet:ref/Correlation])[(Subscript[v, 1]),(Subscript[v, 2])]. Under (Subscript[H, 0]), r (Sqrt[(n-2)/(1-(r^2))]) asymptotically follows a (RefLink[StudentTDistribution, paclet:ref/StudentTDistribution])[n-2].

(RefLink[PearsonCorrelationTest, paclet:ref/PearsonCorrelationTest])[(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[PearsonCorrelationTest, paclet:ref/PearsonCorrelationTest])[(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  (28)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Test whether two vectors are independent:

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

ListPlot[Transpose[{v1,v2}]]

PearsonCorrelationTest[v1,v2,"TestDataTable"]

OpenersExampleSection1(Spacer1)Scope  (7)

OpenersExampleSubsection0(Spacer1)Testing  (4)

Test whether two vectors are independent:

BlockRandom[SeedRandom[2];{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:

PearsonCorrelationTest[v1,v2]

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

PearsonCorrelationTest[v3,v4]

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

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

ℋ=PearsonCorrelationTest[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]];

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

The p-value and test statistic from the test:

ℋ["PValue"]

ℋ["TestStatistic"]

Extract any number of properties simultaneously:

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

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

The p-value, test statistic, and degrees of freedom:

ℋ["PValue","TestStatistic","DegreesOfFreedom"]

OpenersExampleSubsection1(Spacer1)Reporting  (3)

Tabulate the results from the test:

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

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

A table of the test results:

ℋ["TestDataTable"]

Retrieve the entries from a test table for customized reporting:

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

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

res=ℋ["TestData"]

Labeled[ProgressIndicator[res[[2]]],Row[{Style["𝓇: ",Bold,FontSize->14],res[[1]]}]]

Tabulate the p-value or test statistic:

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

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

ℋ["PValueTable"]

The p-value from the table:

ℋ["PValue"]

ℋ["TestStatisticTable"]

The test statistic from the table:

ℋ["TestStatistic"]

OpenersExampleSection2(Spacer1)Options  (12)

OpenersExampleSubsection2(Spacer1)AlternativeHypothesis  (2)

A two-sided test is performed by default:

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

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

PearsonCorrelationTest[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:

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

The two one-sided alternatives:

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

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

OpenersExampleSubsection3(Spacer1)Method  (4)

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

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

PearsonCorrelationTest[v1,v2,Method->Automatic]

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

The p-value can be obtained using permutation methods:

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

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

Set the number of permutations to use:

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

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

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

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

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

Set the seed used for generating random permutations:

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

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

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

OpenersExampleSubsection4(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"]

OpenersExampleSubsection5(Spacer1)VerifyTestAssumptions  (3)

By default, normality is tested when appropriate:

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

PearsonCorrelationTest[v1,v2,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:

PearsonCorrelationTest[v1,v2,VerifyTestAssumptions->All]

Check no assumptions:

PearsonCorrelationTest[v1,v2,VerifyTestAssumptions->None]

Diagnostics can be controlled independently:

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

Check for normality:

PearsonCorrelationTest[v1,v2,VerifyTestAssumptions->"Normality"]

Explicitly set the diagnostic result:

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

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

OpenersExampleSection3(Spacer1)Properties & Relations  (7)

The test statistic is equivalent to (RefLink[Correlation, paclet:ref/Correlation]):

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

PearsonCorrelationTest[v1,v2,"TestStatistic"]

Correlation[v1,v2]

Under (Subscript[H, 0]), the test statistic asymptotically follows a (RefLink[StudentTDistribution, paclet:ref/StudentTDistribution])[n-2]:

n=100;

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

r=PearsonCorrelationTest[Sequence@@Transpose[#],"TestStatistic",VerifyTestAssumptions->None]&/@data;

rTrans=r (Sqrt[(n-2)/(1-(r^2))]);

QuantilePlot[rTrans,StudentTDistribution[n-2]]

DistributionFitTest[rTrans,StudentTDistribution[n-2]]

Use (RefLink[SpearmanRankTest, paclet:ref/SpearmanRankTest]) for non-normal distributions:

𝒟 = MultivariateTDistribution[{{1,0},{0,1}},3];

data=RandomVariate[𝒟,{1000,100}];

r=PearsonCorrelationTest[Sequence@@Transpose[#],VerifyTestAssumptions->None]&/@data;

ρ=SpearmanRankTest[Sequence@@Transpose[#]]&/@data;

Tests based on Spearman's ρ do a better job of preserving the size of the test:

Histogram[{r,ρ}]

A table of expected and observed test sizes:

Grid[{{"α","(Subscript[α, r])","(Subscript[α, ρ])"}}~Join~Table[{α,Probability[p≤α,p\[Distributed]r],Probability[p≤α,p\[Distributed]ρ]},{α,{0.001,.01,.05,.1,.25}}]//N]

(RefLink[IndependenceTest, paclet:ref/IndependenceTest]) can be used to automatically select an appropriate test:

𝒟 = MultivariateTDistribution[{{1,0},{0,1}},3];

data=RandomVariate[𝒟,100];

IndependenceTest[data[[All,1]],data[[All,2]],"TestDataTable"]

Use (RefLink[CorrelationTest, paclet:ref/CorrelationTest]) to test a particular value of r:

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

Correlation[v1,v2]

CorrelationTest[Transpose[{v1,v2}],.8,{"TestDataTable","PearsonCorrelation"}]

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

ts1=TimeSeries[];

ts2=TimeSeries[];

PearsonCorrelationTest[ts1,ts2]

PearsonCorrelationTest[ts1["Values"],ts2["Values"]]

The Pearson correlation test works with all the values together when the input is a (RefLink[TemporalData, paclet:ref/TemporalData]):

td=TemporalData[];

PearsonCorrelationTest[td]

Test selected components of the temporal data explicitly:

paths=td["Components"]

PearsonCorrelationTest[paths[[2]],paths[[3]]]

Use the values directly:

Evaluate[Array[data,4]]=td["ValueList"];

PearsonCorrelationTest[data[2],data[3]]

OpenersExampleSection4(Spacer1)Neat Examples  (1)

Compute the statistic when the null hypothesis (Subscript[H, 0]) is true:

data1=RandomVariate[BinormalDistribution[0.],{1500,100}];

T1=MapThread[PearsonCorrelationTest[#1,#2,"TestStatistic",VerifyTestAssumptions->None]&,{data1[[All,All,1]],data1[[All,All,2]]}];

The test statistic given a particular alternative:

data2=RandomVariate[BinormalDistribution[0.7],{1500,100}];

T2=MapThread[PearsonCorrelationTest[#1,#2,"TestStatistic",VerifyTestAssumptions->None]&,{data2[[All,All,1]],data2[[All,All,2]]}];

Compare the distributions of the test statistics:

SmoothHistogram[{T1,T2},Filling->Axis,PlotLegends->{"(Subscript[H, 0]) is True","(Subscript[H, 0]) is False"}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BlomqvistBetaTest, paclet:ref/BlomqvistBetaTest])  ▪  (RefLink[Correlation, paclet:ref/Correlation])  ▪  (RefLink[CorrelationTest, paclet:ref/CorrelationTest])  ▪  (RefLink[GoodmanKruskalGammaTest, paclet:ref/GoodmanKruskalGammaTest])  ▪  (RefLink[HoeffdingDTest, paclet:ref/HoeffdingDTest])  ▪  (RefLink[IndependenceTest, paclet:ref/IndependenceTest])  ▪  (RefLink[KendallTauTest, paclet:ref/KendallTauTest])  ▪  (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])}})}})