Bartlett's test is used to test whether
multiple data samples have equal variances, against the alternative
that at least two of the data samples do not have equal variances.

The test statistic is

$$T=\frac{\left(N-k\right)\mathrm{ln}{s}_{p}{}^{2}-{\displaystyle \sum _{i=1}^{k}\left({N}_{i}-1\right)\mathrm{ln}{s}_{i}{}^{2}}}{1+\left(1/\left(3\left(k-1\right)\right)\right)\left(\left({\displaystyle \sum _{i=1}^{k}1/\left({N}_{i}-1\right)}\right)-1/\left(N-k\right)\right)},$$

where $${s}_{i}{}^{2}$$ is the variance of the *i*th
group, *N* is the total sample size, *N*_{i} is
the sample size of the *i*th group, *k* is
the number of groups, and $${s}_{p}{}^{2}$$ is
the pooled variance. The pooled variance is defined as

$${s}_{p}{}^{2}={\displaystyle \sum _{i=1}^{k}\left({N}_{i}-1\right){s}_{i}{}^{2}/\left(N-k\right).}$$

The test statistic has a chi-square distribution with *k* –
1 degrees of freedom under the null hypothesis.

Bartlett's test is sensitive to departures from normality.
If your data comes from a nonnormal distribution, Levene's
test could provide a more accurate result.

The Levene, Brown-Forsythe, and O'Brien
tests are used to test if multiple data samples have equal variances,
against the alternative that at least two of the data samples do not
have equal variances.

The test statistic is

$$W=\frac{\left(N-k\right){\displaystyle \sum _{i=1}^{k}{N}_{i}{\left({\overline{Z}}_{i.}-{\overline{Z}}_{\mathrm{..}}\right)}^{2}}}{\left(k-1\right){\displaystyle \sum _{i=1}^{k}{\displaystyle \sum _{j=1}^{{N}_{i}}{\left({Z}_{ij}-{\overline{Z}}_{i.}\right)}^{2}}}},$$

where *N*_{i} is
the sample size of the *i*th group, and *k* is
the number of groups. Depending on the type of test specified with
the `TestType`

name-value pair arguments, *Z*_{ij} can
have one of four definitions:

If you specify `LeveneAbsolute`

, `vartestn`

uses $${Z}_{ij}=\left|{Y}_{ij}-{\overline{Y}}_{i.}\right|$$, where $${\overline{Y}}_{i.}$$ is the mean of the *i*th
subgroup.

If you specify `LeveneQuadratic`

, `vartestn`

uses $${Z}_{ij}{}^{2}={\left({Y}_{ij}-{\overline{Y}}_{i.}\right)}^{2}$$, where $${\overline{Y}}_{i.}$$ is the mean of the *i*th
subgroup.

If you specify `BrownForsythe`

, `vartestn`

uses $${Z}_{ij}=\left|{Y}_{ij}-{\tilde{Y}}_{i.}\right|$$, where $${\tilde{Y}}_{i.}$$ is the median of the *i*th
subgroup.

If you specify `OBrien`

, `vartestn`

uses

$${Z}_{ij}=\frac{\left(0.5+{n}_{i}-2\right){n}_{i}{\left({y}_{ij}-{\overline{y}}_{i}\right)}^{2}-\text{\hspace{0.17em}}\text{\hspace{0.17em}}0.5\left({n}_{i}-1\right){\sigma}_{i}{}^{2}}{\left({n}_{i}-1\right)\left({n}_{i}-2\right)},$$

where *n*_{i} is
the size of the *i*th group, σ_{i}^{2} is
its sample variance.

In all cases, the test statistic has an *F*-distribution
with *k* – 1 numerator degrees of freedom,
and *N* – *k* denominator
degrees of freedom.

The Levene, Brown-Forsythe, and O'Brien tests are less
sensitive to departures from normality than Bartlett's test,
so they are useful alternatives if you suspect the samples come from
nonnormal distributions.