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

OpenersNotesSection(Spacer1)Details and Options

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

where μ is the population median for data and (Subscript[μ, 12]) is the median 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[SignTest, paclet:ref/SignTest])[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[SignTest, paclet:ref/SignTest])[dspec,(Subscript[μ, 0]),"property"] can be used to directly give the value of "property".

Properties related to the reporting of test results include:

For univariate samples, (RefLink[SignTest, paclet:ref/SignTest]) performs the sign test for medians of paired samples. The test statistic is assumed to follow a (RefLink[BinomialDistribution, paclet:ref/BinomialDistribution])[n,1/2] where n is the number of elements in dspec not equal to (Subscript[μ, 0]).

For multivariate samples, (RefLink[SignTest, paclet:ref/SignTest]) performs an affine invariant test for paired samples using spatial signs. The test statistic is assumed to follow a (RefLink[ChiSquareDistribution, paclet:ref/ChiSquareDistribution])[dim] where dim is the dimension of dspec.

The following options can be used:

For the (RefLink[SignTest, paclet:ref/SignTest]), 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. By default, α is set to 0.05.

OpenersPrimaryExamplesSection(Spacer1)Examples  (36)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Test whether the median of a population is zero:

data=RandomVariate[NormalDistribution[],100];

SignTest[data]

Test whether the spatial median of a multivariate population is some value:

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

SignTest[data,{.5,.5,.5}]

Compute the test statistic:

SignTest[data,{.5,.5,.5},"TestStatistic"]

Compare the median difference for paired data to a particular value:

data=RandomVariate[MultinormalDistribution[{2,0},{{1,.75},{.75,1}}],1000];

SignTest[Transpose@data,2]

Report the test results in a table:

SignTest[Transpose@data,2,"TestDataTable"]

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

data=RandomVariate[StudentTDistribution[4],100];

ℋ=SignTest[data,Automatic,"HypothesisTestData"]

A list of available properties:

ℋ["Properties"]

Extract a single property or a list of properties:

ℋ["TestData"]

ℋ["TestDataTable","PValue","TestStatistic"]

OpenersExampleSection1(Spacer1)Scope  (13)

OpenersExampleSubsection0(Spacer1)Testing  (10)

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 median is close to (Subscript[μ, 0]):

SignTest[data1]

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

SignTest[data2]

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

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

SignTest[data,0]

SignTest[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 median is close to (Subscript[μ, 0]):

SignTest[data1,3]

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

SignTest[data2,3]

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

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

SignTest[data]

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

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

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:

SignTest[{data1,data2},0]

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

SignTest[{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:

SignTest[{data1,data2},3]

SignTest[{data2,data1},3]

Test whether the median 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)];

SignTest[{data1,data2}]

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

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

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

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

ℋ=SignTest[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)}];

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

The p-value and test statistic:

ℋ["PValue"]

ℋ["TestStatistic"]

Extract any number of properties simultaneously:

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

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

The p-value and test statistic:

ℋ["PValue","TestStatistic"]

OpenersExampleSubsection1(Spacer1)Reporting  (3)

Tabulate the test results:

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

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

ℋ["TestDataTable"]

Retrieve the entries from a test table for customized reporting:

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

res=Table[SignTest[v,0,"TestData"],{v,data}];

ListPlot[res,Filling->Axis]

Tabulate p-values or test statistics:

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

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

ℋ["PValueTable"]

The p-value from the table:

ℋ["PValue"]

ℋ["TestStatisticTable"]

The test statistic from the table:

ℋ["TestStatistic"]

OpenersExampleSection2(Spacer1)Options  (9)

OpenersExampleSubsection2(Spacer1)AlternativeHypothesis  (3)

A two-sided test is performed by default:

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

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

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

SignTest[data,0,AlternativeHypothesis->Automatic]

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

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

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

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

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

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

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

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

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

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

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

OpenersExampleSubsection3(Spacer1)MaxIterations  (2)

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

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

