I ran a two-way anova in r with my data set (unequal sample sizes, unequal variance): 1 variable measured across 3 species (with males and females in each species). This produces a significant result between species, so I want to know which pairwise comparisons produce the significance. I know that there are functions in packages for performing post hoc tests in R: e.g.
Dunnett's post hoc test from http://www.uwlax.edu/faculty/toribio/math305_fall09/multiple.txt. Packages required: "multcomp", "mvtnorm", "survival", "splines"
library(multcomp)
test.dunnett=glht(anova_results,linfct=mcp(method="Dunnett"))
confint(test.dunnett)
plot(test.dunnett)
*note: glht is described in "multcomp"
But Dunett's test is designed to compare all groups to a control. Instead I want to compare all groups to each other, the Dunnett C. Does anyone know of a package that performs Dunnett C or knows how to code it? (equation at: http://pic.dhe.ibm.com/infocenter/spssstat/v21r0m0/index.jsp?topic=%2Fcom.ibm.spss.statistics.help%2Falg_posthoc_unequalvar.htm)
(So the method
item was defined elsewhere and was not expected to be the name of an argument as I had assumed.) There were three examples of multiple comparisons in the code linked at the uwlax.edu website. The second one gave what it appears you want, namely an all-pairs set of comparisons. It isn't "Dunnett's C" but my experience is that the authors of R generally give the most powerful tests and make it less convenient to use out-moded tests. The citations in the SPSS website for the Dunnett's C code are 40 years old. The citations for the ghlt
and TukeyHSD functions are much more recent and the authors are highly respected. I see no compelling reason to use Dunnett's C and would instead use the TukeyHSD option that achieves your goals:
method1=c(96,79,91,85,83,91,82,87)
method2=c(77,76,74,73,78,71,80)
method3=c(66,73,69,66,77,73,71,70,74)
score=c(method1,method2,method3)
method=c(rep(1,length(method1)),
rep(2,length(method2)),
rep(3,length(method3)))
method=factor(method)
anova_results=aov(score~method)
anova_results
#------------
Call:
aov(formula = score ~ method)
Terms:
method Residuals
Sum of Squares 1090.6190 387.2143
Deg. of Freedom 2 21
Residual standard error: 4.29404
Estimated effects may be unbalanced
#----------
summary(anova_results)
#------------------
Df Sum Sq Mean Sq F value Pr(>F)
method 2 1090.6 545.3 29.57 7.81e-07 ***
Residuals 21 387.2 18.4
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
TukeyHSD(anova_results)
#--------------
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = score ~ method)
$method
diff lwr upr p adj
2-1 -11.178571 -16.78023 -5.5769151 0.0001590
3-1 -15.750000 -21.00924 -10.4907592 0.0000006
3-2 -4.571429 -10.02592 0.8830666 0.1113951
TukeyHSD(anova_results, ordered=T)
#---------------
Tukey multiple comparisons of means
95% family-wise confidence level
factor levels have been ordered
Fit: aov(formula = score ~ method)
$method
diff lwr upr p adj
2-3 4.571429 -0.8830666 10.02592 0.1113951
1-3 15.750000 10.4907592 21.00924 0.0000006
1-2 11.178571 5.5769151 16.78023 0.0001590