4
$\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$
9
$\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$
  • 1
    $\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 '16 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$ – JeanDrayton Aug 22 '16 at 5:48
0
$\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$
  • 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 '16 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$ – JeanDrayton Aug 22 '16 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 '16 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 '16 at 0:21

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.