Skip to content
Prev 138997 / 398506 Next

Finding Interaction and main effects contrasts for two-wayANOVA

On 3/8/2008 3:05 PM, Dale Steele wrote:
Here is one way to reproduce the SAS contrasts:

   ## the dataset (from Montgomery)
twoway <- read.table("http://dsteele.veryspeedy.net/sta501/twoway.txt",
col.names=c('material', 'temp','voltage'),colClasses=c('factor',
'factor', 'numeric'))

library(gmodels)

fm <- lm(voltage ~ material:temp + 0, data = twoway)

cm <- rbind(
  '21-22-31+32        ' = c(  0,   1, -1,  0,  -1,1,   0,   0,   0),
  'material1-material2' = c(1/3,-1/3,  0,1/3,-1/3,0, 1/3,-1/3,   0),
  'temp50-temp80      ' = c(1/3, 1/3,1/3,  0,   0,0,-1/3,-1/3,-1/3))

estimable(fm, cm)
                      Estimate Std. Error   t value DF     Pr(>|t|)
21-22-31+32          37.75000   25.98486  1.452769 27 1.578118e-01
material1-material2 -25.16667   10.60827 -2.372362 27 2.505884e-02
temp50-temp80        80.66667   10.60827  7.604127 27 3.525248e-08

   This formulates the model so that each coefficient corresponds to one 
of the 9 cell means.  For me, that makes specifying the contrasts much 
easier.