8
$\begingroup$

I am trying to fit a mixed effects model with a binary outcome. I have one fixed effect (Offset) and one random effect (chamber, with muliple data points coming from each chamber).

In the text book "The R Book", (2007), pg 604, Crawley suggests using the lmer function with a binomial family for the analysis of binomial data where each participant contributes multiple responses (analagous to each of my chambers contributing multiple outcomes). Based on this example, I have used the following script for my data:

    ball=lmer(Buried~Offset+(1|Chamber), family=binomial, data=ballData)

When I run this model, I get this warning:

    calling lmer with 'family' is deprecated; please use glmer() instead

When I change my code to the following, the model works:

    ball=glmer(Buried~Offset+(1|Chamber), family=binomial, data=ballData)

Based on other questions/answers that I have read on Cross Validated, lmer should only be used for data where the outcome is normally distributed, and glmer is the correct function to use for a binomial outcome. My questions are:

1) Could anyone clarify the discrepency between Crawleys advice and the fact that lmer would not work for me (nor, based on what I have read on CVed, is it recommended to use this function for binomial data)

2) Is glmer indeed the correct function to use to model a binomial outcome with random factors?

3) Assuming that glmer is the correct function to use, I want to compare a model with and without random effects to determine if including random effects improves the fit of the model. I understand that glmer estimates model parameters via maximum likelihood. What function can I use to create a model with no random effects for a binary outcome using maximum likelihood? I was playing around with glm however the help file for this function states that the method of estimation is iteratively reweighted least squares (which is beyond me, but it isn't ML...)

$\endgroup$
1
  • $\begingroup$ A minor point, but one which I believe is not presently addressed by any of the answers: while lmer is no longer appropriate to use with binary outcomes, it is not the case that "lmer should only be used for data where the outcome is normally distributed". More information on this issue is available here. $\endgroup$ Sep 15, 2020 at 8:51

2 Answers 2

15
$\begingroup$

1) In previous versions of the lme4 package, you could run lmer using the binomial family. However, all this did was to actually call glmer, and this functionality has now been removed. So at the time of writing Crawley was correct.

2) Yes, glmer is the correct function to use with a binary outcome.

3) glm can fit a model for binary data without random effects. However, it is incorrect to compare a model fitted with glm to one fitted with glmer using a likelihood-based test because the likelihoods are not comparable. From your description, you have repeated measures within chambers. So, assuming that you have sufficient chambers and these can be thought of as a random sample from a larger population of chambers, then a priori you should retain the random intercepts for Chamber to control for possible non-independence of observations within chambers. You can think of random intercepts as being part of the experimental design.

On the other hand, if the random effect variance is very small and/or the inference or predictions for both the glm and glmer model are the largely the same, then it really doesn't matter which you use anyway.

$\endgroup$
2
  • 3
    $\begingroup$ actually, I think the likelihoods are comparable now between glm and lmer - but I think your advice to keep the random effect is correct anyway $\endgroup$
    – Ben Bolker
    Aug 19, 2016 at 21:48
  • $\begingroup$ Thank you Robert for your advice. Im not too interested in the random effects, I just want to control for the non independence of the responses that came from the same chamber. The variance associated with the random intercepts (grouped by chamber) are quite small, and the models with and without the random terms give me the same answer for my fixed effect. But I will keep the random intercepts to control for the non indepence of the data. Thank you :) $\endgroup$ Aug 22, 2016 at 5:48
2
$\begingroup$

For 2, yes, you should use glmer or glm for binomial outcomes. If you have a little more time to wait for the model to fit---and especially if you are interested in inference for your random effects---I'd suggest using rstanarm::stan_glmer() and rstanarm::stan_glm respectively, which use the same syntax. The huge benefit here is that your uncertainty estimates come from a genuine posterior. Your predictions will also include uncertainty from the parameters. A tip though: make sure you scale your data to be in the single digits.

Be warned that the posterior density of random effects tend to be skewed, so using likelihood-based methods (as in lme4) will tend to give you bad random effect estimates.

3) The loo package allows comparison of your stan_ fits using an approximation to leave-one-out cross validation. I recommend taking a look.

https://cran.r-project.org/web/packages/rstanarm/vignettes/glmer.html

$\endgroup$
5
  • 2
    $\begingroup$ hmm. could you expand on (1) "make sure you scale your data to be in the single digits" (what problems would this cause rstanarm?) and (2) "using likelihood-based methods (as in lme4) will tend to give you bad random effect estimates" ? $\endgroup$
    – Ben Bolker
    Aug 19, 2016 at 21:50
  • $\begingroup$ Thanks for your thoughts Jim. Im quite new to r, and I did get a little lost in your answer. Could you clarify what the rstanarm::stan function does? $\endgroup$ Aug 22, 2016 at 23:18
  • $\begingroup$ Ben - varying intercept/slope models tend to have some crazy looking likelihoods if you have numbers with different orders of magnitude. So it can be helpful to scale - say, within -10 and 10. $\endgroup$
    – Jim
    Aug 24, 2016 at 0:19
  • $\begingroup$ JeanDrayton: the rstanarm package implements the same models in lme4, but estimates them using Bayesian techniques. For varying-intercept/slope models, the main advantage is that you get better estimates of the varying intercepts and slopes. To use them, simply download rstanarm and then replace your call to glmer() with stan_glmer(), and it should work fine. $\endgroup$
    – Jim
    Aug 24, 2016 at 0:21
  • $\begingroup$ Hi @Jim, your answer to this post is very interesting. Just a question, is it possible to relate the resulting parameters that you get from a lmer , let’s say from a treatment response model and kind of associate this to another binary data like yes or no ? I couldn’t find literature that help me with this. Thanks. $\endgroup$
    – Rosa Maria
    Mar 23, 2022 at 8:10

Your Answer

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

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