({{, (RefLink[VarianceTest, paclet:ref/VarianceTest])[data] 
tests whether the variance of the data is one. }, {, (RefLink[VarianceTest, paclet:ref/VarianceTest])[{(Subscript[data, 1]),(Subscript[data, 2])}]
tests whether the variances of (Subscript[data, 1]) and (Subscript[data, 2]) are equal.}, {, (RefLink[VarianceTest, paclet:ref/VarianceTest])[dspec,((Subscript[σ, 0])^2)]
tests a dispersion measure against ((Subscript[σ, 0])^2).}, {, (RefLink[VarianceTest, paclet:ref/VarianceTest])[dspec,((Subscript[σ, 0])^2),"property"]
returns the value of "property".}})

OpenersNotesSection(Spacer1)Details and Options

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

where ((Subscript[σ, i])^2) is the population variance for (Subscript[data, i]).

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 must be univariate {(Subscript[x, 1]),(Subscript[x, 2]),…}.

The argument (Subscript[σ, 0]^2) can be any positive real number.

(RefLink[VarianceTest, paclet:ref/VarianceTest])[dspec,(Subscript[σ, 0]^2)] will choose the most powerful test that applies to dspec.

(RefLink[VarianceTest, paclet:ref/VarianceTest])[dspec,(Subscript[σ, 0]^2),(RefLink[All, paclet:ref/All])] will choose all tests that apply to dspec.

(RefLink[VarianceTest, paclet:ref/VarianceTest])[dspec,(Subscript[σ, 0]^2),"test"] reports the p-value according to "test".

Most tests require normally distributed data. If a test is less sensitive to a normality assumption, it is called robust. Some tests assume that data is symmetric around its medians.

The following tests can be used:

