Description Usage Arguments Details Value See Also Examples
Fit a linear mixedeffects model (LMM) to data, via REML or maximum likelihood.
1 2 3 
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

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
as.formula
or reformulate
); model fits
will work but subsequent methods such as drop1
,
update
may fail.
When handling perfectly collinear predictor variables
(i.e. design matrices of less than full rank),
[gn]lmer
is not quite as sophisticated
as some simpler modeling frameworks such as
lm
and glm
. While it does
automatically drop collinear variables (with a message
rather than a warning), it does not automatically fill
in NA
values for the dropped coefficients;
these can be added via
fixef(fitted.model,add.dropped=TRUE)
.
This information can also be retrieved via
attr(getME(fitted.model,"X"),"col.dropped")
.
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
(more specifically,
an object of subclass lmerMod
), for which many methods
are available (e.g. methods(class="merMod")
)
lm
for linear models;
glmer
for generalized linear; and
nlmer
for nonlinear mixed models.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  ## linear mixed models  reference values from older code
(fm1 < lmer(Reaction ~ Days + (Days  Subject), sleepstudy))
summary(fm1)# (with its own print method; see class?merMod % ./merModclass.Rd
str(terms(fm1))
stopifnot(identical(terms(fm1, fixed.only=FALSE),
terms(model.frame(fm1))))
attr(terms(fm1, FALSE), "dataClasses") # fixed.only=FALSE needed for dataCl.
fm1_ML < update(fm1,REML=FALSE)
(fm2 < lmer(Reaction ~ Days + (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
## Fit sexspecific variances by constructing numeric dummy variables
## for sex and sex:age; in this case the estimated variance differences
## between groups in both intercept and slope are zero ...
data(Orthodont,package="nlme")
Orthodont$nsex < as.numeric(Orthodont$Sex=="Male")
Orthodont$nsexage < with(Orthodont, nsex*age)
lmer(distance ~ age + (ageSubject) + (0+nsexSubject) +
(0 + nsexageSubject), data=Orthodont)

Loading required package: Matrix
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + (Days  Subject)
Data: sleepstudy
REML criterion at convergence: 1743.628
Random effects:
Groups Name Std.Dev. Corr
Subject (Intercept) 24.740
Days 5.922 0.07
Residual 25.592
Number of obs: 180, groups: Subject, 18
Fixed Effects:
(Intercept) Days
251.41 10.47
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + (Days  Subject)
Data: sleepstudy
REML criterion at convergence: 1743.6
Scaled residuals:
Min 1Q Median 3Q Max
3.9536 0.4634 0.0231 0.4634 5.1793
Random effects:
Groups Name Variance Std.Dev. Corr
Subject (Intercept) 612.09 24.740
Days 35.07 5.922 0.07
Residual 654.94 25.592
Number of obs: 180, groups: Subject, 18
Fixed effects:
Estimate Std. Error t value
(Intercept) 251.405 6.825 36.84
Days 10.467 1.546 6.77
Correlation of Fixed Effects:
(Intr)
Days 0.138
Classes 'terms', 'formula' language Reaction ~ Days
.. attr(*, "variables")= language list(Reaction, Days)
.. attr(*, "factors")= int [1:2, 1] 0 1
.. .. attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "Reaction" "Days"
.. .. ..$ : chr "Days"
.. attr(*, "term.labels")= chr "Days"
.. attr(*, "order")= int 1
.. attr(*, "intercept")= int 1
.. attr(*, "response")= int 1
.. attr(*, ".Environment")=<environment: R_GlobalEnv>
.. attr(*, "predvars")= language list(Reaction, Days)
Reaction Days Subject
"numeric" "numeric" "factor"
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + ((1  Subject) + (0 + Days  Subject))
Data: sleepstudy
REML criterion at convergence: 1743.669
Random effects:
Groups Name Std.Dev.
Subject (Intercept) 25.051
Subject.1 Days 5.988
Residual 25.565
Number of obs: 180, groups: Subject, 18
Fixed Effects:
(Intercept) Days
251.41 10.47
refitting model(s) with ML (instead of REML)
Data: sleepstudy
Models:
fm2: Reaction ~ Days + ((1  Subject) + (0 + Days  Subject))
fm1: Reaction ~ Days + (Days  Subject)
Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
fm2 5 1762.0 1778.0 876.00 1752.0
fm1 6 1763.9 1783.1 875.97 1751.9 0.0639 1 0.8004
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + ((1  Subject) + (0 + Days  Subject))
Data: sleepstudy
REML criterion at convergence: 1743.669
Random effects:
Groups Name Variance
Subject (Intercept) 627.5691
Subject.1 Days 35.8582
Residual 653.5838
Number of obs: 180, groups: Subject, 18
Fixed Effects:
(Intercept) Days
251.40510 10.46729
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + ((1  Subject) + (0 + Days  Subject))
Data: sleepstudy
REML criterion at convergence: 1743.7
Scaled residuals:
Min 1Q Median 3Q Max
3.963 0.463 0.020 0.465 5.186
Random effects:
Groups Name Variance Std.Dev.
Subject (Intercept) 627.6 25.05
Subject.1 Days 35.9 5.99
Residual 653.6 25.57
Number of obs: 180, groups: Subject, 18
Fixed effects:
Estimate Std. Error t value
(Intercept) 251.41 6.89 36.5
Days 10.47 1.56 6.7
2 x 2 Matrix of class "dpoMatrix"
(Intercept) Days
(Intercept) 47.408479 1.980557
Days 1.980557 2.432246
2 x 2 Matrix of class "corMatrix"
(Intercept) Days
(Intercept) 1.0000000 0.1844402
Days 0.1844402 1.0000000
Linear mixed model fit by REML ['lmerMod']
Formula: distance ~ age + (age  Subject) + (0 + nsex  Subject) + (0 +
nsexage  Subject)
Data: Orthodont
REML criterion at convergence: 442.6367
Random effects:
Groups Name Std.Dev. Corr
Subject (Intercept) 2.3270
age 0.2264 0.61
Subject.1 nsex 0.0000
Subject.2 nsexage 0.0000
Residual 1.3100
Number of obs: 108, groups: Subject, 27
Fixed Effects:
(Intercept) age
16.7611 0.6602
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.