({{, (RefLink[PairedTTest, paclet:ref/PairedTTest])[data] 
tests whether the mean of data is zero. }, {, (RefLink[PairedTTest, paclet:ref/PairedTTest])[{(Subscript[data, 1]),(Subscript[data, 2])}]
tests whether the mean of (Subscript[data, 1])– (Subscript[data, 2]) is zero.}, {, (RefLink[PairedTTest, paclet:ref/PairedTTest])[dspec,(Subscript[μ, 0])]
tests a location measure against (Subscript[μ, 0]).}, {, (RefLink[PairedTTest, paclet:ref/PairedTTest])[dspec,(Subscript[μ, 0]),"property"]
returns the value of "property".}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[PairedTTest, paclet:ref/PairedTTest]) 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]),…},…}.

If two samples are given, they must be of equal length.

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

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

Properties related to the reporting of test results include:

(RefLink[PairedTTest, paclet:ref/PairedTTest]) is more powerful than the (RefLink[TTest, paclet:ref/TTest]) when samples are matched.

For univariate samples, (RefLink[PairedTTest, paclet:ref/PairedTTest]) performs the Student t test for matched pairs. The test statistic is assumed to follow a (RefLink[StudentTDistribution, paclet:ref/StudentTDistribution]).

For multivariate samples, (RefLink[PairedTTest, paclet:ref/PairedTTest]) performs Hotelling's (T^2) test for matched pairs. The test statistic is assumed to follow a (RefLink[HotellingTSquareDistribution, paclet:ref/HotellingTSquareDistribution]).

The following options can be used:

For the (RefLink[PairedTTest, paclet:ref/PairedTTest]), 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 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[PairedTTest, paclet:ref/PairedTTest]) 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)];

PairedTTest[data]

The full test table:

PairedTTest[data,Automatic,"TestDataTable"]

Test whether the means of two dependent populations differ:

{data1,data2}=BlockRandom[SeedRandom[1];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:

PairedTTest[{data1,data2}]

Compare the locations of dependent multivariate populations:

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

PairedTTest[{data1,data2}]

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]):

PairedTTest[data1]

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

PairedTTest[data2]

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

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

PairedTTest[data,0]

PairedTTest[data,Automatic]

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

BlockRandom[SeedRandom[22];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]):

PairedTTest[data1,3]

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

PairedTTest[data2,3]

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

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

PairedTTest[data]

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

PairedTTest[data,{0.1,0,-.05,0}]

Test whether the mean of differenced datasets is zero:

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

PairedTTest[{data1,data2},0]

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

PairedTTest[{data1,data3},0]

Test whether the mean of differenced data is 3:

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

The order of the datasets affects the test results:

PairedTTest[{data1,data2},3]

PairedTTest[{data2,data1},3]

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

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

PairedTTest[{data1,data2}]

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

PairedTTest[{data1,data2},{1,0,-1,0}]

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

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

ℋ=PairedTTest[data,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)}];

ℋ=PairedTTest[data,0,"HypothesisTestData"];

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

ℋ["PValue"]

ℋ["TestStatistic"]

ℋ["DegreesOfFreedom"]

Extract any number of properties simultaneously:

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

ℋ=PairedTTest[data,0,"HypothesisTestData"];

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

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

OpenersExampleSubsection1(Spacer1)Reporting  (3)

Tabulate the test results:

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

ℋ=PairedTTest[data,0,"HypothesisTestData"];

ℋ["TestDataTable"]

Retrieve the entries from a test table for customized reporting:

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

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

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

Tabulate p-values or test statistics:

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

ℋ=PairedTTest[data,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:

PairedTTest[data,0,AlternativeHypothesis->"Unequal"]

PairedTTest[data,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:

PairedTTest[data,0,AlternativeHypothesis->"Unequal"]

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

PairedTTest[data,0,AlternativeHypothesis->"Less"]

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

PairedTTest[data,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:

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

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

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

OpenersExampleSubsection3(Spacer1)SignificanceLevel  (2)

Set the significance level for diagnostic tests:

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

PairedTTest[data,0,SignificanceLevel->.0001]

By default, 0.05 is used:

PairedTTest[data,0]

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

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

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

ℋ2=PairedTTest[data,.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:

PairedTTest[data,0,VerifyTestAssumptions->None]

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

PairedTTest[data,0,VerifyTestAssumptions->"Normality"]

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

PairedTTest[data,0,VerifyTestAssumptions->All]

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

PairedTTest[data,0,VerifyTestAssumptions->"Normality"->True]

Bypassing diagnostic tests can save compute time:

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

PairedTTest[data,Automatic,"TestDataTable",VerifyTestAssumptions->All]//AbsoluteTiming

PairedTTest[data,Automatic,"TestDataTable",VerifyTestAssumptions->None]//AbsoluteTiming

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

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

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

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

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

The results are identical:

SmoothHistogram[{T,T2}]

OpenersExampleSection3(Spacer1)Applications  (1)

A group of 15 students is convinced that they were more prepared for the mathematics portion of the ACT than that of the SAT. Test this claim assuming that national ACT and SAT scores are normally distributed with means 21.7 and 528.5 and standard deviations 4.1 and 117.2, respectively:

act={25,24,18,22,22,25,28,22,22,28,21,24,33,28,24};

sat={649,518,300,497,550,656,700,574,479,661,476,641,793,667,520};

For comparison, the data should be normalized:

actS=((act-21.7)/4.1);
satS=((sat-528.5)/117.2);

Density estimates for the individual and differenced scores:

{SmoothHistogram[{actS,satS}],SmoothHistogram[actS-satS]}

(Subscript[H, 0]) can be rejected at the 5% level. The students' claim is not refuted:

PairedTTest[{actS,satS},0,"TestDataTable",AlternativeHypothesis->"Greater"]

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

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

data=RandomVariate[NormalDistribution[],100];

PairedTTest[data,Automatic,"TestDataTable"]

TTest[data,Automatic,"TestDataTable"]

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

data1=RandomVariate[NormalDistribution[],100];
data2=RandomVariate[NormalDistribution[],100];

PairedTTest[{data1,data2},Automatic,"TestDataTable"]

TTest[data1-data2,Automatic,"TestDataTable"]

If the variance of the population is known, the more powerful (RefLink[PairedZTest, paclet:ref/PairedZTest]) can be used:

data=RandomVariate[NormalDistribution[.5,1],{10000,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[PairedTTest, paclet:ref/PairedTTest]) is more powerful than the (RefLink[TTest, paclet:ref/TTest]):

{data1,data2}=BlockRandom[SeedRandom[9];Transpose@RandomVariate[BinormalDistribution[.999],100]];

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

PairedTTest[{data1,data2},0,"TestDataTable"]

TTest[{data1,data2},0,"TestDataTable"]

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

ts=TimeSeries[];

PairedTTest[ts]

PairedTTest[ts["Values"]]

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

td=TemporalData[];

PairedTTest[td]

Test all the values only:

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

Test the difference of the means of the two paths:

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

PairedTTest[{data1,data2}]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

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

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

PairedTTest[data]

Use a median-based test instead:

SignTest[data]

OpenersExampleSection6(Spacer1)Neat Examples  (1)

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

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

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

The test statistic given a particular alternative:

T2=PairedTTest[#,2,"TestStatistic",VerifyTestAssumptions->None]&/@data;

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[PairedZTest, paclet:ref/PairedZTest])  ▪  (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])}})}})