Skip to contents

Fits a binomial or Poisson GLMM with lme4-style random effects by the Laplace approximation (nAGQ = 1), computed by penalised iteratively reweighted least squares (PIRLS). As lme4::glmer does, a first stage optimises the covariance parameters with the fixed effects inside PIRLS (nAGQ = 0); the second stage optimises covariance parameters and fixed effects jointly. The same structured algebra as morie_lmm is used inside every PIRLS step, so nothing of size \(n \times n\) is formed.

Usage

morie_glmm(
  formula,
  data,
  family = c("binomial", "poisson"),
  random = NULL,
  weights = NULL,
  offset = NULL,
  nAGQ = 1L,
  vcov_method = c("hessian", "RX"),
  control = list(),
  ...
)

Arguments

formula

A two-sided formula with lme4-style random terms. A binomial response may be 0/1, a factor (first level = failure), logical, a proportion with weights giving the trials, or cbind(successes, failures).

data

A data frame.

family

"binomial" (logit) or "poisson" (log), or a stats::family object of either (other links allowed).

random

Optional nlme-style random effects (see morie_lmm).

weights

Optional prior weights (binomial: number of trials).

offset

Optional offset.

nAGQ

1 (Laplace, default) or 0 (stage 1 only, as glmer).

vcov_method

"hessian" (default, lme4's default: inverse finite-difference Hessian of the deviance over theta and beta) or "RX" (the PIRLS solution, use.hessian = FALSE in lme4). Both are returned.

control

Optional list passed to stats::nlminb.

...

Ignored.

Value

An object of class c("morie_glmm", "morie_lmm") with the components of morie_lmm (sigma is 1; the table has z values and normal p-values), plus family, vcov_RX, vcov_hessian, mu and eta. fitted is the conditional mean; residuals are deviance residuals.

References

Bates, D., Maechler, M., Bolker, B. and Walker, S. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software, 67(1), 1-48.

Examples

set.seed(2)
d <- data.frame(g = factor(rep(1:30, each = 10)), x = rnorm(300))
d$y <- rbinom(300, 1, plogis(-0.5 + d$x + rnorm(30)[d$g]))
morie_glmm(y ~ x + (1 | g), d, family = "binomial")
#> Generalized linear mixed model fit by maximum likelihood (Laplace) [binomial, logit link]
#> Formula: y ~ x + (1 | g) 
#>       AIC       BIC    logLik  deviance 
#>  350.5566  361.6679 -172.2783  344.5566 
#> 
#> Random effects:
#>  Groups        Name Variance Std.Dev.
#>       g (Intercept)   1.0095   1.0047
#> Number of obs: 300, groups: g, 30
#> 
#> Fixed effects:
#>             Estimate Std.Error  z value   Pr(>|z|)
#> (Intercept) -0.19095   0.23101 -0.82662 4.0845e-01
#> x            1.03340   0.16554  6.24220 4.3155e-10