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, …)
~
operator and the terms, separated by
+
operators, on the right. Random-effects terms are
distinguished by vertical bars ("|"
) separating expressions
for design matrices from grouping factors.formula
. By default the variables are taken from the
environment from which lmer
is called. While data
is
optional, the package authors strongly recommend its use,
especially when later applying methods such as update
and
drop1
to the fitted model (such methods are not
guaranteed to work properly if data
is omitted). If
data
is omitted, variables will be taken from the environment
of formula
(if specified as a formula) or from the parent
frame (if specified as a character vector).lmerControl()
or glmerControl()
respectively) containing control parameters, including the nonlinear
optimizer to be used and parameters to be passed through to the
nonlinear optimizer, see the *lmerControl
documentation for
details.start
argument will be
used as the starting value of theta
. If start
is a
list, the theta
element (a numeric vector) is used as the
starting value for the first optimization step (default=1 for
diagonal elements and 0 for off-diagonal elements of the lower
Cholesky factor); the fitted value of theta
from the first
step, plus start[["fixef"]]
, are used as starting values for
the second optimization step. If start
has both fixef
and theta
elements, the first optimization step is skipped.
For more details or finer control of optimization, see
modular
.> 0
verbose output is
generated during the optimization of the parameter estimates. If
> 1
verbose output is generated during the individual PIRLS
steps.data
that should be used in the fit. This can be a logical
vector, or a numeric vector indicating which observation numbers are
to be included, or a character vector of the row names to be
included. All observations are included by default.NULL
or a numeric
vector.NA
s. The default action (na.omit
,
inherited from the ‘factory fresh’ value of
getOption("na.action")
) strips any observations with any
missing values in any variables.NULL
or a numeric vector of length
equal to the number of cases. One or more offset
terms can be included in the formula instead or as well, and if more
than one is specified their sum is used. See model.offset
.contrasts.arg
of
model.matrix.default
.glm
; see there for
details.glm
; see there for details.method
argument was
used in earlier versions of the package. Its functionality has been
replaced by the nAGQ
argument.merMod
(more specifically,
an object of subclass glmerMod
) for which many
methods are available (e.g. methods(class="merMod")
)family
. The expression for the likelihood of a mixed-effects model is an
integral over the random effects space. For a linear mixed-effects
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 Gauss-Hermite 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 random-effects term could
reasonably use up to 25 quadrature points per scalar integral.
lmer
(for details on formulas and
parameterization); glm
for Generalized Linear
Models (without random effects).
nlmer
for nonlinear mixed-effects models. glmer.nb
to fit negative binomial GLMMs.## generalized linear mixed model library(lattice) xyplot(incidence/size ~ period|herd, 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. (gm1a <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), cbpp, binomial, nAGQ = 9)) ## GLMM with individual-level 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) + (1|obs), family = binomial, data = cbpp)) anova(gm1,gm2) ## glmer and glm log-likelihoods 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("HSAUR2")) { # gm2 <- glmer(outcome~treatment*visit+(1|patientID), # data=toenail, # family=binomial,nAGQ=20) # } ## ---------------------------------------------
Run the code above in your browser using DataCamp Workspace