[R] contrast matrix for aov

From: Darren Weber <DarrenLeeWeber_at_gmail.com>
Date: Thu 10 Mar 2005 - 11:03:42 EST

How do we specify a contrast interaction matrix for an ANOVA model?

We have a two-factor, repeated measures design, with

Cue Direction (2) x Brain Hemisphere(2)

Each of these has 2 levels, 'left' and 'right', so it's a simple 2x2 design matrix. We have 8 subjects in each cell (a balanced design) and we want to specify the interaction contrast so that:

CueLeft>CueRght for the Right Hemisphere CueRght>CueLeft for the Left Hemisphere.

Here is a copy of the relevant commands for R:

########################################

lh_cueL <- rowMeans( LHroi.cueL[,t1:t2] )
lh_cueR <- rowMeans( LHroi.cueR[,t1:t2] )
rh_cueL <- rowMeans( RHroi.cueL[,t1:t2] )
rh_cueR <- rowMeans( RHroi.cueR[,t1:t2] )
roiValues <- c( lh_cueL, lh_cueR, rh_cueL, rh_cueR )

cuelabels <- c("CueLeft", "CueRight")
hemlabels <- c("LH", "RH")

roiDataframe <- data.frame( roi=roiValues, Subject=gl(8,1,32,subjectlabels), Hemisphere=gl(2,16,32,hemlabels), Cue=gl(2,8,32,cuelabels) )

roi.aov <- aov(roi ~ (Cue*Hemisphere) + Error(Subject/(Cue*Hemisphere)), data=roiDataframe)
print(summary(roi.aov))
########################################

I've tried to create a contrast matrix like this:

cm <- contrasts(roiDataframe$Cue)

which gives the main effect contrasts for the Cue factor. I really want to specify the interaction contrasts, so I tried this:

########################################

# c( lh_cueL, lh_cueR, rh_cueL, rh_cueR )
# CueRight>CueLeft for the Left Hemisphere.
# CueLeft>CueRight for the Right Hemisphere

cm <- c(-1, 1, 1, -1)
dim(cm) <- c(2,2)

roi.aov <- aov( roi ~ (Cue*Hemisphere) + Error(Subject/(Cue*Hemisphere)), contrasts=cm, data=roiDataframe)
print(summary(roi.aov))
########################################

but the results of these two aov commands are identical. Is it the case that the 2x2 design matrix is always going to give the same F values for the interaction regardless of the contrast direction? OR, is there some way to get a summary output for the contrasts that is not available from the print method?



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Mar 10 11:16:12 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:42 EST