By default, 500 iterations are allowed:

SignTest[{data1,data2},Automatic,MaxIterations->500]

SignTest[{data1,data2},Automatic,MaxIterations->Automatic]

Setting the maximum number of iterations may result in lack of convergence:

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

The p-values are not equivalent:

SignTest[{data1,data2},Automatic,MaxIterations->1]

SignTest[{data1,data2},Automatic,MaxIterations->Automatic]

OpenersExampleSubsection4(Spacer1)Method  (3)

By default, p-values are computed using the (RefLink[BinomialDistribution, paclet:ref/BinomialDistribution]) for univariate data:

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

SignTest[data,0,Method->Automatic]

SignTest[data,0,Method->"Permutation"]

Asymptotic methods can be used for univariate data:

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

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

SignTest[data,0,Method->"Permutation"]

For multivariate data, only the asymptotic result is available:

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

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

SignTest[data,0,Method->"Permutation"]

OpenersExampleSubsection5(Spacer1)SignificanceLevel  (1)

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

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

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

ℋ2=SignTest[data,.2,"HypothesisTestData",SignificanceLevel->.001];

ℋ1["TestConclusion"]//TraditionalForm

ℋ2["TestConclusion"]//TraditionalForm

ℋ1["ShortTestConclusion"]

ℋ2["ShortTestConclusion"]

OpenersExampleSection3(Spacer1)Applications  (2)

A new sleeping aid was tested on eight patients. The number of minutes taken for each subject to fall asleep was recorded for a night taking the medication and for a night with a placebo:

sleepAid={12,9,11,21,17,22,18,11};
placebo={21,16,8,36,28,20,29,22};

SmoothHistogram[{sleepAid,placebo}]

The (RefLink[SignTest, paclet:ref/SignTest]) does not detect a difference in the sleep aid and placebo:

SignTest[{sleepAid,placebo},0,"TestDataTable"]

The datasets, while very small, do not fail a test for normality:

DistributionFitTest/@{sleepAid,placebo}

A more powerful (RefLink[PairedTTest, paclet:ref/PairedTTest]) shows a significant reduction in time to sleep with the sleep aid:

PairedTTest[{sleepAid,placebo},0,"TestDataTable"]

A group of 10 students with low assessments in mathematics and science was asked to participate in tutoring program. A test similar to the original assessment was administered after the program. The students' scores on the math and science portions of both assessments are as follows:

preMath={64,51,45,37,60,67,51,59,65,53};
preSci={58,46,62,40,58,34,69,31,26,58};
postMath={84,68,73,72,78,72,70,65,81,78};
postSci={66,69,64,70,60,57,59,68,59,56};

pre=Transpose[{preMath,preSci}];
post=Transpose[{postMath,postSci}];

ContourPlot[Evaluate@PDF[SmoothKernelDistribution[N[post-pre]],{m,s}],{m,-8,50},{s,-25,50},PlotRange->All]

There is a significant improvement in scores overall:

SignTest[{Transpose[{preMath,preSci}],Transpose[{postMath,postSci}]},0,"TestDataTable"]

The Bonferroni-corrected tests of the individual components suggest that math scores alone account for the detected improvement:

α=.05;

SignTest[{preSci,postSci},0,"ShortTestConclusion",SignificanceLevel->α/2]

SignTest[{preMath,postMath},0,"ShortTestConclusion",SignificanceLevel->α/2]

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

Conceptually, the (RefLink[SignTest, paclet:ref/SignTest]) counts the number of positive signs in a dataset:

data=RandomVariate[BinomialDistribution[10,.5],100];

μ=10*.5;

sgn=Sign[data-μ];

T=Count[sgn,1]

For univariate data, the test statistic follows a (RefLink[BinomialDistribution, paclet:ref/BinomialDistribution]), ignoring zeros:

n=Count[sgn,Except[0]];

Probability[x<=T,x\[Distributed]BinomialDistribution[n,.5]]

