If you doubt that groups A, B, C are from populations with equal population variances, but believe that data are reasonably close to normal, then you can use a version of a one-way ANOVA that does not require equal variances. In R, this procedure is oneway.test
.
[This would be analogous to choosing a Welch two-sample t test instead of a pooled t test, if you had only two levels of the factor.]
Here is an example:
set.seed(2021)
a = rnorm(32, 101, 16)
b = rnorm(30, 110, 10)
c = rnorm(40, 114, 9)
x = c(a,b,c)
g = as.factor(rep(1:3, c(32,30,40)))
boxplot(x~g, col="skyblue2")
oneway.test(x ~ g)
One-way analysis of means
(not assuming equal variances)
data: x and g
F = 4.6551, num df = 2.000, denom df = 55.596,
p-value = 0.01351
Not assuming equal variances, oneway.test
finds
a significant difference at the 2% level. [An ad hoc Welch
2-sample t test finds a significant difference between a
and c
,
but not for the other comparisons among levels.]
t.test(a,c)$p.val # Welch 2-sample t test
[1] 0.007086897
By contrast, a standard ANOVA (incorrectly assuming equal variances)
finds a significant difference at the lower 1% level, which is not
justifiable in view of the unequal variances among levels. [Notice that
oneway,test
uses denominator DF = 55, as a 'penalty' for unequal variances, while the standard ANOVA uses DDF = 99.]
anova(lm(x~g))
Analysis of Variance Table
Response: x
Df Sum Sq Mean Sq F value Pr(>F)
g 2 1757.8 878.88 5.3814 0.006045 **
Residuals 99 16168.5 163.32
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Unless you are quite sure--based on previous knowledge or experience
with similar data--that levels of such a factor must have nearly equal variances, it is good practice to do the version of the ANOVA that
does not assume equal variances. Tests for equal variance are known
to have low power, so 'branching' to one kind of ANOVA or the other
based on such a test is not a good idea. If there is a question about
the normality of the data, it may be best to use a nonparametric "ANOVA"
(possibly a permutation test).
Note: Example of a permutation test.
The major finding from my (fake) data above was that sample means for A and C are statistically different.
Regardless of its distribution, suppose I am willing to use the Welch t statistic as a reasonable measure ('metric') of the distance between $\bar X_A$ and $\bar X_C.$ Under the null hypothesis $H_0:\mu_A = \mu_B,$ it should not matter which of the $32+40 = 72$ observations comes from which group.
By repeatedly re-assigning the observations at random to groups of sizes $32$ and $40$ and computing the Welch t statistic for each assignment, I can get a good idea of the permutation distribution of that statistic. This method of approximating the permutation distribution does not depend on the normality or homoscedasticity of the data.
Then, if the observed Welch t from the actual assignment is sufficiently far into a tail of the permutation distribution, I can reject $H_0.$
AC = c(a,c); G=rep(1:2, c(32,40))
t.obs = t.test(AC~G)$stat
set.seed(101)
t.perm = replicate(10^5, t.test(AC~sample(G))$stat)
mean(abs(t.perm) >= abs(t.obs))
[1] 0.00617 # P-value of permutation test
hist(t.prm, prob=T, col="skyblue2", main="Permutation Dist'n")
abline(v=c(-t.obs, t.obs), col="red")