LeveneTest[data]
tests whether the variance of data is 1.
LeveneTest[{data1,data2,…}]
tests whether the variances of data1, data2, … are equal.
LeveneTest[dspec,
]
tests a dispersion measure against
.
LeveneTest[dspec,
,"property"]
returns the value of "property".
LeveneTest
LeveneTest[data]
tests whether the variance of data is 1.
LeveneTest[{data1,data2,…}]
tests whether the variances of data1, data2, … are equal.
LeveneTest[dspec,
]
tests a dispersion measure against
.
LeveneTest[dspec,
,"property"]
returns the value of "property".
Details and Options
- LeveneTest tests the null hypothesis
against the alternative hypothesis
: -


data 

{data1,data2} 

{data1,data2,…} 
not all equal - where σi2 is the population variance for datai.
- By default, a probability value or
-value is returned. - A small
-value suggests that it is unlikely that
is true. - The data in dspec must be univariate {x1,x2,…}.
- The argument
can be any positive real number. The default value of
is 1 if not specified, and ignored if the number of groups in dspec is more than 2. - The LeveneTest assumes the data is normally distributed and, for the two-sample case, is much less sensitive to this assumption than the FisherRatioTest.
- LeveneTest[data,
,"HypothesisTestData"] returns a HypothesisTestData object htd that can be used to extract additional test results and properties using the form htd["property"]. - LeveneTest[data,
,"property"] can be used to directly give the value of "property". - Properties related to the reporting of test results include:
-
"DegreesOfFreedom" the degrees of freedom used in a test "PValue" list of
-values"PValueTable" formatted table of
-values"ShortTestConclusion" a short description of the conclusion of a test "TestConclusion" a description of the conclusion of a test "TestData" list of pairs of test statistics and
-values"TestDataTable" formatted table of
-values and test statistics"TestStatistic" list of test statistics "TestStatisticTable" formatted table of test statistics - When one sample of size
is given, the LeveneTest is equivalent to the FisherRatioTest. - For the
-sample case {data1,data2,…,datak} with datai={xi,1,xi,2,…,xi,ni}, the test statistic is given by
, where zi,j=Abs[xi,j-Mean[datai]], zi=Mean[{zi,1,zi,2,…,zi,ni}], and z=Mean[{z1,z2,…,zk}]. The test statistic is assumed to follow FRatioDistribution[k-1,
(ni-1)] under
. - The following options can be used:
-
AlternativeHypothesis "Unequal" the inequality for the alternative hypothesis SignificanceLevel 0.05 cutoff for diagnostics and reporting VerifyTestAssumptions Automatic set which diagnostic tests to run - For the LeveneTest, a cutoff
is chosen such that
is rejected only if
. The value of
used for the "TestConclusion" and "ShortTestConclusion" properties is controlled by the 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 VerifyTestAssumptions in LeveneTest include:
-
"Normality" verify that all data is normally distributed
Examples
open all close allBasic Examples (2)
Test variances from two populations for equality:
data = RandomVariate[NormalDistribution[], {2, 100}];LeveneTest[data]Create a HypothesisTestData object for further property extraction:
ℋ = LeveneTest[data, Automatic, "HypothesisTestData"]ℋ["Properties"]Compare the variance of a population to a particular value:
data = RandomVariate[NormalDistribution[1, 2.1], 10^3];LeveneTest[data, 4, "TestDataTable"]Variance[data]Test against the alternative hypothesis
:
LeveneTest[data, 4, "TestDataTable", AlternativeHypothesis -> "Greater"]Scope (10)
Testing (8)
Test whether the variance of a population is 1:
SeedRandom[3];data1 = RandomVariate[NormalDistribution[], 500];The
-value is uniformly distributed in [0,1] under
:
LeveneTest[data1]The histogram of a sample of
-values of the Levene test:
sample = Table[Quiet@LeveneTest[RandomVariate[NormalDistribution[0, 1], 100]], {10 ^ 3}];Histogram[sample, Automatic, PDF]The
-value is typically small when
is false:
SeedRandom[3];data2 = RandomVariate[NormalDistribution[1, 3], 500];LeveneTest[data2]Compare the variance of a population to a particular value:
SeedRandom[3];data1 = RandomVariate[NormalDistribution[0, 2], 10^4];
data2 = RandomVariate[NormalDistribution[0, 2.1], 10^4];LeveneTest[data1, 2^2]LeveneTest[data2, 2^2]Compare the variances of two populations:
SeedRandom[3];data1 = RandomVariate[NormalDistribution[0, 3], 500];
data2 = RandomVariate[NormalDistribution[1, 3], 500];The
-value is uniformly distributed in [0,1] under
:
LeveneTest[{data1, data2}]The histogram of a sample of
-values of the Levene test:
sample = Table[Quiet@LeveneTest[{RandomVariate[NormalDistribution[0, 3], 100], RandomVariate[NormalDistribution[1, 3], 100]}], {5 10 ^ 3}];Histogram[sample, Automatic, PDF]The
-value is typically small when the variances are not equal:
SeedRandom[3];data3 = RandomVariate[NormalDistribution[10, 1], 350];LeveneTest[{data1, data3}]Test whether the ratio of the variances of two populations is a particular value:
SeedRandom[3];data1 = RandomVariate[NormalDistribution[0, 2], 500];
data2 = RandomVariate[NormalDistribution[0, 1], 500];Subscript[σ, 0] = 4;The following forms are equivalent:
LeveneTest[{data1, data2}, Subscript[σ, 0]]LeveneTest[{data2, data1}, 1 / Subscript[σ, 0]]The order of the datasets should be considered when determining
:
LeveneTest[{data2, data1}, Subscript[σ, 0]]Test whether the variances of three populations are identical:
SeedRandom[3];data1 = RandomVariate[NormalDistribution[10, 1], 500];
data2 = RandomVariate[NormalDistribution[0, 1], 200];
data3 = RandomVariate[NormalDistribution[-3, 1], 400];LeveneTest[{data1, data2, data3}]Create a HypothesisTestData object for repeated property extraction:
SeedRandom[3];data = RandomVariate[NormalDistribution[], {2, 10^4}];ℋ = LeveneTest[data, 1, "HypothesisTestData"];The properties available for extraction:
ℋ["Properties"]Extract some properties from a HypothesisTestData object:
SeedRandom[3];data = Table[RandomVariate[NormalDistribution[0, 1], i], {i, {1000, 2000, 3000}}];ℋ = LeveneTest[data, 1, "HypothesisTestData"];The
-value, test statistic, and degrees of freedom:
ℋ["PValue"]ℋ["TestStatistic"]ℋ["DegreesOfFreedom"]Extract any number of properties simultaneously:
SeedRandom[3];data = RandomVariate[NormalDistribution[], {2, 100}];ℋ = LeveneTest[data, 1, "HypothesisTestData"];The
-value, test statistic, and degrees of freedom:
ℋ["PValue", "TestStatistic", "DegreesOfFreedom"]Reporting (2)
SeedRandom[3];data = RandomVariate[NormalDistribution[], {2, 10^3}];ℋ = LeveneTest[data, 1, "HypothesisTestData"];ℋ["TestDataTable"]The values from the table can be extracted using "TestData":
ℋ["TestData"]Tabulate
-values or test statistics:
SeedRandom[3];data = RandomVariate[NormalDistribution[], {3, 10^4}];ℋ = LeveneTest[data, 1, "HypothesisTestData"];ℋ["PValueTable"]ℋ["PValue"]ℋ["TestStatisticTable"]The test statistic from the table:
ℋ["TestStatistic"]Options (8)
AlternativeHypothesis (3)
A two-sided test is performed by default:
data = RandomVariate[NormalDistribution[], 100];LeveneTest[data, 1, AlternativeHypothesis -> "Unequal"]LeveneTest[data, 1, AlternativeHypothesis -> Automatic]Perform a two-sided test or a one-sided alternative:
data = RandomVariate[NormalDistribution[0, 1.25], 100];LeveneTest[data, Automatic, AlternativeHypothesis -> "Unequal"]LeveneTest[data, Automatic, AlternativeHypothesis -> "Less"]LeveneTest[data, Automatic, AlternativeHypothesis -> "Greater"]Perform tests with one-sided alternatives when a null value is given:
data1 = RandomVariate[NormalDistribution[0, .9], 100];
data2 = RandomVariate[NormalDistribution[0, 1], 100];Variance[data1] / Variance[data2]LeveneTest[{data1, data2}, 1, AlternativeHypothesis -> "Less"]LeveneTest[{data1, data2}, 1.5, AlternativeHypothesis -> "Less"]SignificanceLevel (2)
Set the significance level for diagnostic tests:
data = BlockRandom[SeedRandom[5];RandomVariate[StudentTDistribution[3], 50]];LeveneTest[data, 1, SignificanceLevel -> .005]LeveneTest[data, 1, SignificanceLevel -> Automatic]The significance level is also used for "TestConclusion" and "ShortTestConclusion":
data = BlockRandom[SeedRandom[1];RandomVariate[NormalDistribution[0, 1], 100]];ℋ1 = LeveneTest[data, 1.5, "HypothesisTestData", SignificanceLevel -> .05];ℋ2 = LeveneTest[data, 1.5, "HypothesisTestData", SignificanceLevel -> .01];ℋ1["TestConclusion"]//TraditionalFormℋ2["TestConclusion"]//TraditionalFormℋ1["ShortTestConclusion"]ℋ2["ShortTestConclusion"]VerifyTestAssumptions (3)
Diagnostics can be controlled as a group using All or None:
data1 = RandomVariate[StudentTDistribution[3], 1000];
data2 = RandomVariate[NormalDistribution[0, Sqrt[3]], 1000];LeveneTest[{data1, data2}, 1 / 4, VerifyTestAssumptions -> All]LeveneTest[{data1, data2}, 1 / 4, VerifyTestAssumptions -> None]Diagnostics can be controlled independently:
data1 = RandomVariate[StudentTDistribution[3], 1000];
data2 = RandomVariate[NormalDistribution[0, Sqrt[3]], 1000];LeveneTest[{data1, data2}, 1 / 4, VerifyTestAssumptions -> "Normality"]Set the normality assumption to True:
LeveneTest[{data1, data2}, 1 / 4, VerifyTestAssumptions -> "Normality" -> True]It is often useful to bypass diagnostic tests for simulation purposes:
data = RandomVariate[NormalDistribution[], {1000, 100}];AbsoluteTiming[T = Quiet@LeveneTest[#, Automatic, "TestStatistic"]& /@ data;]The assumptions of the test hold by design, so a great deal of time can be saved:
AbsoluteTiming[T2 = Quiet@LeveneTest[#, Automatic, "TestStatistic", VerifyTestAssumptions -> None]& /@ data;]SmoothHistogram[{T, T2}]Applications (1)
Set up a test for constant error variance using Levene's test, which partitions the data into two equal pieces:
HomogeneityOfVarianceTest[data_] := With[{nh = Ceiling[(Length[data]/2)]}, LeveneTest[TakeDrop[data, nh], 1, "TestDataTable", VerifyTestAssumptions -> None]]Generate some data for multiple regression analysis:
data = ({#1[[1]], #1[[2]], #1[[3]], 1.2 + (3.7 + RandomReal[{-1, 1}]) #1[[1]] - 2 #1[[2]] + 23.4 #1[[3]]}&) /@ RandomReal[10, {100, 3}];lm = LinearModelFit[data, {x, y, z}, {x, y, z}];The residuals plotted against each predictor variable:
Row[Table[ListPlot[Transpose[{data[[All, i]], lm["FitResiduals"]}], Frame -> True, FrameLabel -> {{x, y, z}[[i]], "Residual"}], {i, 3}]]res = (SortBy[#1, First][[All, 2]]&) /@ Table[Transpose[{data[[All, i]], lm["FitResiduals"]}], {i, 3}];The first variable is positively correlated with its variance:
HomogeneityOfVarianceTest /@ resProperties & Relations (8)
The Levene test is equivalent to FisherRatioTest when a single dataset is given:
SeedRandom[3];data = RandomVariate[NormalDistribution[], 100];LeveneTest[data]FisherRatioTest[data]Given a single dataset with length
, the test statistic follows a ChiSquareDistribution[n-1] under
:
SeedRandom[3];data = RandomVariate[NormalDistribution[], {1000, 100}];T = LeveneTest[#, Automatic, "TestStatistic", VerifyTestAssumptions -> None]& /@ data;Show[SmoothHistogram[T, PlotStyle -> Orange], Plot[PDF[ChiSquareDistribution[99], x], {x, 50, 160}], PlotRange -> All]The maximum-likelihood estimate of the degrees of freedom is near
:
EstimatedDistribution[T, ChiSquareDistribution[df]]DistributionFitTest[T, ChiSquareDistribution[99]]Given two datasets with lengths
and
, the test statistic follows an FRatioDistribution[1,n+m-2] under
:
n = 100;
m = 75;
SeedRandom[3];
data1 = RandomVariate[NormalDistribution[], {1000, n}];
data2 = RandomVariate[NormalDistribution[], {1000, m}];T = MapThread[LeveneTest[{#1, #2}, Automatic, "TestStatistic", VerifyTestAssumptions -> None]&, {data1, data2}];Show[Histogram[T, {0.2}, "PDF"], Plot[PDF[FRatioDistribution[1, n + m - 2], x], {x, 0, 8}, PlotRange -> {0, 1.5}]]DistributionFitTest[T, FRatioDistribution[1, n + m - 2], "TestConclusion"]The Levene test is less sensitive to the assumption of normality than the FisherRatioTest:
SeedRandom[3];data1 = RandomVariate[LaplaceDistribution[1, 2], {1000, 100}];
data2 = RandomVariate[LaplaceDistribution[1, 2], {1000, 75}];fisher = MapThread[FisherRatioTest[{#1, #2}, VerifyTestAssumptions -> None]&, {data1, data2}];levene = MapThread[LeveneTest[{#1, #2}, VerifyTestAssumptions -> None]&, {data1, data2}];The Fisher ratio test tends to underestimate the
-value and commit more Type I errors:
Histogram[{fisher, levene}, Automatic, "PDF"]The two-sample test statistic:
Subscript[n, 1] = 100;Subscript[n, 2] = 75;Subscript[σ, 0] = 2;SeedRandom[3];data1 = RandomVariate[NormalDistribution[0, Subscript[σ, 0]], Subscript[n, 1]];
data2 = RandomVariate[NormalDistribution[0, 1], Subscript[n, 2]];Subscript[n, t] = Subscript[n, 1] + Subscript[n, 2];levene[d1_, d2_] := Block[{μZ1, μZ2, z1, z2, μZZ},
z1 = Abs[Standardize[d1, Mean, 1&]];
z2 = Subscript[σ, 0]Abs[Standardize[d2, Mean, 1&]];
μZ1 = Mean[z1];μZ2 = Mean[z2];
μZZ = (Subscript[n, 1]μZ1 + Subscript[n, 2]μZ2/Subscript[n, t]);
(Subscript[n, t] - 2)(Subscript[n, 1](μZ1 - μZZ)^2 + Subscript[n, 2](μZ2 - μZZ)^2/(z1 - μZ1).(z1 - μZ1) + (z2 - μZ2).(z2 - μZ2))
]levene[data1, data2]LeveneTest[{data1, data2}, Subscript[σ, 0] ^ 2, "TestStatistic"]The three-sample test statistic:
Subscript[n, 1] = 100;Subscript[n, 2] = 75;Subscript[n, 3] = 150;SeedRandom[3];data1 = RandomVariate[NormalDistribution[-4, 3], Subscript[n, 1]];
data2 = RandomVariate[NormalDistribution[1, 3], Subscript[n, 2]];
data3 = RandomVariate[NormalDistribution[5, 3], Subscript[n, 3]];Subscript[n, t] = Subscript[n, 1] + Subscript[n, 2] + Subscript[n, 3];levene3[d1_, d2_, d3_] := Block[{μZ1, μZ2, μZ3, z1, z2, z3, μZZ},
z1 = Abs[d1 - Mean[d1]];
z2 = Abs[d2 - Mean[d2]];
z3 = Abs[d3 - Mean[d3]];
μZ1 = Mean[z1];μZ2 = Mean[z2];μZ3 = Mean[z3];
μZZ = (Subscript[n, 1]μZ1 + Subscript[n, 2]μZ2 + Subscript[n, 3]μZ3/Subscript[n, t]);
((Subscript[n, t] - 3)/2)(Subscript[n, 1](μZ1 - μZZ)^2 + Subscript[n, 2](μZ2 - μZZ)^2 + Subscript[n, 3](μZ3 - μZZ)^2/Total[(z1 - μZ1) ^ 2] + Total[(z2 - μZ2) ^ 2] + Total[(z3 - μZ3) ^ 2])
]levene3[data1, data2, data3]LeveneTest[{data1, data2, data3}, 1, "TestStatistic"]The Levene test works with the values only when the input is a TimeSeries:
ts = TemporalData[TimeSeries, {{{1.224578634529677, 0.47929635789978015, 0.6572781300178168,
0.21496048742669355, 0.7299608014554928, -0.2495111111278263, -1.3286551762002712,
0.552725018274874, 0.19272112205837066, 1.1809144012420882, -1.1671 ... 40938613662046, 1.052394590214582, 0.9345044123980388, 0.38537803109557855,
-0.48660931166089394, -0.71203560340161}}, {{0, 100, 1}}, 1, {"Continuous", 1},
{"Discrete", 1}, 1, {ValueDimensions -> 1, ResamplingMethod -> None}}, False, 10.1];LeveneTest[ts]LeveneTest[ts["Values"]]The Levene test works with all the values together when the input is a TemporalData:
td = TemporalData[Automatic, {{{-0.25275046867718637, -0.7175779198306353, -1.9370139837317764,
0.006665621735740701, -0.3730807122324292, 0.6740106823161018, 0.8562214990564344,
0.955785083955732, 1.7020898014886303, 1.8523009430646802, 0.244 ... 3951759101545, -1.1611722313627828, 1.1602446901533021,
1.1052173095128992, 1.1089143920161917, -0.13837156328402}}, {{0, 100, 1}}, 2,
{"Continuous", 2}, {"Discrete", 1}, 1, {ValueDimensions -> 1, ResamplingMethod -> None}}, False,
10.1];LeveneTest[td]data = td["ValueList"]//Flatten;
LeveneTest[data]Test whether the variances of the two paths are equal:
{data1, data2} = td["ValueList"];LeveneTest[{data1, data2}]Possible Issues (3)
The Levene test assumes the data is drawn from a NormalDistribution:
data = RandomVariate[LaplaceDistribution[1, 2], {2, 100}];LeveneTest[data, 1, "TestDataTable"]Use ConoverTest or SiegelTukeyTest for non-normal data:
ConoverTest[data, 1, "TestDataTable"]SiegelTukeyTest[data, 1, "TestDataTable"]The Levene test ignores the argument
when there are more than 2 groups:
data = RandomVariate[NormalDistribution[1, 2], {4, 100}];Length[data]LeveneTest[data, 2, "TestDataTable"]When there are more than 2 groups in the data, the Levene test only allows the two-sided test for the alternative hypothesis:
data = RandomVariate[NormalDistribution[1, 2], {4, 100}];LeveneTest[data, 1, AlternativeHypothesis -> "Unequal"]LeveneTest[data, 1, AlternativeHypothesis -> "Greater"]LeveneTest[data, 1, AlternativeHypothesis -> "Less"]Neat Examples (1)
Compute the statistic when the null hypothesis
is true:
data = RandomVariate[NormalDistribution[], {250, 100}];T1 = LeveneTest[#, 1, "TestStatistic", VerifyTestAssumptions -> None]& /@ data;The test statistic given a particular alternative:
T2 = LeveneTest[#, 3, "TestStatistic", VerifyTestAssumptions -> None]& /@ data;Compare the distributions of the test statistics:
SmoothHistogram[{T1, T2}, Filling -> Axis, PlotLegends -> {"SubscriptBox[H, 0] is True", "SubscriptBox[H, 0] is False"}]Related Guides
Text
Wolfram Research (2010), LeveneTest, Wolfram Language function, https://reference.wolfram.com/language/ref/LeveneTest.html (updated 2017).
CMS
Wolfram Language. 2010. "LeveneTest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/LeveneTest.html.
APA
Wolfram Language. (2010). LeveneTest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LeveneTest.html
BibTeX
@misc{reference.wolfram_2026_levenetest, author="Wolfram Research", title="{LeveneTest}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/LeveneTest.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_levenetest, organization={Wolfram Research}, title={LeveneTest}, year={2017}, url={https://reference.wolfram.com/language/ref/LeveneTest.html}, note=[Accessed: 13-June-2026]}