Solved – Repeated measures with lmer and logistic regression

lme4-nlmelogisticrrepeated measures

I have a question about the lmer() function and repeated measures design with R.

In my study, each participant sees 60 trials, presented at random. In each trial, the participants have to report whether they see something or not (so, it is a yes/no answer). I was recommended to use R and the lmer package. I built the following model, which seems to support my hypothesis. Yet, I want to be sure that I am building it correctly. Basically, the syntax is the following:

model.1 <- glmer(DV ~ X + Y + Z + Y:Z + (1|Trial/Subject), data=data, family="binomial")

X, Y, and Z are my predictors (all continuous variables).
I also tested a second model (see below):

model.2 <- glmer(DV ~ X + Y + Z + Y:Z + (1|Trial), data=data, family="binomial")

My questions are:

  1. Is model.1 correct in terms of random effect?
  2. What is the difference between the two models?

Best Answer

Given the information you provided, I would simply specify Subject as random:

model.3 <- glmer(DV ~ X + Y + Z + Y:Z + (1|Subject), data=data, family="binomial")

Having Subject specified in the model will account for the multiple measurements on the same subjects (the "repeated measurements" aspect of your study). Neither of your models (i.e. model.1 and model.2 does that; see further below).

Unless there is a reason that those 60 random trials might differ among subjects, which I don't know, I wouldn't take Trial into the model.

In the random statement, you want to include things that would fall under (a) "pseudo-replication" (temporal and spatial) and (b) factors for which you want a variance to be estimated. For example, if you were to repeat your experiment in different cities, or different hospitals, or other things that could affect the outcome, I would include this in the random statement as well. This will allow you to capture this additional potential variation, which may or may not be of interest to you.

To answer your second question, the difference between + (1|Trial/Subject) and + (1|Trial) is that the former has Subject nested in Trial, which expands to + (1|Trial) + (1|Trail:Subject) and means that you want to capture the variance (a) due to Trial and (b) the variance of the grouping of Trial with Subject; while in the latter you only want to account for the variation due to Trial. You should always check your model with summary(my.model) and find the line where it says Number of obs: and groups:. There you can double check whether your syntax captures the number of groups for which you wanted to the variances to be estimated.

Some useful links: http://glmm.wikidot.com/faq and in particular to understand the (g)lmer syntax for the random statement http://glmm.wikidot.com/faq#toc27

There are also a lot of other question regarding model specifications here on Cross Validated.

You may find this one helpful as well: http://rpsychologist.com/r-guide-longitudinal-lme-lmer

Related Question