Michael Cantinotti
2013-Oct-03 14:45 UTC
[R] Testing custom linear contrasts with Welch correction (anova function)
Dear R users, I am doing custom contrasts with R (comparison of group means). Everything works fine, but I would like to test the 3 contrasts with and without a Welch correction for unequal variances. I can replicate SPSS results when equal variances are assumed, but I do not manage to test the contrasts when equal variances are not assumed. I pasted below the results with R and SPSS (at the bottom of my email). R provides F, while SPSS provides t (F = t squared). Is there a way to apply the Welch correction to custom contrasts with R anova function (or another correction for unequal variances, like Brown-Forsythe), or do I need to use another package when equal variances cannot be assumed ? Regards, Michael =========================================# R Syntax ========================================= # c1 : group 1 vs. group 2. # c2 : group 3 vs. group 4. # c3 : group 1+2 vs. group 3+4. c1 <- c(1, -1, 0, 0) c2 <- c(0, 0, 1, -1) c3 <- c(1, 1, -1, -1) modele.global <- lm(var ~ cond, data=Plan_CR_4_Modifie) modele.contrastes <- lm(var ~ C(cond, c1, 1) + C(cond, c2, 1) + C(cond, c3, 1), data=Plan_CR_4_Modifie) anova(modele.global) anova(modele.contrastes) ------------------------------------------ R Results: > anova(modele.global) Analysis of Variance Table Response: var Df Sum Sq Mean Sq F value Pr(>F) cond 3 49 16.3333 7.4973 0.0007824 *** Residuals 28 61 2.1786 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > anova(modele.contrastes) Analysis of Variance Table Response: var Df Sum Sq Mean Sq F value Pr(>F) C(cond, c1, 1) 1 1 1.000 0.4590 0.5036442 C(cond, c2, 1) 1 16 16.000 7.3443 0.0113548 * C(cond, c3, 1) 1 32 32.000 14.6885 0.0006571 *** Residuals 28 61 2.179 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 =========================================* SPSS Syntax - CONTRAST TESTS. ========================================= ONEWAY var BY cond /CONTRAST= 1 -1 0 0 /CONTRAST= 0 0 1 -1 /CONTRAST= 1 1 -1 -1 /STATISTICS DESCRIPTIVES HOMOGENEITY /MISSING ANALYSIS /POSTHOC = SCHEFFE LSD BONFERRONI ALPHA(.05). ------------------------------------------ SPSS Results - Contrasts: Assume equal variances |--------|-----------------|----------|------|------|---------------| |Contrast|Value of Contrast|Std. Error|t |df |Sig. (2-tailed)| |--------|-----------------|----------|------|------|---------------| |1 |-.50 |.738 |-.678 |28 |.504 | |--------|-----------------|----------|------|------|---------------| |2 |-2.00 |.738 |-2.710|28 |.011 | |--------|-----------------|----------|------|------|---------------| |3 |-4.00 |1.044 |-3.833|28 |.001 | --------------------------------------------------------------------| Does not assume equal variances |--------|-----------------|----------|------|------|---------------| |Contrast|Value of Contrast|Std. Error|t |df |Sig. (2-tailed)| |--------|-----------------|----------|------|------|---------------| |1 |-.50 |.627 |-.798 |11.603|.441 | |--------|-----------------|----------|------|------|---------------| |2 |-2.00 |.835 |-2.397|10.155|.037 | |--------|-----------------|----------|------|------|---------------| |3 |-4.00 |1.044 |-3.833|19.431|.001 | --------------------------------------------------------------------| [[alternative HTML version deleted]]