# 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?

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.