mixeddata=read.table("http://personality-project.org/r/datasets/R.appendix5.data",header=T) #Valence and Task are within, Gender and Dosage between mixedmod = aov(Recall~(Valence*Gender)+Error(Subject/(Valence)),mixeddata) plot(Recall~Gender, mixeddata, col="papayawhip") #main effect Gender plot(Recall~Valence, mixeddata, col="papayawhip") #main effect Valence with(mixeddata,interaction.plot(Valence,Gender, Recall, main = "Recall", col=2:3) ) #I used 'with' in lieu of attaching the data #Alternate graph boxplot(Recall~Valence*Gender,data=mixeddata, col="lavenderblush2") #that's right, lavenderblush1 was simply not going to cut it, 3 and 4 were overkill #Statistical outcomes summary(mixedmod) model.tables(mixedmod, "means") #Looking at individuals. Note that we have to do it differently than before b/c female subjects are not found in the male cells and vice versa, #so doing it without subsetting would result in 'missing' data and no plot with(subset(mixeddata, Gender=="M"),interaction.plot(Gender:Valence, Subject,Recall, main = "Recall", col=rainbow(9), fixed=T) ) par(new=T) with(subset(mixeddata, Gender=="F"),interaction.plot(Gender:Valence, Subject,Recall, main = "Recall", col=rainbow(10:18), fixed=T) ) #Homework data format assistance library(MASS) data(anorexia) anorexia2=reshape(anorexia, varying=list(2:3), v.names="Weight", times=c("Pre","Post"), timevar="PrePost",idvar="Subject",direction="long") # make the data long format anorexia3=data.frame(Subject=as.factor(anorexia2$Subject), PrePost=as.factor(anorexia2$PrePost), Treat=anorexia2$Treat,Weight=anorexia2$Weight) #convert variables to factors mymixmod=aov(Weight~(Treat*PrePost)+ Error(Subject/PrePost), data=anorexia3) #the as.factor will make it not treat subject as numeric. It will automatically do PrePost and give a warning that it has. #Note that compared to SPSS, the main effect of PrePost will be slightly different as R does type I SS by default (which is equivalent to type II in this scenario with only one RM factor). #SPSS on the other hand is nonsensically controlling for the interaction as part of the main effect of PrePost.