2
$\begingroup$

I am new to the forum, but I have been following for quite some time. I have a perhaps stupid 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?
$\endgroup$
  • $\begingroup$ See Ben Bolker's answer here. stats.stackexchange.com/questions/79360/… $\endgroup$ – gammer Jan 31 '17 at 2:59
  • $\begingroup$ I'm pretty sure he's one of the people who wrote lme4 so I think he knows what he's talking about. $\endgroup$ – gammer Jan 31 '17 at 2:59
  • $\begingroup$ @Stefan, I took this as asking about the syntax, which Ben's answer clarifies pretty well in my opinion. $\endgroup$ – gammer Jan 31 '17 at 3:11
  • $\begingroup$ @Andrew, if you look at the link, you'll see that model.1 includes a random effect for subject (which trial is nested within). Model.2 does not include that. I know nothing about the application so I have no clue which is right. You might do a test to see whether model.1 (the larger model) is better. Or use substantive knowledge. Good luck. $\endgroup$ – gammer Jan 31 '17 at 3:12
  • $\begingroup$ Thank you all for your help! I will check the link and see if it applies to my case as well. I will try to compare the two models and see if the first is better than the second.. Thanks! $\endgroup$ – Andrew Jan 31 '17 at 8:50
3
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Good answer. Under some circumstances, trial could be a reasonable random effect (e.g. if the images are inhomogeneous in terms of their error rate for some reason not captured by X, Y, and Z) but, as described, I'd be inclined to agree that model.3 makes the most sense. $\endgroup$ – gammer Jan 31 '17 at 4:51
  • $\begingroup$ Thanks for the comments! The reason why I chose model.1 is because I assumed that participants will vary in the extent to which they answer to the trials. Let's say that in trial 1 there is variability across subjects in their responses. Would this help? $\endgroup$ – Andrew Jan 31 '17 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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