2

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)
  • Why did you not post the SPSS syntax as well? How one could replicate your findings without it? – ttnphns Apr 01 '15 at 10:49
  • Good point, added it! – Michele Nuijten Apr 01 '15 at 10:56
  • Looking at your SPSS syntax I may say: it is RM-ANOVA without any explicit random factors (besides the implicit factor "respondent id"). So, find in R the way to do that simple, one within factor X one between factor ANOVA. Note that in R some anova functions have default SS type as I, not III, as SPSS has as default. – ttnphns Apr 01 '15 at 11:07
  • Well, that simple anova is the aov() analysis at the bottom of the R script, that part is fine. However, I can't include Type III Sums of Squares and a polynomial contrast, that's the problem... – Michele Nuijten Apr 01 '15 at 11:09
  • Fine. So, if your main interest is that table "Tests of Within-subject contrasts" of SPSS output with linear and quadratic effects - please wait somebody knowing R to come in and help (I can't help with R, sorry). – ttnphns Apr 01 '15 at 11:17

0 Answers0