# r lmer syntax for mixed model ANOVA [duplicate]

I have a question concerning a mixed model ANOVA conducted using the lmer function of the lme4 package. Despite a lengthy research across tutorials and forum entries I do not have a clear response to how exactly my lmer formula should be written.

### Experimental design

32 participants take place in the study, half of which constitute the test group, the other half the control group. Both groups do a pre and a posttest, and in both testing sessions they see 18 items of 3 conditions (= 54 items per testing session), and the stimuli of each condition are not repeated in the pre and the posttest.

My question is now if the following formula is correct/complete and if the fact that we deal here with repeated measures is automatically calculated: (dv: dependent variable)

### Formula

fit1 <- lmer(dv ~ (condition * session * group) + (1|item_ID) + (1|subj_ID) + group,
myData, REML=FALSE)


Or is one of the following more accurate:

fit2 <- lmer(dv ~ (condition * session * group) + (1|item_ID) + (1+session|subj_ID) + group,
myData, REML=FALSE)

fit3 <- lmer(dv ~ (condition * session * group) + (1|item_ID) +
(1+session+condition|subj_ID) + group, myData, REML=FALSE)


I have also conducted the ANOVA comparing the three models (anova(fit1,fit2,fit3)) but given that these three models are not equally complex this comparison is actually not valid, is this assumption right?

Moreover, I have included the pbkrtest package to obtain degrees of freedom and p values; are the obtained dfs usable for reporting the inferential statistics or do I need to apply an additional transformation?

## marked as duplicate by Tim♦, Xi'an, kjetil b halvorsen, Christoph Hanck, gung - Reinstate Monica♦ r StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Feb 15 '16 at 12:22

• Well if I'm not mistaken it's less a question of proper implementation and more a question of which effects do you want to estimate. Models 2 and 3 include random slopes for subj_ID in addition to a random intercept. Do you want there to be a random slope corresponding to the effect of session for each subject (models 2 & 3) and a random slope corresponding to the effect of condition for each subject (model 3)? Should the effect of session and condition be different for different subjects? That's a theoretical question as far as I see it, not a question of implementation. – psychometriko Feb 8 '16 at 13:24