lmer {lme4}  R Documentation 
Fit a linear mixedeffects 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, ...)
formula 
a twosided linear formula object
describing both the fixedeffects and fixedeffects part
of the model, with the response on the left of a 
data 
an optional data frame containing the
variables named in 
REML 
logical scalar  Should the estimates be chosen to optimize the REML criterion (as opposed to the loglikelihood)? 
control 
a list (of correct class, resulting from

start 
a named 
verbose 
integer scalar. If 
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

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). 
... 
other potential arguments. A 
If the formula
argument 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
update
may fail.
Unlike some simpler modeling frameworks such as
glm
which
automatically detect perfectly collinear predictor
variables, [gn]lmer
cannot 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 ab
within the data from the
results of interaction(a,b,drop=TRUE)
).
the deviance function returned when
devFunOnly
is TRUE
takes a single numeric
vector argument, representing the theta
vector.
This vector defines the scaled variancecovariance
matrices of the random effects, in the Cholesky
parameterization. For models with only simple
(interceptonly) random effects, theta
is a vector
of the standard deviations of the random effects. For
more complex or multiple random effects, running
getME(.,"theta")
to retrieve the theta
vector 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 theta
vector and elements of the lower triangles of the
Cholesky factors of the random effects.
An object of class merMod
, for which many methods
are available (e.g. methods(class="merMod")
)
## 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 + (1Subject) + (0+DaysSubject), 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