Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Homoscedascity test for Two-Way ANOVA

I've been using var.test and bartlett.test to check basic ANOVA assumptions, among others, homoscedascity (homogeniety, equality of variances). Procedure is quite simple for One-Way ANOVA:

bartlett.test(x ~ g)  # where x is numeric, and g is a factor
var.test(x ~ g)

But, for 2x2 tables, i.e. Two-Way ANOVA's, I want to do something like this:

bartlett.test(x ~ c(g1, g2))  # or with list; see latter:
var.test(x ~ list(g1, g2))

Of course, ANOVA assumptions can be checked with graphical procedures, but what about "an arithmetic option"? Is that, at all, manageable? How do you test homoscedascity in Two-Way ANOVA?

like image 847
aL3xa Avatar asked May 29 '10 00:05

aL3xa


3 Answers

Hypothesis testing is the wrong tool to use to asses the validity of model assumptions. If the sample size is small, you have no power to detect any variance differences, even if the variance differences are large. If you have a large sample size you have power to detect even the most trivial deviations from equal variance, so you will almost always reject the null. Simulation studies have shown that preliminary testing of model assumption leads to unreliable type I errors.

Looking at the residuals across all cells is a good indicator, or if your data are normal, you can use the AIC or BIC with/without equal variances as a selection procedure.

If you think there are unequal variances, drop the assumption with something like:

library(car)
model.lm <- lm(formula=x ~ g1 + g2 + g1*g2,data=dat,na.action=na.omit)
Anova(model.lm,type='II',white.adjust='hc3')

You don't loose much power with the robust method (hetroscedastic consistent covariance matrices), so if in doubt go robust.

like image 135
Ian Fellows Avatar answered Nov 05 '22 22:11

Ian Fellows


You can test for heteroscedasticity using the Fligner–Killeen test of homogeneity of variances. Supposing your model is something like

model<-aov(gain~diet*supplement)

fligner.test(gain~diet*supplement)

        Fligner-Killeen test of homogeneity of variances

data:  gain by diet by supplement 
Fligner-Killeen:med chi-squared = 2.0236, df = 2, p-value = 0.3636

You could have used bartlett.test (but this is more a test of non-normality than of equality of variances)

bartlett.test(gain~diet*supplement)
        Bartlett test of homogeneity of variances

data:  gain by diet by supplement 
Bartlett's K-squared = 2.2513, df = 2, p-value = 0.3244

Moreover, you could perform the Levene test for equal group variances in both one-way and two-way ANOVA. Implementations of Levene's test can be found in packages car (link fixed), s20x and lawstat

levene.test(gain~diet*supplement)  # car package version

Levene's Test for Homogeneity of Variance
      Df F value Pr(>F)
group 11  1.1034 0.3866
      36 
like image 7
George Dontas Avatar answered Nov 05 '22 20:11

George Dontas


For bartlett.test

bartlett.test(split(x,list(g1,g2)))

var.test is not applicable as it works only when there are two groups.

like image 6
Jyotirmoy Bhattacharya Avatar answered Nov 05 '22 22:11

Jyotirmoy Bhattacharya