I have 3 different samples of size 5, mean 100 and standard deviation 12.
How do I compare the 3 variances at the same time? I know I need to make a new table, but I have no idea how to do it.
I have 3 different samples of size 5, mean 100 and standard deviation 12.
How do I compare the 3 variances at the same time? I know I need to make a new table, but I have no idea how to do it.
I will assume that the samples are of normal variables, with mean 100 and standard deviation 12. To test the homogeneity of variances, there is the Levene test, which can be found in the package car
.
library(car)
set.seed(343) # Torna o exemplo reprodutível
n <- 5
x <- rnorm(n, mean = 100, sd = 12)
y <- rnorm(n, mean = 100, sd = 12)
z <- rnorm(n, mean = 100, sd = 12)
Now, we add the samples in a variable v
of a data.frame
, with a factor
, the variable f
that tells us which sample belongs to each line of the df.
dados <- data.frame(f = rep(letters[24:26], each = n), v = c(x, y, z))
leveneTest(v ~ f, data = dados, center = mean)
#Levene's Test for Homogeneity of Variance (center = mean)
# Df F value Pr(>F)
#group 2 0.2198 0.8058
# 12
An alternative form, taking into account that you refer to the ANOVA table, will be to use the functions for the linear model, both lm
and aov
.
modelo <- aov(v ~ f, data = dados)
leveneTest(modelo, center = mean)
The results are the same.
EDITION.
There is also the Brown-Forsythe test, which although perhaps be less used, may have advantages, namely in terms of robustness. A function that performs this test can be found in the onewaytests
package.
library(onewaytests)
bf.test(v ~ f, data = dados)
#
# Brown-Forsythe Test
#---------------------------------------------------------
# data : v and f
#
# statistic : 0.156811
# num df : 2
# denom df : 11.3735
# p.value : 0.8566824
#
# Result : Difference is not statistically significant.
#---------------------------------------------------------
#
Again, there is no evidence of variance heterogeneity. The null hypothesis is not rejected. We can therefore perform an ANOVA test for the mean difference, where one of the assumptions is precisely the equality of variances.