[R] anova planned comparisons/contrasts

Tyler Smith tyler.smith at mail.mcgill.ca
Sat Nov 24 21:11:26 CET 2007


On 2007-11-22, Dieter Menne <dieter.menne at menne-biomed.de> wrote:
> Tyler Smith <tyler.smith <at> mail.mcgill.ca> writes:
>
>> I'm trying to figure out how anova works in R by translating the
>> examples in Sokal And Rohlf's (1995 3rd edition) Biometry. I've hit a
>> snag with planned comparisons, their box 9.4 and section 9.6. It's a
>> basic anova design:
>> 
>
> .... how to do contrast....
>
> It's easier to use function estimable in package gmodels, or glht in package
> multcomp.
>

Isn't glht calculating unplanned comparisons, as opposed to the
planned comparisons with contrasts() and summary(..., split= ...)? Can
you do planned comparisons with glht, or unplanned comparisons with
summary()? 

contrasts(warpbreaks$tension) <- matrix(c(-1,1,0,1,0,-1,0,-1,1), 3, 3)
amod <- aov(formula = breaks ~ tension, data = warpbreaks)

## this isn't right:
summary(amod, split = list(tension = list('L vs M' =1, 'L vs H'=2, 
	      'M vs H' = 3)))

## posthoc contrasts (three ways to do the same test, I think):
summary(glht(amod, linfct = mcp(tension = 'Tukey')))
summary(glht(amod, linfct = mcp(tension = 
		   	    	matrix(c(-1,1,0,1,0,-1,0,-1,1), 3, 3))))
TukeyHSD(amod)

Thanks,

Tyler



More information about the R-help mailing list