glmer  R Documentation 
Fit a generalized linear mixedeffects model (GLMM). Both fixed
effects and random effects are specified via the model formula
.
glmer(formula, data = NULL, family = gaussian , control = glmerControl() , start = NULL , verbose = 0L , nAGQ = 1L , subset, weights, na.action, offset, contrasts = NULL , mustart, etastart , devFunOnly = FALSE)
formula 
a twosided linear formula object describing both the
fixedeffects and randomeffects part of the model, with the response
on the left of a 
data 
an optional data frame containing the variables named in

family 
a GLM family, see 
control 
a list (of correct class, resulting from

start 
a named list of starting values for the parameters in the
model, or a numeric vector. A numeric 
verbose 
integer scalar. If 
nAGQ 
integer scalar  the number of points per axis for evaluating the adaptive GaussHermite approximation to the loglikelihood. Defaults to 1, corresponding to the Laplace approximation. Values greater than 1 produce greater accuracy in the evaluation of the loglikelihood at the expense of speed. A value of zero uses a faster but less exact form of parameter estimation for GLMMs by optimizing the random effects and the fixedeffects coefficients in the penalized iteratively reweighted least squares step. (See Details.) 
subset 
an optional expression indicating the subset of the rows
of 
weights 
an optional vector of ‘prior weights’ to be used
in the fitting process. Should be 
na.action 
a function that indicates what should happen when the
data contain 
offset 
this can be used to specify an a priori known
component to be included in the linear predictor during
fitting. This should be 
contrasts 
an optional list. See the 
mustart 
optional starting values on the scale of the
conditional mean, as in 
etastart 
optional starting values on the scale of the unbounded
predictor as in 
devFunOnly 
logical  return only the deviance evaluation function. Note that because the deviance function operates on variables stored in its environment, it may not return exactly the same values on subsequent calls (but the results should always be within machine tolerance). 
Fit a generalized linear mixed model, which incorporates both
fixedeffects parameters and random effects in a linear predictor, via
maximum likelihood. The linear predictor is related to the
conditional mean of the response through the inverse link function
defined in the GLM family
.
The expression for the likelihood of a mixedeffects model is an
integral over the random effects space. For a linear mixedeffects
model (LMM), as fit by lmer
, this integral can be
evaluated exactly. For a GLMM the integral must be approximated. The
most reliable approximation for GLMMs
is adaptive GaussHermite quadrature,
at present implemented only for models with
a single scalar random effect. The
nAGQ
argument controls the number of nodes in the quadrature
formula. A model with a single, scalar randomeffects term could
reasonably use up to 25 quadrature points per scalar integral.
An object of class merMod
(more specifically,
an object of subclass glmerMod
) for which many
methods are available (e.g. methods(class="merMod")
)
In earlier version of the lme4 package, a method
argument was
used. Its functionality has been replaced by the nAGQ
argument.
lmer
(for details on formulas and
parameterization); glm
for Generalized Linear
Models (without random effects).
nlmer
for nonlinear mixedeffects models.
glmer.nb
to fit negative binomial GLMMs.
## generalized linear mixed model library(lattice) xyplot(incidence/size ~ periodherd, cbpp, type=c('g','p','l'), layout=c(3,5), index.cond = function(x,y)max(y)) (gm1 < glmer(cbind(incidence, size  incidence) ~ period + (1  herd), data = cbpp, family = binomial)) ## using nAGQ=0 only gets close to the optimum (gm1a < glmer(cbind(incidence, size  incidence) ~ period + (1  herd), cbpp, binomial, nAGQ = 0)) ## using nAGQ = 9 provides a better evaluation of the deviance ## Currently the internal calculations use the sum of deviance residuals, ## which is not directly comparable with the nAGQ=0 or nAGQ=1 result. ## 'verbose = 1' monitors iteratin a bit; (verbose = 2 does more): (gm1a < glmer(cbind(incidence, size  incidence) ~ period + (1  herd), cbpp, binomial, verbose = 1, nAGQ = 9)) ## GLMM with individuallevel variability (accounting for overdispersion) ## For this data set the model is the same as one allowing for a period:herd ## interaction, which the plot indicates could be needed. cbpp$obs < 1:nrow(cbpp) (gm2 < glmer(cbind(incidence, size  incidence) ~ period + (1  herd) + (1obs), family = binomial, data = cbpp)) anova(gm1,gm2) ## glmer and glm loglikelihoods are consistent gm1Devfun < update(gm1,devFunOnly=TRUE) gm0 < glm(cbind(incidence, size  incidence) ~ period, family = binomial, data = cbpp) ## evaluate GLMM deviance at RE variance=theta=0, beta=(GLM coeffs) gm1Dev0 < gm1Devfun(c(0,coef(gm0))) ## compare stopifnot(all.equal(gm1Dev0,c(2*logLik(gm0)))) ## the toenail oncholysis data from Backer et al 1998 ## these data are notoriously difficult to fit ## Not run: if (require("HSAUR3")) { gm2 < glmer(outcome~treatment*visit+(1patientID), data=toenail, family=binomial,nAGQ=20) } ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.