# Mixed Model Type-III Sums of Squares- R vs SPSS

The age old question of comparing sums of squares (SS) between programs has reared its ugly head again.

I am trying to replicate output in SPSS, that was computed using Type 3 Sums of Squares, in R.

I understand that with multiple regressions, there are several ways to get Type 3 SS in R (to match Type 3 output from SPSS).

However, I am running a mixed model using aov (which uses Type 1 SS) and even when I try all the "usual" fixes," my estimates don't match the Type 3 SS output from SPSS.

First of all, when I run the SPSS syntax using "/METHOD=SSTYPE(1)" the results match those I get using this code:

  mymodel<-aov(data=longdat,  DV ~ 1 + Task + Cue + Compatibility + Cue:Task + Compatibility:Task + Cue:Compatibility + Cue:Compatibility:Task + Error(subject/Cue/Compatibility/Cue*Compatibility))
summary(mymodel)


So I know the analyses are the same when they use Type 1 SS.

However, when I use:

 options(contrasts = c("contr.sum","contr.poly"))
drop1(tt, ~., test="F")


The results do not match the SPSS Type 3 output.

In attempts to get matching output, I have also tried the Anova function (which can give Type 3 SS)

  Anova(mymodel, type=3, test.statistic="F")


but I get this error "Error in terms.formula(formula, data = data) : 'data' argument is of the wrong type."

I have also tried using lmer.

Can someone help me get Type 3 Sums of Squares for a mixed model in R?

Thank you!

• (I changed the title a bit adding the term Type-III so it is more obvious what you are asking for. I hope you do not mind, please feel free to change it too.) – usεr11852 Mar 3 '15 at 20:55
• You showed R syntax you did but did not show the SPSS syntax. Why so? How can one follow you? – ttnphns Mar 4 '15 at 7:12
• Unfortunately the SPSS syntax is not mine to share. Apologies for any confusion! – Sarah Thomas Mar 27 '15 at 19:21

I think the simplest thing to do will be to simply use the functions mixed and aov.car from the package afex. Please note that to calculate the degrees of freedom these functions use the Kenward-Rogers approximation. Other functions (or other software in general) might use Satterthwaite approximations. A very interesting discussion on Type-III sums was done in this site and is available: here.

Thanks! I tried to use the mixed function but my random effects were giving different results than the SPSS output. I ended up using the ezAnova function with this code (at the advice of a colleague).

ezANOVA( data = longdat, dv = DV, wid = subject,
within = .(Cue,Compatibility),   between = Task, type = 3, detailed=TRUE)


and the anova_out function in the schoRsch package to get a partial eta squared.

These two functions allowed me to replicate the SPSS mixed ANOVA output.

• +1. No problem. And thank you for posting your solution. It creates a good resource for future users! :) (I formatted your code again a bit.) – usεr11852 Mar 6 '15 at 21:07