Having trouble finding straightforward information this topic.

Basically, I'm trying to use the lme4 package to analyze my data, and the model looks something like (A ~ BCD) + (random effects term 1) + (random effects term 2).

'A' is a yes/no response, which, based on what I've read, indicates that I should use glmer(). However, my experiment uses repeated measures - each subject undergoes many trials. It's a psychophysical experiment, so there are many subjects who essentially make yes/no judgements about many, many images. I've read that when there are many trials within a subject, you should use lmer().

Sorry if the info given is too sparse; if anyone thinks they can help me out with this, I'll provide as much info as necessary.

Question: When exactly should one use lmer() vs glmer(), especially in the context of psychophysical experiments where one subject will undergo many trials with binomial outcomes?

More info/part 2 of question: I initially analyzed my data using ANOVAs in SPSS. The SPSS indicated a highly significant interaction, one that is logical and predicted. When running the same data to modeled in glmer(), that interaction in highly insignificant. When running through lmer, it is significant again.

If anyone can help shed some light on whether this makes sense or why it would be so, I'd appreciate it very much.

  • $\begingroup$ Does, in your case, repeated measure mean that you have measured A at different time points (say, every 6 months over a period of 2 years)? I don't see why you would model a binary response in growth models (first two time points a person answered "yes", the last two time points "no"). If you are saying that subjects make judgements many times, perhaps your response is always a different one? $\endgroup$
    – Daniel
    Aug 2, 2016 at 20:10
  • $\begingroup$ No, not measured at different time points. It means each subject makes a response about similar images featuring different conditions. Specifically, there are hundreds of images featuring a target that can vary in size and position. For each image, the subject has to decide whether the target is on the left or the right side of the screen, so their response is correct/incorrect. Whether or not they correctly detected the stimulus would depend on 3 things: age (between-subjects factor) and target size/position (within-subjects factors) $\endgroup$
    – Socratease
    Aug 2, 2016 at 20:19
  • $\begingroup$ So what is your dependent variable? You don't want to run hundreds of models, one per image, where the response "correct/incorrect" for this image is used as dependent variable? $\endgroup$
    – Daniel
    Aug 2, 2016 at 20:21
  • $\begingroup$ What exactly are your lmer and glmer model formulas? Also, please provide output from str(data) and head(data). It sounds like you have repeated measures on subjects but without more information it is hard to advise. Also, do different subjects make judgements on the same images ? $\endgroup$ Aug 2, 2016 at 20:31
  • $\begingroup$ @Daniel - The dependent variable is the subject response. The independent factors are the size and position of the stimulus, as well as the age group of the subject. In a simple ANOVA, actually the medians of each condition were first calculated and then compared. I think this part of my confusion - I'm not sure if my data is truly binary, when we're often actually working with these "response accuracies" that are calculated from binary responses. $\endgroup$
    – Socratease
    Aug 3, 2016 at 3:09

1 Answer 1


lmer is used to fit linear mixed-effect models, so it assumes that the residual error has a Gaussian distribution. If your dependent variable A is a binary outcome (e.g. a yes/no response), then the error distribution is binomial and not Gaussian. In this case you have to use glmer, which allow to fit a generalized linear mixed-effects model: these models include a link function that allows to predict response variables with non-Gaussian distributions. One example of link function that could work in your case is the logistic function, which takes an input with any value from negative to positive infinity and return an output that always takes values between zero and one, which is interpretable as the probability of the binary outcome (e.g. the probability of the subject responding 'yes').

About the repeated measurement design, both lmer and glmer can handle it equally well, you just have to set 'subject' as a grouping factor (in the random-effect part of the model) for the within-subject predictors. In this way you allow these predictors to have a fixed-effect (common to all subjects) and a subject-specific random effect, so that you can test statistically the effect common to all subjects, and treat the subject-specific variations as a nuisance term.

For more details on how to proceed I would recommend this excellent book by Knoblauch and Maloney that dedicates a large section on the application of mixed-effects models (using R and the lme4 library) to the modelling of psychophysical data.

  • $\begingroup$ Thanks so much for this response and the book recommendation, they're both very helpful. How would I go about applying the link function? Also, do you have any insight as to the second part of my question (under the tl;dr?) $\endgroup$
    – Socratease
    Aug 3, 2016 at 14:01
  • 3
    $\begingroup$ I suggest you to read carefully the documentation about the functions glm and glmer. You will see that you can set the link function through the family argument of the function. For example to fit a logistic model you should set it to family=binomial(link = "logit") $\endgroup$
    – matteo
    Aug 4, 2016 at 12:26
  • 2
    $\begingroup$ It isn't t surprising that also lmer find a significant interaction, especially if the effect is large. Nevertheless a linear regression fit (such as lmer) is wrong when your data is binomial (i.e. a binary outcome). It would violate the assumptions of the linear models (which assume that the outcome variable is continuous, the residual are normally distributed with constant variance, and so on). Even if the linear regression might result in similar parameter estimates, the estimated standard error for these parameters will be invalid, and might lead to erroneous inferences. $\endgroup$
    – matteo
    Aug 4, 2016 at 13:01
  • $\begingroup$ I know this is an old post but you may want to use signal detection theory to analyze this type of data. If you calculate the sensitivity (d') and Bias (c) of each individual over all the stimuli for each session, you can analyze their sensitivity to the stimulus and their bias for selecting left or right. This is will not tell you the same thing as a raw analysis of your data, instead, this will tell you more about how well an individual was able to detect the stimulus and not just percentages. $\endgroup$ Nov 14, 2019 at 21:08
  • $\begingroup$ A probit GLM would be exactly equivalent to a (Gaussian, equal-variance) SDT analysis; see here mlisi.xyz/files/SDT_GLM.pdf, although of course there's more to SDT than Gaussian-equal-variance models $\endgroup$
    – matteo
    Nov 15, 2019 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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