({{, (RefLink[PairedZTest, paclet:ref/PairedZTest])[data] 
tests whether the mean of the data is zero. }, {, (RefLink[PairedZTest, paclet:ref/PairedZTest])[{(Subscript[data, 1]),(Subscript[data, 2])}]
tests whether the means of (Subscript[data, 1]) and (Subscript[data, 2]) are equal.}, {, (RefLink[PairedZTest, paclet:ref/PairedZTest])[dspec,σ]
tests for zero or equal means assuming a population variance σ.}, {, (RefLink[PairedZTest, paclet:ref/PairedZTest])[dspec,σ,(Subscript[μ, 0])]
tests the mean against (Subscript[μ, 0]).}, {, (RefLink[PairedZTest, paclet:ref/PairedZTest])[dspec,σ,(Subscript[μ, 0]),"property"]
returns the value of "property".}})

OpenersNotesSection(Spacer1)Details and Options

Given (Subscript[data, 1]) and (Subscript[data, 2]), (RefLink[PairedZTest, paclet:ref/PairedZTest]) performs a test on the paired differences of the two datasets.

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

where μ is the population mean for data and (Subscript[μ, 12]) is the mean of the paired differences of the two datasets (Subscript[data, 1])-(Subscript[data, 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 in dspec can be univariate {(Subscript[x, 1]),(Subscript[x, 2]),…} or multivariate {{(Subscript[x, 1]),(Subscript[y, 1]),…},{(Subscript[x, 2]),(Subscript[y, 2]),…},…}.

The argument σ can be any positive real number or a positive definite matrix with dimension equal to the dimension of data.

The argument (Subscript[μ, 0]) can be a real number or a real vector with length equal to the dimension of the data.

(RefLink[PairedZTest, paclet:ref/PairedZTest]) assumes that the data is normally distributed and that the variance is known and not estimated from the data.

If variances or covariance matrices are not provided, (RefLink[PairedZTest, paclet:ref/PairedZTest]) treats the sample estimate as the known variance or covariance.

(RefLink[PairedZTest, paclet:ref/PairedZTest])[dspec,σ,(Subscript[μ, 0]),"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[PairedZTest, paclet:ref/PairedZTest])[dspec,σ,(Subscript[μ, 0]),"property"] can be used to directly give the value of "property".

Properties related to the reporting of test results include:

If a known variance σ is not provided, (RefLink[PairedZTest, paclet:ref/PairedZTest]) performs a z-test assuming the sample variance is the known variance for univariate data and Hotelling's (T^2) test assuming the sample covariance is the known covariance for multivariate data.

Options include:

For tests of location, a cutoff α is chosen such that (Subscript[H, 0]) is rejected if and 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 assumptions including tests for normality, equal variance, and symmetry. By default, α is set to 0.05.

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

OpenersPrimaryExamplesSection(Spacer1)Examples  (33)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Test whether the mean of a population is zero:

data=RandomVariate[NormalDistribution[0.05,1],(10^4)];

PairedZTest[data,1]

The full test table:

PairedZTest[data,1,Automatic,"TestDataTable"]

Test whether the means of two dependent populations differ:

{data1,data2}=BlockRandom[SeedRandom[2];Transpose@RandomVariate[BinormalDistribution[.5],1000]];

The mean of the differences:

Mean[data1-data2]

SmoothHistogram[data1-data2]

At the 0.05 level, the mean of the differenced data is not significantly different from 0:

PairedZTest[{data1,data2},1]

Compare the locations of dependent multivariate populations:

BlockRandom[SeedRandom[1];data1=RandomVariate[MultinormalDistribution[{0,0},IdentityMatrix[2]],1000];
data2=RandomVariate[MultinormalDistribution[{0,0},IdentityMatrix[2]],1000]];

The mean of the differences:

Mean[data1-data2]

Histogram3D[{data1-data2}]

At the 0.05 level, the mean of the differenced data is not significantly different from 0:

PairedZTest[{data1,data2},IdentityMatrix[2]]

OpenersExampleSection1(Spacer1)Scope  (13)

OpenersExampleSubsection0(Spacer1)Testing  (10)

Test (Subscript[H, 0]): μ=0 versus (Subscript[H, a]):μ≠0:

BlockRandom[SeedRandom[2];data1=RandomVariate[NormalDistribution[0,1],500];
data2=RandomVariate[NormalDistribution[3,1],500]];

The p-values are typically large when the mean is close to (Subscript[μ, 0]):

PairedZTest[data1,1]

The p-values are typically small when the location is far from (Subscript[μ, 0]):

PairedZTest[data2,1]

Using (RefLink[Automatic, paclet:ref/Automatic]) is equivalent to testing for a mean of zero:

data=RandomVariate[NormalDistribution[0,1],500];

PairedZTest[data,1,0]

PairedZTest[data,1,Automatic]

Test (Subscript[H, 0]): μ=3 versus (Subscript[H, a]):μ≠3:

BlockRandom[SeedRandom[4];data1=RandomVariate[NormalDistribution[3,1],500];
data2=RandomVariate[NormalDistribution[0,1],200]];

The p-values are typically large when the mean is close to (Subscript[μ, 0]):

PairedZTest[data1,1,3]

The p-values are typically small when the location is far from (Subscript[μ, 0]):

PairedZTest[data2,1,3]

Test whether the mean vector of a multivariate population is the zero vector:

data=RandomVariate[MultinormalDistribution[{.1,0,-.05,0},IdentityMatrix[4]],(10^3)];

PairedZTest[data,IdentityMatrix[4]]

Alternatively, test against {0.1,0,-0.05,0}:

PairedZTest[data,IdentityMatrix[4],{0.1,0,-.05,0}]

Test whether the mean of differenced datasets is zero:

BlockRandom[SeedRandom[21];data1=RandomVariate[NormalDistribution[0,1],150];
data2=RandomVariate[NormalDistribution[1,1],150];
data3=RandomVariate[NormalDistribution[0,2],150]];

The p-values are generally small when the mean is not zero:

PairedZTest[{data1,data2},1,0]

The p-values are generally large when the mean is zero:

PairedZTest[{data1,data3},5,0]

Test whether the mean of differenced data is 3:

BlockRandom[SeedRandom[34];data1=RandomVariate[NormalDistribution[3,1],100];
data2=RandomVariate[NormalDistribution[0,1],100]];

The order of the datasets affects the test results:

PairedZTest[{data1,data2},1,3]

PairedZTest[{data2,data1},1,3]

Test whether the mean vector of differenced multivariate datasets is the zero vector:

BlockRandom[SeedRandom[2];data1=RandomVariate[MultinormalDistribution[{.5,0,-.5,0},IdentityMatrix[4]],135];
data2=RandomVariate[MultinormalDistribution[{-.5,0,.5,0},IdentityMatrix[4]],135]];

PairedZTest[{data1,data2},IdentityMatrix[4]]

Alternatively, test against {1,0,-1,0}:

PairedZTest[{data1,data2},IdentityMatrix[4],{1,0,-1,0}]

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

data=RandomVariate[NormalDistribution[],{2,(10^4)}];

ℋ=PairedZTest[data,1,0,"HypothesisTestData"];

The properties available for extraction:

ℋ["Properties"]

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

data=RandomVariate[NormalDistribution[],{2,(10^4)}];

ℋ=PairedZTest[data,1,0,"HypothesisTestData"];

The p-value and test statistic:

ℋ["PValue"]

ℋ["TestStatistic"]

Extract any number of properties simultaneously:

data=RandomVariate[NormalDistribution[],{2,(10^4)}];

ℋ=PairedZTest[data,1,0,"HypothesisTestData"];

The p-value and test statistic:

ℋ["PValue","TestStatistic"]

OpenersExampleSubsection1(Spacer1)Reporting  (3)

Tabulate the test results:

data=RandomVariate[NormalDistribution[],{2,20}];

ℋ=PairedZTest[data,1,0,"HypothesisTestData"];

ℋ["TestDataTable"]

Retrieve the entries from a test table for customized reporting:

data=RandomVariate[NormalDistribution[],{1000,25}];

res=Table[PairedZTest[i,1,0,"TestData",VerifyTestAssumptions->None],{i,data}];

ListPlot[res,FrameLabel->{"Z","p-value"},Frame->True,PlotRange->All]

Tabulate p-values or test statistics:

data=RandomVariate[NormalDistribution[],{2,(10^2)}];

ℋ=PairedZTest[data,1,0,"HypothesisTestData"];

ℋ["PValueTable"]

The p-value from the table:

ℋ["PValue"]

ℋ["TestStatisticTable"]

The test statistic from the table:

ℋ["TestStatistic"]

OpenersExampleSection2(Spacer1)Options  (8)

OpenersExampleSubsection2(Spacer1)AlternativeHypothesis  (3)

A two-sided test is performed by default:

data=RandomVariate[NormalDistribution[],100];

Test (Subscript[H, 0]):μ=0 versus (Subscript[H, a]):μ≠0:

PairedZTest[data,1,0,AlternativeHypothesis->"Unequal"]

PairedZTest[data,1,0,AlternativeHypothesis->Automatic]

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

data=RandomVariate[NormalDistribution[],100];

Test (Subscript[H, 0]):μ=0 versus (Subscript[H, a]):μ≠0:

PairedZTest[data,1,0,AlternativeHypothesis->"Unequal"]

Test (Subscript[H, 0]):μ≥0 versus (Subscript[H, a]):μ<0:

PairedZTest[data,1,0,AlternativeHypothesis->"Less"]

Test (Subscript[H, 0]):μ≤0 versus (Subscript[H, a]):μ>0:

PairedZTest[data,1,0,AlternativeHypothesis->"Greater"]

Perform tests with one-sided alternatives when (Subscript[μ, 0]) is given:

data1=RandomVariate[NormalDistribution[2.9,1],1000];
data2=RandomVariate[NormalDistribution[0,1],1000];

Mean[data1-data2]

Test (Subscript[H, 0]): μ≥3  versus (Subscript[H, a]): μ<3:

PairedZTest[{data1,data2},2,3,AlternativeHypothesis->"Less"]

Test (Subscript[H, 0]): μ≥2.9  versus (Subscript[H, a]): μ<2.9:

PairedZTest[{data1,data2},2,2.9,AlternativeHypothesis->"Less"]

OpenersExampleSubsection3(Spacer1)SignificanceLevel  (2)

Set the significance level for diagnostic tests:

data=BlockRandom[SeedRandom[2];RandomVariate[StudentTDistribution[3],50]];

PairedZTest[data,3,0,SignificanceLevel->.0001]

By default, 0.05 is used:

PairedZTest[data,3,0]

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

BlockRandom[SeedRandom[1];data=RandomVariate[NormalDistribution[0,1],100]];

ℋ1=PairedZTest[data,1,.2,"HypothesisTestData",SignificanceLevel->.1];

ℋ2=PairedZTest[data,1,.2,"HypothesisTestData",SignificanceLevel->.01];

ℋ1["TestConclusion"]//TraditionalForm

ℋ2["TestConclusion"]//TraditionalForm

ℋ1["ShortTestConclusion"]

ℋ2["ShortTestConclusion"]

OpenersExampleSubsection4(Spacer1)VerifyTestAssumptions  (3)

By default, normality is tested:

data=RandomVariate[CauchyDistribution[0,1],100];

Here, normality is assumed:

PairedZTest[data,1,0,VerifyTestAssumptions->None]

The result is the same, but a warning is issued:

PairedZTest[data,1,0,VerifyTestAssumptions->"Normality"]

Alternatively, use (RefLink[All, paclet:ref/All]):

PairedZTest[data,1,0,VerifyTestAssumptions->All]

Set the normality assumption to (RefLink[True, paclet:ref/True]):

PairedZTest[data,1,0,VerifyTestAssumptions->"Normality"->True]

Bypassing diagnostic tests can save compute time:

data=RandomVariate[MultinormalDistribution[{0,0,0},IdentityMatrix[3]],10^4];

PairedZTest[data,IdentityMatrix[3],Automatic,"TestDataTable",VerifyTestAssumptions->All]//AbsoluteTiming

PairedZTest[data,IdentityMatrix[3],Automatic,"TestDataTable",VerifyTestAssumptions->None]//AbsoluteTiming

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

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

AbsoluteTiming[T=Quiet@PairedZTest[#,1,Automatic,"TestStatistic"]&/@data;]

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

AbsoluteTiming[T2=Quiet@PairedZTest[#,1,Automatic,"TestStatistic",VerifyTestAssumptions->None]&/@data;]

The results are identical:

SmoothHistogram[{T,T2}]

OpenersExampleSection3(Spacer1)Applications  (1)

On average, a person's arm span is approximately equal to his or her height. A college rowing team was measured with the expectation that their arm spans would be significantly greater than their heights. Assume that the standard deviation for the height and arm span of the adult population is 0.4 ft.:

armSpan={6.27,5.82,6.13,6.14,5.96,6.57,6.03,6.06,6.16,6.72};

ht={6.21,5.42,5.75,5.97,5.46,6.24,5.62,5.66,6.11,6.31};

An estimate of the distribution for the difference in arm span and height:

SmoothHistogram[armSpan-ht]

The rowing team's arm spans are significantly greater than their heights:

PairedZTest[{armSpan,ht},((.4)^2),0,"TestDataTable",AlternativeHypothesis->"Greater"]

You might also be interested in the ratio of arm span to height:

SmoothHistogram[armSpan/ht]

The (RefLink[PairedZTest, paclet:ref/PairedZTest]) should not be used to test this since the ratio of two normal random variables is not normal:

SignedRankTest[armSpan/ht,1,"TestDataTable",AlternativeHypothesis->"Greater"]

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

(RefLink[PairedZTest, paclet:ref/PairedZTest]) is equivalent to a (RefLink[ZTest, paclet:ref/ZTest]) for a single dataset:

data=RandomVariate[NormalDistribution[],100];

PairedZTest[data,1,Automatic,"TestDataTable"]

ZTest[data,1,Automatic,"TestDataTable"]

For two datasets, the (RefLink[PairedZTest, paclet:ref/PairedZTest]) is equivalent to a (RefLink[ZTest, paclet:ref/ZTest]) of the paired differences:

data1=RandomVariate[NormalDistribution[],100];
data2=RandomVariate[NormalDistribution[0,Sqrt@2],100];

PairedZTest[{data1,data2},{1,2},Automatic,"TestDataTable"]

The known variance:

Variance[TransformedDistribution[x-y,{x\[Distributed]NormalDistribution[],y\[Distributed]NormalDistribution[0,Sqrt@2]}]]

ZTest[data1-data2,3,Automatic,"TestDataTable"]

If the variance of the population is unknown, the less powerful (RefLink[PairedTTest, paclet:ref/PairedTTest]) should be used:

data=RandomVariate[NormalDistribution[.5,1],{1000,100}];

pT=PairedTTest[#,VerifyTestAssumptions->None]&/@data;

pZ=PairedZTest[#,1,VerifyTestAssumptions->None]&/@data;

The probability that the (RefLink[PairedZTest, paclet:ref/PairedZTest]) will return a p-value smaller than the (RefLink[PairedTTest, paclet:ref/PairedTTest]):

Probability[z<t,{t,z}\[Distributed]Transpose[{pT,pZ}]]//N

If the data can be paired, the (RefLink[PairedZTest, paclet:ref/PairedZTest]) is more powerful than the (RefLink[ZTest, paclet:ref/ZTest]):

{data1,data2}=BlockRandom[SeedRandom[9];Transpose@RandomVariate[MultinormalDistribution[{0,0},{{1,.99},{.99,3}}],1000]];

The paired test detects a significant difference where the unpaired test does not:

PairedZTest[{data1,data2},Automatic,0,"TestDataTable"]//Quiet

ZTest[{data1,data2},Automatic,0,"TestDataTable"]//Quiet

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

ts=TimeSeries[];

PairedZTest[ts]

PairedZTest[ts["Values"]]

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

td=TemporalData[];

PairedZTest[td]

Test all the values only:

data=td["ValueList"]//Flatten;
PairedZTest[data]

Test whether the means of the two paths are equal:

{data1,data2}=td["ValueList"];

PairedZTest[{data1,data2}]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

(RefLink[PairedZTest, paclet:ref/PairedZTest]) requires that the data be normally distributed:

data=RandomVariate[CauchyDistribution[0,1],100];

PairedZTest[data,1]

Use a median-based test:

SignTest[data]

OpenersExampleSection6(Spacer1)Neat Examples  (1)

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

data1=RandomVariate[NormalDistribution[],{250,100}];

T1=PairedZTest[#,1,0,"TestStatistic",VerifyTestAssumptions->None]&/@data1;

The test statistic given a particular alternative:

data2=RandomVariate[NormalDistribution[2,1],{250,100}];

T2=PairedZTest[#,1,0,"TestStatistic",VerifyTestAssumptions->None]&/@data2;

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[HypothesisTestData, paclet:ref/HypothesisTestData])  ▪  (RefLink[LocationTest, paclet:ref/LocationTest])  ▪  (RefLink[LocationEquivalenceTest, paclet:ref/LocationEquivalenceTest])  ▪  (RefLink[VarianceTest, paclet:ref/VarianceTest])  ▪  (RefLink[VarianceEquivalenceTest, paclet:ref/VarianceEquivalenceTest])  ▪  (RefLink[DistributionFitTest, paclet:ref/DistributionFitTest])  ▪  (RefLink[MannWhitneyTest, paclet:ref/MannWhitneyTest])  ▪  (RefLink[PairedTTest, paclet:ref/PairedTTest])  ▪  (RefLink[SignTest, paclet:ref/SignTest])  ▪  (RefLink[SignedRankTest, paclet:ref/SignedRankTest])  ▪  (RefLink[TTest, paclet:ref/TTest])  ▪  (RefLink[ZTest, paclet:ref/ZTest])}})}})

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