Equality (Homogeneity) of Variance
Menu locations:
Analysis_Analysis of Variance_One Way
Analysis_Analysis of Variance_Kruskal-Wallis.
StatsDirect provides parametric (Bartlett and Levene) and nonparametric (squared ranks) tests for equality/homogeneity of variance.
Most commonly used statistical hypothesis tests, such as t tests, compare means or other measures of location. Some studies need to compare variability also. Equality of variance tests can be used on their own for this purpose but they are often used alongside other methods (e.g. analysis of variance) to support assumptions made about variance. For this reason, StatsDirect presents equality of variance tests with analysis of variance.
Bartlett and Levene (parametric) tests
Two samples
Use the F test to compare the variances of two random samples from a normal distribution. Note that the F test is quite sensitive to departures from normality; if you have any doubt then please use the nonparametric equivalent described below.
More than two samples (Levene)
StatsDirect gives Levene's test as an option with One Way Analysis of Variance.
The W50 definition of Levene test statistic (Brown and Forsythe, 1974) is used; this is essentially a one way analysis of variance on the absolute (unsigned) values of the deviations of observations from their group medians.
Levene's test assumes only that your data form random samples from continuous distributions. If you are in any doubt about this, use the squared ranks test presented below, it is generally more robust.
More than two samples (Bartlett)
StatsDirect gives Bartlett's test as an option with One Way Analysis of Variance.
Bartlett's test assesses equality of the variances of more than two samples from a normal distribution (Armitage and Berry, 1994).
Please note that Bartlett's test is not reliable with moderate departures from normality; use Levene's test as an alternative routinely. Bartlett's test is included here solely for the purpose of continuity with textbooks.
Squared Ranks (nonparametric) test
StatsDirect gives the squared ranks test as an option in the Kruskal-Wallis test.
The squared ranks test can be used to assess equality of variance across two or more independent, random samples which have been measured using a scale that is at least interval (Conover, 1999).
When you analyse more than two samples with the squared ranks test, StatsDirect performs an automatic comparison of all possible pair-wise contrasts as described by Conover (1999).
Assumptions of the squared ranks test:
-
random samples
-
independence within samples
-
mutual independence between samples
-
measurement scale is at least interval
Example
From Conover (1999, p. 305).
Test workbook (Nonparametric worksheet: Machine X, Machine Y).
The following data represent the weight of cereal in boxes filled by two different machines X and Y.
| Machine X | Machine Y |
| 10.8 | 10.8 |
| 11.1 | 10.5 |
| 10.4 | 11.0 |
| 10.1 | 10.9 |
| 11.3 | 10.8 |
| 10.7 | |
| 10.8 |
To analyse these data in StatsDirect you must first prepare them in two workbook columns appropriately labelled. Alternatively, open the test workbook using the file open function of the file menu. Then select Kruskal-Wallis from the Nonparametric section of the analysis menu. Then select the columns marked "Machine X" and "Machine Y" in one selection action. Ignore the Kruskal-Wallis test result and choose "Equality of variance (squared ranks)" from the options offered after the analysis.
For this example:
Squared ranks approximate equality of variance test (2 sample)
z = 2.327331
Two tailed P = 0.0199
One tailed P = 0.01
Here we reject the null hypothesis that the samples are from identical distributions (except for possibly different means) and we infer a statistically significant difference between the variances.
The parametric tests are given as an option of One Way Analysis of Variance. For the one way example (Expt 1 to Expt 4 in the ANOVA worksheet of the test workbook), selecting the equality of variance option gives:
Approximate equality of variance tests and adjusted ANOVA
Levene's (W50) F = 0.090165 (df = 3, 16) P = 0.9644
Bartlett's chi-square = 0.155706 df = 3 P = 0.9844
Welch adjusted ANOVA F = 2.059491 (df = 3, 8.867108) P = 0.177
Here there is no evidence that the variances differ, and the Welch adjustment does not change the conclusion of the one way analysis (P = 0.177 against P = 0.1195).
R code
This R code reproduces the two examples above. It needs no packages and was checked with R 4.6.1. Paste it into R, or save it as a script and run it.
# Squared ranks test for equality of variance: the StatsDirect help example
# (Conover 1999, weights of cereal boxes filled by two machines) in R
x <- c(10.8, 11.1, 10.4, 10.1, 11.3) # Machine X
y <- c(10.8, 10.5, 11.0, 10.9, 10.8, 10.7, 10.8) # Machine Y
# R has no squared ranks test, so it is calculated as Conover (1999) describes:
# each observation's absolute deviation from its sample mean is ranked over
# both samples together (mid-ranks for ties), and the test statistic is the
# sum of the squared ranks of the first sample, standardised with the
# correction for ties
u <- c(abs(x - mean(x)), abs(y - mean(y)))
r <- rank(u)
n1 <- length(x)
n2 <- length(y)
N <- n1 + n2
ssq <- sum(r[1:n1]^2)
r2bar <- mean(r^2)
z <- (ssq - n1 * r2bar) /
sqrt(n1 * n2 / (N * (N - 1)) * sum(r^4) - n1 * n2 / (N - 1) * r2bar^2)
six <- function(x) formatC(x, digits = 6, format = "f", drop0trailing = TRUE)
pv <- function(p) {
if (p < 0.0001) "P < 0.0001" else
paste("P =", formatC(p, digits = 4, format = "f", drop0trailing = TRUE))
}
cat("z =", six(z), "\n")
cat("Two tailed", pv(2 * pnorm(-abs(z))), "\n")
cat("One tailed", pv(pnorm(-abs(z))), "\n")
# The parametric tests, illustrated with the one way ANOVA example (Armitage
# and Berry 1994, worms recovered from four groups of rats): StatsDirect gives
# them as an option of One Way, in one report with the Welch adjusted ANOVA
worms <- c(279, 338, 334, 198, 303, 378, 275, 412, 265, 286,
172, 335, 335, 282, 250, 381, 346, 340, 471, 318)
group <- factor(rep(paste("Expt", 1:4), each = 5))
# Levene's test in its W50 form (Brown and Forsythe 1974) is a one way ANOVA
# of the absolute deviations from the group medians
dev <- abs(worms - ave(worms, group, FUN = median))
lev <- anova(aov(dev ~ group))
dfs <- function(a, b) paste0("(df = ", a, ", ", b, ")")
cat("Levene's (W50) F =", six(lev$"F value"[1]), "", dfs(lev$Df[1], lev$Df[2]), "",
pv(lev$"Pr(>F)"[1]), "\n")
# Bartlett's test and the Welch ANOVA are standard R functions
b <- bartlett.test(worms, group)
cat("Bartlett's chi-square =", six(b$statistic), " df =", b$parameter, "",
pv(b$p.value), "\n")
w <- oneway.test(worms ~ group) # var.equal = FALSE is Welch
cat("Welch adjusted ANOVA F =", six(w$statistic), "",
dfs(w$parameter[1], six(w$parameter[2])), "", pv(w$p.value), "\n")