({{, (RefLink[LocationTest, paclet:ref/LocationTest])[data] 
tests whether the mean or median of the data is zero. }, {, (RefLink[LocationTest, paclet:ref/LocationTest])[{(Subscript[data, 1]),(Subscript[data, 2])}]
tests whether the means or medians of (Subscript[data, 1]) and (Subscript[data, 2]) are equal.}, {, (RefLink[LocationTest, paclet:ref/LocationTest])[dspec,(Subscript[μ, 0])]
tests a location measure against (Subscript[μ, 0]).}, {, (RefLink[LocationTest, paclet:ref/LocationTest])[dspec,(Subscript[μ, 0]),"property"]
returns the value of "property".}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[LocationTest, paclet:ref/LocationTest]) performs a hypothesis test on data with null hypothesis (Subscript[H, 0]) that the true population location parameter is some value μ=(Subscript[μ, 0]), and alternative hypothesis (Subscript[H, a]) that μ≠(Subscript[μ, 0]).

Given (Subscript[data, 1]) and (Subscript[data, 2]), (RefLink[LocationTest, paclet:ref/LocationTest]) tests null hypothesis (Subscript[H, 0]) against alternative hypothesis (Subscript[H, a]), where (Subscript[H, 0]) and (Subscript[H, a]) are defined for each test accordingly.

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 (Subscript[μ, 0]) can be a real number or a real vector with length equal to the dimension of the data.

(RefLink[LocationTest, paclet:ref/LocationTest])[dspec] will choose the most powerful test that applies to dspec.

(RefLink[LocationTest, paclet:ref/LocationTest])[dspec,(RefLink[Automatic, paclet:ref/Automatic])] is equivalent to (Subscript[μ, 0])=0.

(RefLink[LocationTest, paclet:ref/LocationTest])[dspec,(Subscript[μ, 0]),(RefLink[All, paclet:ref/All])] will choose all tests that apply to dspec.

(RefLink[LocationTest, paclet:ref/LocationTest])[dspec,(Subscript[μ, 0]),"test"] reports the p-value according to "test".

Tests based on means assume the data in dspec is normally distributed. Some tests assume the data is symmetric about a common median. Tests that do not assume symmetry or normality are classified as robust.

A paired sample test assumes equal-length dependent data.

The following tests can be used:

The "T" test performs Student t-test for univariate data and Hotelling's (T^2) test for multivariate data.

The "Z" test 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.

The "PairedT" and "PairedZ" tests perform "T" and "Z" tests on the paired differences of two datasets. A single dataset is treated as a list of differences.

(RefLink[LocationTest, paclet:ref/LocationTest])[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[LocationTest, paclet:ref/LocationTest])[dspec,(Subscript[μ, 0]),"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 location, 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[LocationTest, paclet:ref/LocationTest]) include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (58)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Test whether the mean or median of a population is zero using a collection of tests:

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

Mean[data]

ℋ=LocationTest[data,Automatic,{"TestDataTable",All}]

Test whether the means of two populations differ by 2:

BlockRandom[SeedRandom[1];data1=RandomVariate[NormalDistribution[1.85,1],1000];
data2=RandomVariate[NormalDistribution[0,1],1000];]

The mean difference (Subscript[μ, 1])-(Subscript[μ, 2]):

Mean[data1]-Mean[data2]

SmoothHistogram[{data1,data2+2}]

At the 0.05 level, (Subscript[μ, 1])-(Subscript[μ, 2]) is significantly different from 2:

LocationTest[{data1,data2},2]

Compare the locations of multivariate populations:

data1=RandomVariate[MultinormalDistribution[{1,2},IdentityMatrix[2]],(10^3)];
data2=RandomVariate[MultinormalDistribution[{0,0},IdentityMatrix[2]],(10^3)];

The mean difference vector (Subscript[μ, 1])-(Subscript[μ, 2]):

Mean[data1]-Mean[data2]

Histogram3D[{data1,Transpose[Transpose[data2]+{1,2}]},40]

At the 0.05 level, (Subscript[μ, 1])-(Subscript[μ, 2]) is not significantly different from {1,2}:

LocationTest[{data1,data2},{1,2}]

OpenersExampleSection1(Spacer1)Scope  (17)

OpenersExampleSubsection0(Spacer1)Testing  (13)

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

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

The p-values are typically large when the mean is close to 0:

LocationTest[data1]

The p-values are typically small when the mean is far from 0:

LocationTest[data2]

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

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

LocationTest[data,0]

LocationTest[data,Automatic]

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

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

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

LocationTest[data1,3]

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

LocationTest[data2,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)];

LocationTest[data]

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

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

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

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

LocationTest[data,0,Automatic]

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

LocationTest[data,0,"AutomaticTest"]

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

data1=RandomVariate[NormalDistribution[0,1],100];
data2=RandomVariate[NormalDistribution[1,1],100];
data3=RandomVariate[NormalDistribution[0,2],100];

The p-values are generally small when the locations are not equal:

LocationTest[{data1,data2},0]

The p-values are generally large when the locations are equal:

LocationTest[{data1,data3},0]

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

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

The order of the datasets affects the test results:

LocationTest[{data1,data2},3]

LocationTest[{data2,data1},3]

Test whether the mean difference vector of two multivariate populations is the zero vector:

data1=RandomVariate[MultinormalDistribution[{.5,0,-.5,0},IdentityMatrix[4]],(10^2)];

data2=RandomVariate[MultinormalDistribution[{-.5,0,.5,0},IdentityMatrix[4]],(10^2)];

LocationTest[{data1,data2}]

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

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

Perform a particular test for equal locations:

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

LocationTest[data,0,"T"]

Any number of tests can be performed simultaneously:

LocationTest[data,0,{"T","Sign","MannWhitney"}]

Perform all tests appropriate to the data simultaneously:

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

LocationTest[data,0,All]

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

LocationTest[data,0,"AllTests"]

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

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

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

The properties available for extraction:

ℋ["Properties"]

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

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

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

The p-value and test statistic from a t-type test:

ℋ["PValue","T"]

ℋ["TestStatistic","T"]

Extract any number of properties simultaneously:

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

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

The p-value and test statistic from a Mann–Whitney test:

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

OpenersExampleSubsection1(Spacer1)Reporting  (4)

Tabulate the results from a selection of tests:

data1=RandomVariate[NormalDistribution[],2000];
data2=RandomVariate[NormalDistribution[],2300];

ℋ=LocationTest[{data1,data2},0,"HypothesisTestData"];

A full table of all appropriate test results:

ℋ["TestDataTable",All]

A table of selected test results:

ℋ["TestDataTable",{"T","Z"}]

Retrieve the entries from a test table for customized reporting:

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

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

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

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

ℋ["PValueTable","T"]

The p-value from the table:

ℋ["PValue","T"]

A table of p-values from all appropriate tests:

ℋ["PValueTable",All]

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

ℋ["PValueTable",{"T","Sign","MannWhitney"}]

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

data=RandomVariate[CauchyDistribution[1,2],{2,(10^3)}];

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

ℋ[Automatic]

The test statistic from the table:

ℋ["TestStatistic"]

A table of test statistics from all appropriate tests:

ℋ["TestStatisticTable",All]

OpenersExampleSection2(Spacer1)Options  (20)

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:

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

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

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

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

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

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

LocationTest[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]-Mean[data2]

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

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

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

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

OpenersExampleSubsection3(Spacer1)MaxIterations  (1)

Set the maximum number of iterations to use for multivariate median-based tests:

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

LocationTest[{data1,data2},Automatic,"Sign",MaxIterations->100]

LocationTest[{data1,data2},Automatic,"SignedRank",MaxIterations->100]

LocationTest[{data1,data2},Automatic,"MannWhitney",MaxIterations->100]

OpenersExampleSubsection4(Spacer1)Method  (6)

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

data=RandomVariate[NormalDistribution[],100];

LocationTest[data,0,Method->Automatic]

LocationTest[data,0,Method->"Asymptotic"]

For univariate median-based tests, p-values can be obtained using permutation methods:

data=RandomVariate[NormalDistribution[],35];

LocationTest[data,0,"SignedRank",Method->"Asymptotic"]

LocationTest[data,0,"SignedRank",Method->"Permutation"]

Set the number of permutations to use:

data=RandomVariate[NormalDistribution[],35];

LocationTest[data,0,"SignedRank",Method->{"Permutation","MonteCarloSamples"->(10^3)}]

LocationTest[data,0,"SignedRank",Method->{"Permutation","MonteCarloSamples"->(10^5)}]

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

LocationTest[data,0,"SignedRank",Method->{"Permutation","MonteCarloSamples"->(10^4)}]

For some tests, the permutation result is exact:

data=RandomVariate[NormalDistribution[],100];

LocationTest[data,0,"Sign",Method->"Permutation"]

The result is not affected by the number of permutations when exact tests are used:

LocationTest[data,0,"Sign",Method->{"Permutation","MonteCarloSamples"->(10^7)}]

For mean-based tests, the p-value is exact under the assumptions of the test:

data=RandomVariate[NormalDistribution[],35];

LocationTest[data,0,"T",Method->"Permutation"]

LocationTest[data,0,"T",Method->"Asymptotic"]

Set the seed used for generating random permutations:

data=RandomVariate[NormalDistribution[],35];

LocationTest[data,0,"SignedRank",Method->{"Permutation","RandomSeed"->0}]

LocationTest[data,0,"SignedRank",Method->{"Permutation","RandomSeed"->9}]

OpenersExampleSubsection5(Spacer1)SignificanceLevel  (3)

Set the significance level for diagnostic tests:

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

LocationTest[data,0,"T",SignificanceLevel->.0001]

By default, 0.05 is used:

LocationTest[data,0,"T"]

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

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

LocationTest[data,0,"AutomaticTest",SignificanceLevel->.0005]

A median-based test would have been chosen by default:

LocationTest[data,0,"AutomaticTest",SignificanceLevel->Automatic]

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

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

ℋ1=LocationTest[data,.395,"HypothesisTestData",SignificanceLevel->.05];

ℋ2=LocationTest[data,.395,"HypothesisTestData",SignificanceLevel->.00001];

ℋ1["TestConclusion"]//TraditionalForm

ℋ2["TestConclusion"]//TraditionalForm

ℋ1["ShortTestConclusion"]

ℋ2["ShortTestConclusion"]

OpenersExampleSubsection6(Spacer1)VerifyTestAssumptions  (7)

By default, normality and equal variance are tested when appropriate:

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

LocationTest[{data1,data2},0,"T",VerifyTestAssumptions->Automatic]

If assumptions are not checked, some test results may differ:

LocationTest[{data1,data2},0,"T",VerifyTestAssumptions->None]

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

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

Verify all assumptions:

LocationTest[{data1,data2},0,"T",VerifyTestAssumptions->All]

Check no assumptions:

LocationTest[{data1,data2},0,"T",VerifyTestAssumptions->None]

Diagnostics can be controlled independently:

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

Assume normality and symmetry but check for equal variances:

LocationTest[{data1,data2},0,"T",VerifyTestAssumptions->"EqualVariance"]

Only check for normality:

LocationTest[{data1,data2},0,"T",VerifyTestAssumptions->"Normality"]

Unlisted assumptions are not tested:

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

Normality is assumed:

LocationTest[data,0,"T",VerifyTestAssumptions->{"EqualVariance","Symmetry"}]

The result is the same but a warning is issued:

LocationTest[data,0,"T",VerifyTestAssumptions->All]

Test assumption values can be explicitly set:

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

LocationTest[data,0,"TestDataTable"]

LocationTest[data,0,"TestDataTable",VerifyTestAssumptions->"Normality"->True]

The sign test was previously chosen because the data is not normally distributed:

LocationTest[data,0,{"TestDataTable","T"}]

Bypassing diagnostic tests can save compute time:

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

LocationTest[data,Automatic,{"TestDataTable","T"},VerifyTestAssumptions->All]//AbsoluteTiming

LocationTest[data,Automatic,{"TestDataTable","T"},VerifyTestAssumptions->None]//AbsoluteTiming

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

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

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

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

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

The results are identical:

SmoothHistogram[{T,T2}]

OpenersExampleSection3(Spacer1)Applications  (4)

Test whether the locations of some populations are equivalent:

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

BoxWhiskerChart[{data1,data2,data3},"Notched",ChartStyle->"SolarColors"]

The first two populations have similar locations:

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

The third population differs in location from the first:

LocationTest[{data1,data3},Automatic,"TestDataTable"]

The heart and body weights of a group of house cats were obtained:

ExampleData[{"Statistics","FisherCats"},"ColumnDescriptions"]

{sex,heart,weight}=Transpose@ExampleData[{"Statistics","FisherCats"}];

The heart weight of male cats is significantly greater than that of female cats:

LocationTest[{Pick[heart,sex,"M"],Pick[heart,sex,"F"]},0,"TestDataTable",AlternativeHypothesis->"Greater"]

Perhaps male cats are just larger in general:

maleHBR=Pick[heart/weight,sex,"M"];
femaleHBR=Pick[heart/weight,sex,"F"];

SmoothHistogram[{maleHBR,femaleHBR},PlotLegends->{"maleHBR","femaleHBR"}]

The ratio of heart weight to body weight is not significantly different between the sexes:

LocationTest[{maleHBR,femaleHBR},0,"TestDataTable"]

Six measurements were taken for 100 counterfeit Swiss banknotes and 100 genuine ones:

data=ExampleData[{"Statistics","SwissBankNotes"}];

ExampleData[{"Statistics","SwissBankNotes"},"ColumnDescriptions"]

cBills=Pick[data[[All,{1,2}]],data[[All,-1]],1];
gBills=Pick[data[[All,{1,2}]],data[[All,-1]],0];

A plot of two of the measures for counterfeit and genuine notes:

ListPlot[{cBills,gBills},PlotStyle->{PointSize->.025},Frame->True,AspectRatio->1,PlotRange->{{213,217},{128,132}}]

A test of the bivariate median vectors shows a significant difference:

LocationTest[{cBills,gBills},0,{"TestDataTable","MannWhitney"}]

Samples were drawn from a pool of water at 10 randomly selected locations. Each sample was tested for zinc concentration at both the surface of the water and the bottom of the pool:

bottom={.430,.266,.567,.531,.707,.716,.651,.589,.469,.723};
surface={.415,.238,.390,.410,.605,.609,.632,.523,.411,.612};

A visual inspection of the data. The distance between the vertical bars shows the quantity being tested under an assumption of dependence and independence respectively:

MeanLine[data_,h_]:=Graphics[{Thick,Purple,Line[{{Mean[data],0},{Mean[data],h}}]}]

{Show[SmoothHistogram[bottom-surface,PlotLabel->"Paired",PlotStyle->Darker[Green]],MeanLine[bottom-surface,6],MeanLine[{0},6],Axes->{Automatic,None},ImageSize->200],Show[SmoothHistogram[{bottom,surface},PlotLabel->"Independent",PlotLegends->{"bottom","surface"}],MeanLine[bottom,2.5],MeanLine[surface,2.5],Axes->{Automatic,None},ImageSize->200]}

Assuming the data is paired yields a significant result not present under independence:

LocationTest[{bottom,surface},0,{"TestDataTable","PairedT"}]

LocationTest[{bottom,surface},0,{"TestDataTable","T"}]

Assume a laboratory test showed that zinc concentrations form a gradient that becomes higher with increasing depth. This information justifies the use of a one-sided alternative:

LocationTest[{bottom,surface},0,{"TestDataTable","PairedT"},AlternativeHypothesis->"Greater"]

OpenersExampleSection4(Spacer1)Properties & Relations  (9)

The p-value suggests the expected proportion of false positives (Type I errors):

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

pvals=Table[LocationTest[i,0,"T",VerifyTestAssumptions->None],{i,data}];

Setting the size of a test to 0.05 results in an erroneous rejection of (Subscript[H, 0]) about 5% of the time:

Probability[x≤0.05,x\[Distributed]pvals]//N

Type II errors arise when (Subscript[H, 0]) is not rejected, given it is false:

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

ℋs=Table[LocationTest[i,0,"T",VerifyTestAssumptions->None],{i,data}];

Increasing the size of the test lowers the Type II error rate:

ListLinePlot[Table[{sz,Probability[x>sz,x\[Distributed]ℋs]//N},{sz,Range[0.001,.25,.01]}],AxesLabel->{"Size","Type II Error"}]

The power of each test is the probability of rejecting (Subscript[H, 0]) when it is false:

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

tests={"Sign","SignedRank","T","Z"};

p=Transpose@Table[LocationTest[i,0,tests,VerifyTestAssumptions->None],{i,data}];

α={.001,.005,.01,.025,.05,.1};

The power of the tests at six different levels. The sign test has the lowest power in general:

N[Grid[Join[{Join[{""},α]},Table[Join[{tests[[i]]},(Probability[x≤#1,x\[Distributed]p[[i]]]&)/@α],{i,Length[tests]}]],Alignment->Left,Dividers->{{False,True},{False,True}}]]

The power of tests decreases with smaller sample sizes:

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

tests={"Sign","SignedRank","T","Z"};

p=Transpose@Table[LocationTest[i,0,tests,VerifyTestAssumptions->None],{i,data}];

α={.001,.005,.01,.025,.05,.1};

The power of the tests is lower than in the previous example:

N[Grid[Join[{Join[{""},α]},Table[Join[{tests[[i]]},(Probability[x≤#1,x\[Distributed]p[[i]]]&)/@α],{i,Length[tests]}]],Alignment->Left,Dividers->{{False,True},{False,True}}]]

For dependent samples, paired tests are more powerful than their non-paired counterparts:

data1=Sort@RandomVariate[NormalDistribution[1,1],{1000,20}];
data2=Sort@RandomVariate[NormalDistribution[1.5,1],{1000,20}];

tests={"T","PairedT","Z","PairedZ"};

p=Table[MapThread[LocationTest[{#1,#2},0,i,VerifyTestAssumptions->None]&,{data1,data2}],{i,tests}];

Paired tests assume observations in one dataset are matched with observations in the other:

N[Table[{tests[[i]],Probability[x≤0.05,x\[Distributed]p[[i]]]},{i,Length[tests]}]]//TableForm

A paired t-test is equivalent to a t-test applied to the point-wise differences of two datasets:

data1=Sort@RandomVariate[NormalDistribution[1,1],25];
data2=Sort@RandomVariate[NormalDistribution[1,1],25];

LocationTest[{data1,data2},0,{"TestDataTable","PairedT"}]

LocationTest[data1-data2,0,{"TestDataTable","T"}]

Paired tests assume that the data represents differences when given a single dataset:

LocationTest[data1-data2,0,{"TestDataTable","PairedT"}]

A two-sided p-value is twice the smaller of the two one-sided p-values:

data1=RandomVariate[NormalDistribution[0,1],100];
data2=RandomVariate[NormalDistribution[.5,1],100];

twoSided=LocationTest[{data1,data2},0,All,AlternativeHypothesis->"Unequal"];

minOneSided=Min/@Transpose[{LocationTest[{data1,data2},0,All,AlternativeHypothesis->"Less"],LocationTest[{data1,data2},0,All,AlternativeHypothesis->"Greater"]}];

twoSided-2 minOneSided

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

ts=TimeSeries[];

LocationTest[ts,Automatic,{"TestDataTable",All}]

LocationTest[ts["Values"],Automatic,{"TestDataTable",All}]

%%==%

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

td=TemporalData[];

LocationTest[td]

Test all the values only:

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

Test whether the means or medians of the two paths are equal:

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

LocationTest[{data1,data2}]

OpenersExampleSection5(Spacer1)Possible Issues  (3)

Unknown variances and covariances are estimated from the data when using z-type tests:

data1=RandomVariate[NormalDistribution[],1000];
data2=RandomVariate[NormalDistribution[],7];

For large samples, the estimation has little effect on the results:

LocationTest[data1,0,{"TestDataTable",{"T","Z"}}]

With small samples, t-type tests should be used to account for the estimation:

LocationTest[data2,0,{"TestDataTable",{"T","Z"}}]

Median-based tests should be used if the data is not normally distributed:

data=BlockRandom[SeedRandom[1];RandomVariate[StudentTDistribution[3],100]];

LocationTest[data,0,"T"]

Median-based tests do not assume normality:

LocationTest[data,0,"SignedRank"]

Changing the significance level affects internal diagnostics:

BlockRandom[SeedRandom[1];
data1=RandomVariate[NormalDistribution[0,1],35];
data2=RandomVariate[NormalDistribution[0,1.5],35];
]

ℋ1=LocationTest[{data1,data2},0,"HypothesisTestData",SignificanceLevel->.05];
ℋ2=LocationTest[{data1,data2},0,"HypothesisTestData",SignificanceLevel->.01];

The degrees of freedom are affected by a test for variance:

VarianceEquivalenceTest[{data1,data2}]>0.05

VarianceEquivalenceTest[{data1,data2}]>0.01

{ℋ1["DegreesOfFreedom","T"],ℋ2["DegreesOfFreedom","T"]}

The p-values are not equivalent:

ℋ1["T"]==ℋ2["T"]

OpenersExampleSection6(Spacer1)Neat Examples  (2)

A visual comparison of the discriminating power of some tests across the three alternatives:

data=RandomVariate[NormalDistribution[],{500,50}];

tests={"T","Z","SignedRank","Sign"};
alts={"Less","Unequal","Greater"};

res=Table[(Quiet@LocationTest[#1,0,i,AlternativeHypothesis->j,VerifyTestAssumptions->None]&)/@data,{i,tests},{j,alts}];

m=Mean/@data;

Grid[Join[{Join[{""},alts]},Join[Partition[Thread[Rotate[tests,(π/2)]],1],Table[ListPlot[Transpose[{m,res[[i,j]]}],FrameTicks->None,Frame->True,PlotRange->{{-.5,.5},{0,1}}],{i,4},{j,3}],2]]]

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

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

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

The test statistic given a particular alternative:

T2=LocationTest[#,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[LocationEquivalenceTest, paclet:ref/LocationEquivalenceTest])  ▪  (RefLink[VarianceTest, paclet:ref/VarianceTest])  ▪  (RefLink[VarianceEquivalenceTest, paclet:ref/VarianceEquivalenceTest])  ▪  (RefLink[DistributionFitTest, paclet:ref/DistributionFitTest])  ▪  (RefLink[IndependenceTest, paclet:ref/IndependenceTest])  ▪  (RefLink[LogRankTest, paclet:ref/LogRankTest])  ▪  (RefLink[MannWhitneyTest, paclet:ref/MannWhitneyTest])  ▪  (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])}, {▪(RefLinkPlain[Probability & Statistics with Quantities, paclet:guide/ProbabilityWithQuantities])}, {▪(RefLinkPlain[Random Variables, paclet:guide/RandomVariables])}, {▪(RefLinkPlain[Statistical Data Analysis, paclet:guide/Statistics])}, {▪(RefLinkPlain[Scientific Data Analysis, paclet:guide/ScientificDataAnalysis])}})}})