SignTest[data,μ,"TestDataTable",AlternativeHypothesis->"Less"]

The (RefLink[SignTest, paclet:ref/SignTest]) is generally less powerful than other hypothesis tests for location:

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

(Subscript[p, sign])=Table[SignTest[i],{i,data}];
(Subscript[p, sr])=Table[SignedRankTest[i,VerifyTestAssumptions->None],{i,data}];
(Subscript[p, T])=Table[TTest[i,VerifyTestAssumptions->None],{i,data}];

Probability[x<.05,x\[Distributed](Subscript[p, sign])]//N

Probability[x<.05,x\[Distributed](Subscript[p, sr])]//N

Probability[x<.05,x\[Distributed](Subscript[p, T])]//N

For multivariate data, spatial signs are used when computing the test statistic:

SpatialSign[d_]:=With[{norm=Norm[d]},If[norm==0,ConstantArray[0,Length[d]],d/norm]]

data1=RandomVariate[MultinormalDistribution[{0,0},IdentityMatrix[2]],100];
data2=RandomVariate[MultinormalDistribution[{2,1},IdentityMatrix[2]],100];

Spatial signs tend to cluster when the spatial median is nonzero:

{ListPlot[SpatialSign/@data1,AspectRatio->1,PlotRange->{{-1,1},{-1,1}}],ListPlot[SpatialSign/@data2,AspectRatio->1,PlotRange->{{-1,1},{-1,1}}]}

The amount of clustering is quantified by the test statistic:

t1=SignTest[data1,{0,0},"TestStatistic"]

t2=SignTest[data2,{0,0},"TestStatistic"]

The test statistic follows a (RefLink[ChiSquareDistribution, paclet:ref/ChiSquareDistribution])[p]:

p=Dimensions[data1][[2]]

Probability[x>t1,x\[Distributed]ChiSquareDistribution[p]]

SignTest[data1]

The test statistic is affine invariant for multivariate data:

data=RandomVariate[MultinormalDistribution[{0,0},IdentityMatrix[2]],100];

𝒯=AffineTransform[{{{1,2},{3,4}},{1,2}}];

SignTest[data,{0,0},"TestDataTable"]

SignTest[𝒯[data],𝒯[{0,0}],"TestDataTable"]

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

ts=TimeSeries[];

SignTest[ts]

SignTest[ts["Values"]]

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

td=TemporalData[];

SignTest[td]

Test all the values only:

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

Test the difference of the medians of the two paths:

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

SignTest[{data1,data2}]

OpenersExampleSection5(Spacer1)Neat Examples  (2)

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

data1=RandomVariate[NormalDistribution[],{2500,100}];
data2=RandomVariate[NormalDistribution[],{2500,100}];

T1=MapThread[SignTest[{#1,#2},0,"TestStatistic"]&,{data1,data2}];

The test statistic given a particular alternative:

T2=MapThread[SignTest[{#1,#2},1,"TestStatistic"]&,{data1,data2}];

Compare the distributions of the test statistics:

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

The distribution of spatial signs in three dimensions shows that larger deviations from a zero mean vector produce more highly clustered spatial signs and larger sign statistics:

SpatialSign[d_]:=With[{norm=Norm[d]},If[norm==0,ConstantArray[0,Length[d]],d/norm]]

data=Table[RandomVariate[MultinormalDistribution[{a,-.5a,a},IdentityMatrix[3]],500],{a,{0,1,2,4}}];

sPointPlot[data_]:=Show[Graphics3D[{Directive[Yellow,Specularity[White,20]],Sphere[{0,0,0}]}],ListPointPlot3D[SpatialSign/@data,PlotRange->{{-1,1},{-1,1},{-1,1}}],Boxed->False,PlotLabel->TextCell[SignTest[data,0,"TestStatistic"],"Section"],Background -> GrayLevel[0]]

GraphicsGrid[Partition[sPointPlot/@data,2]]

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