I'm trying to replicate SPSS output in R for a mixed ANOVA with a polynomial contrast to test a linear trend.
I fitted a mixed ANOVA in R (see code below), but I can't figure out how to get the results of the polynomial contrast for the within subjects variable and how to produce type III Sums of Squares (since that is the type SPSS uses).
I found several posts related to this question (see e.g., How does one do a Type-III SS ANOVA in R with contrast codes? and Mixed Model Type-III Sums of Squares- R vs SPSS), but I couldn't find the answer to my question.
In the code below, the data set is downloaded directly from Open Science Framework.
My dependent variable is perc_causal_words, my between subjects variable is AffCoh, and my within subjects variable is story.
The SPSS result of the polynomial contrast for story*AffCoh is F(1, 111) = .99, p=.322.
Can someone help me in getting a mixed ANOVA with type III Sums of Squares and a polynomial contrast?
Here is the SPSS syntax I am trying to replicate:
GLM cause.1.00 cause.2.00 cause.3.00 BY AffCoh
/WSFACTOR=story 3 Polynomial
/METHOD=SSTYPE(3)
/CRITERIA=ALPHA(.05)
/WSDESIGN=story
/DESIGN=AffCoh.
The data and the code in R:
library("httr")
library("RCurl")
source("http://sachaepskamp.com/files/OSF/getOSFfile.R") # the getOSFfile function
library("foreign")
library("tidyr")
##@@ DATA LOADING @@##
file <- getOSFfile("https://osf.io/nwbpd/")
data <- read.spss(file)
##@@ DATA MANIPULATION @@##
# select only the variables relevant for the main analysis
# that is: participant number, number of causal words in story 1, 2, and 3,
# and whether participants were in the coherent or incoherent condition
data_mod <- data.frame(data$Participant,
data$cause.1.00,
data$cause.2.00,
data$cause.3.00,
data$AffCoh)
colnames(data_mod) <- c("subject","cause1","cause2","cause3","AffCoh")
data_mod$subject <- as.factor(data_mod$subject)
# gather data into a long format
data_long <- gather(data=data_mod,
key=story,
perc_causal_words,
cause1:cause3)
# fit mixed ANOVA
aov <- aov(perc_causal_words ~ AffCoh * story + Error(subject/story), data=data_long)