(RefLink[VarianceTest, paclet:ref/VarianceTest])[data,(Subscript[σ, 0]^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[VarianceTest, paclet:ref/VarianceTest])[data,(Subscript[σ, 0]^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 given:

For tests of variance, 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 and symmetry. By default, α is set to 0.05.

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

OpenersPrimaryExamplesSection(Spacer1)Examples  (40)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Test variances from two populations for equality:

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

VarianceTest[data]

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

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

The full test table:

ℋ["TestDataTable",All]

Compare the variance of a population to a particular value:

SeedRandom[1];data=RandomVariate[NormalDistribution[1,2],(10^3)];

VarianceTest[data,4,"TestDataTable"]

Variance[data]

Test the ratio of the variances of two populations against a particular value:

SeedRandom[1];data1=RandomVariate[NormalDistribution[0,1],100];
data2=RandomVariate[NormalDistribution[0,2.5],250];

VarianceTest[{data1,data2},1/4,"TestDataTable"]

Variance[data1]/Variance[data2]

Perform the test with alternative hypothesis (Subscript[σ, 1]^2)/(Subscript[σ, 2]^2)<1/4:

VarianceTest[{data1,data2},1/4,AlternativeHypothesis->"Less"]

OpenersExampleSection1(Spacer1)Scope  (15)

OpenersExampleSubsection0(Spacer1)Testing  (11)

Test whether the variance of a population is one:

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

The p-values are typically large under (Subscript[H, 0]):

VarianceTest[data1]

The p-values are typically small when (Subscript[H, 0]) is false:

VarianceTest[data2]

Compare the variance of a population to a particular value:

SeedRandom[2];data1=RandomVariate[NormalDistribution[0,2],(10^4)];
data2=RandomVariate[NormalDistribution[0,2.1],(10^4)];

VarianceTest[data1,(2^2)]

VarianceTest[data2,(2^2)]

Compare the variance of a quantity data to a particular value:

SeedRandom["K"];
tempData=RandomVariate[NormalDistribution[(Quantity[273, "K", kelvins, "Kelvins"]),(Quantity[5, "K", kelvins, "Kelvins"])],26]

VarianceTest[tempData,((((Quantity[4.8, "K", kelvins, "Kelvins"])))^2)]

Compare the variances of two populations:

SeedRandom[1];data1=RandomVariate[NormalDistribution[],500];
data2=RandomVariate[StudentTDistribution[5],500];
data3=RandomVariate[NormalDistribution[],350];

The p-values are typically large when the variances are equal:

VarianceTest[{data1,data3}]

The p-values are typically small when the variances are not equal:

VarianceTest[{data1,data2}]

Test whether the ratio of the variances of two populations is a particular value:

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

(Subscript[σ, 0])=4;

The following forms are equivalent:

VarianceTest[{data2,data1},1/(Subscript[σ, 0])]

VarianceTest[{data1,data2},(Subscript[σ, 0])]

The order of the datasets should be considered when determining (Subscript[σ, 0]):

VarianceTest[{data2,data1},(Subscript[σ, 0])]

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

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

VarianceTest[data,1,Automatic]

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

VarianceTest[data,1,"AutomaticTest"]

Perform a particular test for equal variance:

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

VarianceTest[data,1,"BrownForsythe"]

Any number of tests can be performed simultaneously:

VarianceTest[data,1,{"PValue",{"Levene","BrownForsythe"}}]

Perform all tests appropriate to the data simultaneously:

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

VarianceTest[data,1,All]

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

VarianceTest[data,1,"AllTests"]

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

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

ℋ=VarianceTest[data,1,"HypothesisTestData"];

The properties available for extraction:

ℋ["Properties"]

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

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

ℋ=VarianceTest[data,1,"HypothesisTestData"];

The p-value and test statistic from a Levene test:

ℋ["PValue","Levene"]

ℋ["TestStatistic","Levene"]

Extract any number of properties simultaneously:

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

ℋ=VarianceTest[data,1,"HypothesisTestData"];

The p-value and test statistic from the Brown–Forsythe test:

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

OpenersExampleSubsection1(Spacer1)Reporting  (4)

Tabulate the results from a selection of tests:

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

ℋ=VarianceTest[data,1,"HypothesisTestData"];

ℋ["TestDataTable"]

A full table of all appropriate test results:

ℋ["TestDataTable",All]

A table of selected test results:

ℋ["TestDataTable",{"Conover","BrownForsythe"}]

Retrieve the entries from a test table for customized reporting:

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

ℋ=VarianceTest[data,1,"HypothesisTestData"];

res=ℋ["TestData",All];

ℋ["AllTests"]

The p-values are above 0.05, so there is not enough evidence to reject normality at that level:

Show[BarChart[res[[All,2]],ChartLabels->Placed[ℋ["AllTests"],Center],BarOrigin->Left],Graphics[{Dashed,InfiniteLine[{{.05,0},{.05,1}}]}]]

Tabulate p-values for a test or group of tests:

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

ℋ=VarianceTest[data,1,"HypothesisTestData"];

ℋ["PValueTable","Levene"]

The p-value from the table:

ℋ["PValue","Levene"]

A table of p-values from all appropriate tests:

ℋ["PValueTable",All]

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

ℋ["PValueTable",{"Levene","Conover","BrownForsythe"}]

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

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

ℋ=VarianceTest[data,1,"HypothesisTestData"];

ℋ["TestStatisticTable"]

The test statistic from the table:

ℋ["TestStatistic"]

A table of test statistics from all appropriate tests:

ℋ["TestStatisticTable",All]

OpenersExampleSection2(Spacer1)Options  (10)

OpenersExampleSubsection2(Spacer1)AlternativeHypothesis  (3)

A two-sided test is performed by default:

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

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

VarianceTest[data,1,AlternativeHypothesis->"Unequal"]

VarianceTest[data,1,AlternativeHypothesis->Automatic]

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

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

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

VarianceTest[data,Automatic,AlternativeHypothesis->"Unequal"]

Test (Subscript[H, 0]): (σ^2)≥1 versus (Subscript[H, a]): (σ^2)<1:

VarianceTest[data,Automatic,AlternativeHypothesis->"Less"]

Test (Subscript[H, 0]): (σ^2)≤1 versus (Subscript[H, a]): (σ^2)>1:

VarianceTest[data,Automatic,AlternativeHypothesis->"Greater"]

Perform tests with one-sided alternatives when a null value is given:

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

Variance[data1]/Variance[data2]

Test (Subscript[H, 0]): (Subscript[σ, 1]^2)/(Subscript[σ, 2]^2)≥1 versus (Subscript[H, a]): (Subscript[σ, 1]^2)/(Subscript[σ, 2]^2)<1:

VarianceTest[{data1,data2},1,AlternativeHypothesis->"Less"]

Test (Subscript[H, 0]): (Subscript[σ, 1]^2)/(Subscript[σ, 2]^2)≥1.5 versus (Subscript[H, a]): (Subscript[σ, 1]^2)/(Subscript[σ, 2]^2)<1.5:

VarianceTest[{data1,data2},1.5,AlternativeHypothesis->"Less"]

OpenersExampleSubsection3(Spacer1)SignificanceLevel  (3)

Set the significance level for diagnostic tests:

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

VarianceTest[data,1,"FisherRatio",SignificanceLevel->.005]

By default, 0.05 is used:

VarianceTest[data,1,"FisherRatio",SignificanceLevel->Automatic]

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

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

VarianceTest[data,1,"AutomaticTest",SignificanceLevel->.0001]

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

VarianceTest[data,1,"AutomaticTest",SignificanceLevel->Automatic]

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

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

ℋ1=VarianceTest[data,1.5,"HypothesisTestData",SignificanceLevel->.05];

ℋ2=VarianceTest[data,1.5,"HypothesisTestData",SignificanceLevel->.01];

ℋ1["TestConclusion"]//TraditionalForm

ℋ2["TestConclusion"]//TraditionalForm

ℋ1["ShortTestConclusion"]

ℋ2["ShortTestConclusion"]

OpenersExampleSubsection4(Spacer1)VerifyTestAssumptions  (4)

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

SeedRandom[1];data1=RandomVariate[StudentTDistribution[3],1000];
data2=RandomVariate[NormalDistribution[0,Sqrt[3]],1000];

Verify all assumptions:

VarianceTest[{data1,data2},1/4,"Levene",VerifyTestAssumptions->All]

Check no assumptions:

VarianceTest[{data1,data2},1/4,"Levene",VerifyTestAssumptions->None]

Diagnostics can be controlled independently:

SeedRandom[2];data1=RandomVariate[StudentTDistribution[3],1000];
data2=RandomVariate[NormalDistribution[0,Sqrt[3]],1000];

Assume normality but check for symmetry:

VarianceTest[{data1,data2},1/4,"Levene",VerifyTestAssumptions->"Symmetry"]

Only check for normality:

VarianceTest[{data1,data2},1/4,"Levene",VerifyTestAssumptions->"Normality"]

Test assumption values can be explicitly set:

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

VarianceTest[data,1,"TestDataTable"]

VarianceTest[data,1,"TestDataTable",VerifyTestAssumptions->"Normality"->True]

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

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

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

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

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

The results are identical:

SmoothHistogram[{T,T2}]

OpenersExampleSection3(Spacer1)Applications  (2)

Test whether the variances of some populations are equivalent:

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

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

The first two populations have similar variances:

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

The third population differs in variance from the first:

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

An object with a length of 2.15 cm was measured with the same ruler by 25 grade-school students in two different classes:

group1={2.28,2.13,2.21,2.,2.06,2.09,2.12,2.27,2.17,2.09,2.02,2.28,2.28,2.03,2.11,2.05,2.06,2.28,2.1,2.35,2.07,2.22,2.19,2.33,2.02};

group2={2.03,2.12,1.92,1.96,2.05,2.05,2.02,2.12,2.02,1.95,2.,2.03,1.93,1.96,2.08,1.92,2.12,2.01,1.84,2.06,2.,1.95,1.90,2.,1.94};

{Variance[group1],Variance[group2]}

The second group is superior in their precision:

VarianceTest[{group1,group2},1,"TestDataTable"]

Compare the accuracy of the groups using squared error:

SqrErr1=(((group1-2.15))^2);SqrErr2=(((group2-2.15))^2);

{Mean[SqrErr1],Mean[SqrErr2]}

The first group is significantly more accurate:

LocationTest[{SqrErr1,SqrErr2},0,"TestDataTable"]

OpenersExampleSection4(Spacer1)Properties & Relations  (7)

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

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

pvals=Table[VarianceTest[i,1,"FisherRatio",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

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

n=100;

data1=RandomVariate[NormalDistribution[0,.75],{1000,n}];
data2=RandomVariate[NormalDistribution[0,1],{1000,n}];

tests=VarianceTest[{data1[[1]],data2[[1]]},1,"AllTests"]

pvs=MapThread[VarianceTest[{#1,#2},1,tests,VerifyTestAssumptions->None]&,{data1,data2}];

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

The power of the tests at six different levels. The Siegel–Tukey has the lowest power:

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

The power of the tests is proportional to the sample size:

n=10;

data1=RandomVariate[NormalDistribution[0,.75],{1000,n}];
data2=RandomVariate[NormalDistribution[0,1],{1000,n}];

tests=VarianceTest[{data1[[1]],data2[[1]]},1,"AllTests"]

pvs=MapThread[VarianceTest[{#1,#2},1,tests,VerifyTestAssumptions->None]&,{data1,data2}];

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

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

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

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[0,.5],100];

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

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

twoSided-2 minOneSided

The Brown–Forsythe and Levene tests are equivalent to the Fisher ratio test for a single sample:

data=RandomVariate[NormalDistribution[],100];

VarianceTest[data,Automatic,{"TestDataTable",{"FisherRatio","BrownForsythe","Levene"}}]

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

ts=TimeSeries[];

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

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

%%==%

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

td=TemporalData[];

VarianceTest[td]

Test all the values only:

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

Test whether the variances of the two paths are equal:

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

VarianceTest[{data1,data2}]

OpenersExampleSection5(Spacer1)Possible Issues  (2)

The Conover and Siegel–Tukey tests are not defined for a single sample:

data=RandomVariate[NormalDistribution[],100];

VarianceTest[data,Automatic,{"TestDataTable",{"Conover","SiegelTukey"}}]

Some tests assume the data is normally distributed:

data=RandomVariate[LaplaceDistribution[1,2],{2,100}];

VarianceTest[data,Automatic,{"TestDataTable",{"BrownForsythe","FisherRatio","Levene"}}]

Conover's test and the Siegel–Tukey test do not assume normality:

VarianceTest[data,Automatic,{"TestDataTable",{"Conover","SiegelTukey"}}]

OpenersExampleSection6(Spacer1)Neat Examples  (1)

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

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

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

The test statistic given a particular alternative:

T2=VarianceTest[#,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[VarianceEquivalenceTest, paclet:ref/VarianceEquivalenceTest])  ▪  (RefLink[DistributionFitTest, paclet:ref/DistributionFitTest])  ▪  (RefLink[IndependenceTest, paclet:ref/IndependenceTest])  ▪  (RefLink[LogRankTest, paclet:ref/LogRankTest])  ▪  (RefLink[FisherRatioTest, paclet:ref/FisherRatioTest])  ▪  (RefLink[LeveneTest, paclet:ref/LeveneTest])  ▪  (RefLink[BrownForsytheTest, paclet:ref/BrownForsytheTest])  ▪  (RefLink[ConoverTest, paclet:ref/ConoverTest])  ▪  (RefLink[SiegelTukeyTest, paclet:ref/SiegelTukeyTest])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Hypothesis Tests, paclet:guide/HypothesisTests])}, {▪(RefLinkPlain[Random Variables, paclet:guide/RandomVariables])}, {▪(RefLinkPlain[Statistical Data Analysis, paclet:guide/Statistics])}})}})