Fit a linear mixed-effects model (LMM) to data.
lmer(formula, data = NULL, REML = TRUE, control = lmerControl(), start = NULL, verbose = 0L, subset, weights, na.action, offset, contrasts = NULL, devFunOnly = FALSE, ...)
- a two-sided linear formula object describing both the fixed-effects and fixed-effects part of the model, with the response on the left of a
~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.
- an optional data frame containing the variables named in
formula. By default the variables are taken from the environment from which
lmeris called. While
datais optional, the package authors strongly recommend its use, especially when later applying methods such as
drop1to the fitted model (such methods are not guaranteed to work properly if
datais omitted). If
datais 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).
- logical scalar - Should the estimates be chosen to optimize the REML criterion (as opposed to the log-likelihood)?
- a list (of correct class, resulting from
glmerControl()respectively) containing control parameters, including the nonlinear optimizer to be used and parameters to be passed through to the nonlinear optimizer, see the
*lmerControldocumentation for details.
- a named
listof starting values for the parameters in the model. For
lmerthis can be a numeric vector or a list with one component named
- integer scalar. If
> 0verbose output is generated during the optimization of the parameter estimates. If
> 1verbose output is generated during the individual PIRLS steps.
- an optional expression indicating the subset of the rows of
datathat 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.
- an optional vector of ‘prior weights’ to be used in the fitting process. Should be
NULLor a numeric vector.
- a function that indicates what should happen when the data contain
NAs. 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.
- this can be used to specify an a priori known component to be included in the linear predictor during fitting. This should be
NULLor a numeric vector of length equal to the number of cases. One or more
offsetterms can be included in the formula instead or as well, and if more than one is specified their sum is used. See
- an optional list. See the
- 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).
- other potential arguments. A
methodargument was used in earlier versions of the package. Its functionality has been replaced by the
- If the
formulaargument is specified as a character vector, the function will attempt to coerce it to a formula. However, this is not recommended (users who want to construct formulas by pasting together components are advised to use
reformulate); model fits will work but subsequent methods such as
- Unlike some simpler modeling frameworks such as
glmwhich automatically detect perfectly collinear predictor variables,
[gn]lmercannot handle design matrices of less than full rank. For example, in cases of models with interactions that have unobserved combinations of levels, it is up to the user to define a new variable (for example creating
abwithin the data from the results of
- the deviance function returned when
TRUEtakes a single numeric vector argument, representing the
thetavector. This vector defines the scaled variance-covariance matrices of the random effects, in the Cholesky parameterization. For models with only simple (intercept-only) random effects,
thetais a vector of the standard deviations of the random effects. For more complex or multiple random effects, running
getME(.,"theta")to retrieve the
thetavector for a fitted model and examining the names of the vector is probably the easiest way to determine the correspondence between the elements of the
thetavector and elements of the lower triangles of the Cholesky factors of the random effects.
## linear mixed models - reference values from older code (fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)) summary(fm1)# (with its own print method) fm1_ML <- update(fm1,REML=FALSE) (fm2 <- lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject), sleepstudy)) anova(fm1, fm2) sm2 <- summary(fm2) print(fm2, digits=7, ranef.comp="Var") # the print.merMod() method print(sm2, digits=3, corr=FALSE) # the print.summary.merMod() method (vv <- vcov.merMod(fm2, corr=TRUE)) as(vv, "corMatrix")# extracts the ("hidden") 'correlation' entry in @factors
Documentation reproduced from package lme4, version 1.0-6. License: GPL (>= 2)