How to compare 3 different variances?

Asked

Viewed 199 times

0

I have 3 different samples of size 5, average 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.

  • 3

    Please give an example of data with dput(x), where x is one sample and the same for the others. With sizes equal to 5 should be easy.

1 answer

3

I’m going to assume that the samples are from 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 put the samples together in a variable v of a data.frame, with a factor, the variable f which tells us which sample each row of df belongs to.

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 way, taking into account that referred to the ANOVA table, will be to use the functions for the linear model, both lm as 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 less widely used, can have advantages, particularly in terms of robustness. A function that performs this test can be found in the package onewaytests.

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 difference of means, where one of the assumptions is precisely the equality of variances.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.