in need of some clarity (or charity, whichever way you look at it) - haha!

Running a linear mixed regression with two within subject variables each of which has two levels (AB, XY), with the DV as the DV (this was randomly generated), there are 10 participants in this randomly generated dataset. Data structure looks like this:

Subject  AB XY        DV
1        1  1   0.8434005
1        1  2   0.6905524
1        2  1   1.8233546
1        2  2   1.4140288

Using Lmertest, I firstly ran the following for the main effects model with subjects as a random variable:

> anova(lmer(DV~AB+XY+(1|Subject), data=df))
Type III Analysis of Variance Table with Satterthwaite's method
    Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
AB 0.03248 0.03248     1    28  0.0322 0.8589
XY 0.49017 0.49017     1    28  0.4861 0.4914

Then ran the model with the interaction:

> anova(lmer(DV~AB*XY+(1|Subject), data=df))
Type III Analysis of Variance Table with Satterthwaite's method
      Sum Sq Mean Sq NumDF DenDF F value  Pr(>F)  
AB    3.6828  3.6828     1    27  4.0786 0.05346 .
XY    2.6918  2.6918     1    27  2.9811 0.09567 .
AB:XY 3.8526  3.8526     1    27  4.2666 0.04859 *
---

As you can see the Main effects have changed wildly across their values.

When I run a similar analysis in SPSS, there is no such change to the values of the main effects. Have I done something wrong? Why would adding an interaction change the main effect? And why does no such change happen in SPSS? Please advise or signpost me to some resources as I am having no luck. I do know that getting R and SPSS to produce the same output has its difficulties, but this seems like a very fundamental issue - either the interaction term changes the main effects or it does not.

Is this something to do with the type of anova being conducting? type I would do AB and then XY and then AB*XY, but type III does something more complex where it does them all together? Would that indicate that SPSS (as adding the interaction does not change the values for the main effect) is not doing a type III anova?

Thanks in advance for any help at all!

migrated from stackoverflow.com Oct 27 at 11:07

This question came from our site for professional and enthusiast programmers.

  • this blog post suggests that SPSS uses Helmert contrasts by default. Can you give us a reproducible example ... ? – Ben Bolker Oct 20 at 14:54
  • Ah, sorry I did not realise. I think you were correct regarding your contrast comments, as now it does appear to be working now! I thought I had changed the contrast options but I must have made a mistake. Thank you for the help. – APaice Oct 20 at 21:38
  • 1
    well, if you've answered your own question, you can (are encouraged to) post an answer -- this won't be the last time someone asks this question ... (the fact that you understand the comment about contrasts means you're already ahead of a lot of the people using linear models to try to answer questions ...) – Ben Bolker Oct 20 at 21:42

OP here, the answer was simply that I had not changed the default constrasts in R to match those used in spss (an oversight). The code for this change of constrast is:

options(contrasts = c("contr.helmert", "contr.poly"))

Now the main effects are not altered by the interaction! Which makes it closer to what SPSS is doing, if you are interested in making them look similar.

My dataset looks like this:

'data.frame':   40 obs. of  4 variables:
 $ Subject: Factor w/ 10 levels "1","2","3","4",..: 1 1 1 1 2 2 2 2 3 3 ...
 $ AB     : Factor w/ 2 levels "1","2": 1 1 2 2 1 1 2 2 1 1 ...
 $ XY     : Factor w/ 2 levels "1","2": 1 2 1 2 1 2 1 2 1 2 ...
 $ DV     : num  1.45 2.35 2.46 1.2 2.27 ..

And the linear models (with output) look like this (I am using lmerTest):

anova(lmer(DV~AB+XY+(1|Subject),data=df))

Type III Analysis of Variance Table with Satterthwaite's method
   Sum Sq Mean Sq NumDF DenDF F value  Pr(>F)  
AB 0.0002  0.0002     1    28  0.0003 0.98716  
XY 3.3457  3.3457     1    28  4.7797 0.03732 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1   

anova(lmer(DV~AB*XY+(1|Subject),data=df))  

Type III Analysis of Variance Table with Satterthwaite's method
      Sum Sq Mean Sq NumDF DenDF F value  Pr(>F)  
AB    0.0002  0.0002     1    27  0.0003 0.98664  
XY    3.3457  3.3457     1    27  5.1769 0.03104 *
AB:XY 2.1497  2.1497     1    27  3.3264 0.07927 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Hopefully that sums that up!

Although as stated in the comments, this answer may have been better suited to Crossvalidated so apologies for that.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.