# Mixed effect logistic regression: defining random effect for repeated measure design with replications

I measured a binary response for each subject in 5 different conditions. For each subject and condition, I replicated the experiment 36 times. I thus have 36 binary values per condition per subject.

I am trying to build a model for those data. I suppose a logistic regression is what I'm looking for, and I am working with the lmer package. My aim is to check whether the conditions significantly influence the observed values, so I would have two models:

lmH1<-lmer(value~condition, (random effects), data=dataset, family=binomial)


and

lmH0<-lmer(value~1, (random effects), data=dataset, family=binomial)


By looking at the output from anova(lmH0, lmH1), I would be able to determine the significance of the effect of my condition.

I am just not sure what to specify as random effect; the models I defined so far are:

lmH1 <- lmer( value ~ condition + ( 1 | subject ), data = dataSet, family = binomial )


and

lmH2 <- lmer( value ~ condition + ( 1 | subject/condition ), data = dataSet, family = binomial )


However I am not sure about how lmer handles the replicates, so I don't know whether I should include those replicates in my random effects or not. I could modify the proposed models so that the grouping defined by the random effects refers to a specific binary values instead of a group of binaries values. My new models would then be

lmH1a <- lmer( value ~ condition + ( 1 | subject/(condition:replicate) ), data = dataSet, family = binomial )


and

lmH2a <- lmer( value ~ condition + ( 1 | subject/condition/replicate ), data = dataSet, family = binomial )


With those models R returns the warning message Number of levels of a grouping factor for the random effects is equal to n, the number of observations. But the model is still computed.

All 4 models return very similar values for the fixed effects and for the random effects that they have in common (e.g. the subject random effects are very similar for all 4 models and the condition within subject random effects are very similar for lmH2 and lmH2a).

How can I check which random effect structure is the most appropriate for my design and collected data?

## 1 Answer

Your simple (1|subject) is best for just trying to use multi-level modelling as a replacement for repeated measures ANOVA. Your other ones are all incorrect. lmer handles using lmH1 just fine. There's no need to try to define them further.

There are certainly other ways to define random effects in order to ask different questions and you should really look at a variety of examples online to find them. Searching for lmer on this site will help.

• Thanks John for your reply. I'm not familiar with logistic regression and lme4, but I spent some time playing with the nlme package, and the lmH2 model corresponds to the Machines example of Pinheiro and Bates book (2000, pp. 24). Having subject and condition nested within subject as a random effects accounts for the random interaction between subject and condition. We don't expect the outcome for a given subject to deviate from the fixed effect model with the exact same magnitude for all conditions. I don't really get yet why the other models that I mentioned would be incorrect. – Adrien Combaz Sep 2 '13 at 9:57
• They're incorrect if you're just trying to do something as equivalent as possible to repeated measures ANOVA in a designed experiment like yours. You don't really have a comparable experiment to the Machines one unless your condition variable is a random sample of conditions and you want to see their variability across subjects and make some statement about sampled condition and individual subjects. You don't want that because you have a designed experiment (I think). You might want to see if condition varies randomly by subject (condition|subject). – John Sep 2 '13 at 22:19