Rev 3365 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{lmer}\docType{genericFunction}\alias{lmer}\alias{lmer,formula-method}\concept{GLMM}% << so it's found\title{Fit (Generalized) Linear Mixed-Effects Models}\description{This generic function fits a linear mixed-effects model with nested orcrossed grouping factors for the random effects.}\usage{lmer(formula, data, family, method, control, start,subset, weights, na.action, offset, contrasts,model, \dots)\S4method{lmer}{formula}(formula, data, family, method,control, start, subset, weights, na.action, offset, contrasts,model, \dots)}\arguments{\item{formula}{a two-sided linear formula object describing thefixed-effects part of the model, with the response on the left of a\code{~} operator and the terms, separated by \code{+} operators, onthe right. The vertical bar character \code{"|"} separates anexpression for a model matrix and a grouping factor.}\item{data}{an optional data frame containing the variables named in\code{formula}. By default the variables are taken from theenvironment from which \code{lmer} is called.}\item{family}{a GLM family, see \code{\link[stats]{glm}}. If \code{family} ismissing then a linear mixed model is fit; otherwise a generalizedlinear mixed model is fit.}\item{method}{a character string. For a linear mixed model thedefault is \code{"REML"} indicating that the model should be fit bymaximizing the restricted log-likelihood. The alternative is\code{"ML"} indicating that the log-likelihood should bemaximized. (This method is sometimes called "full" maximumlikelihood.) For a generalized linear mixed model the criterionis always the log-likelihood but this criterion does not have aclosed form expression and must be approximated. The default approximation is\code{"PQL"} or penalized quasi-likelihood. Alternatives are\code{"Laplace"} or \code{"AGQ"} indicating the Laplacian andadaptive Gaussian quadrature approximations respectively. The\code{"PQL"} method is fastest but least accurate. The\code{"Laplace"} method is intermediate in speed and accuracy.The \code{"AGQ"} method is the most accurate but can beconsiderably slower than the others.}\item{control}{a list of control parameters. See below for details.}\item{start}{a list of relative precision matrices for the randomeffects. This has the same form as the slot \code{"Omega"} in afitted model. Only the upper triangle of these symmetric matricesshould be stored.}\item{subset, weights, na.action, offset, contrasts}{further modelspecification arguments as in \code{\link[stats]{lm}}; see there fordetails.}\item{model}{logical indicating if the model componentshould be returned (in slot \code{frame}).}\item{\dots}{potentially further arguments for methods. Currentlynone are used.}}}\details{This is a revised version of the \code{\link[nlme]{lme}} function from the\pkg{nlme} package. This version uses a different method ofspecifying random-effects terms and allows for fitting generalizedlinear mixed models as well as linear mixed models.Additional standard arguments to model-fitting functions can be passedto \code{lmer}.\describe{\item{subset}{an optional expression indicating the subset of the rows of\code{data} that should be used in the fit. This can be a logicalvector, or a numeric vector indicating which observation numbers areto be included, or a character vector of the row names to beincluded. All observations are included by default.}\item{na.action}{a function that indicates what should happen when thedata contain \code{NA}s. The default action (\code{na.fail}) causes\code{lme} to print an error message and terminate if there are anyincomplete observations.}\item{control}{a named list of control parameters for the estimationalgorithm, specifying only the ones to be changed from theirdefault values. Hence defaults to an empty list.\crPossible control options and their default values are:\describe{\item{\code{maxIter}:}{maximum number of iterations for the \code{lme}optimization algorithm. Default is 50.}\item{\code{tolerance}:}{relative convergence tolerance for the\code{lme} optimization algorithm. Default is\code{sqrt(.Machine$double.eps)}.}\item{\code{msMaxIter}:}{maximum number of iterationsfor the \code{nlminb} optimization step inside the \code{lme}optimization. Default is 200.}\item{\code{msVerbose}:}{a logical value passed as the\code{trace} argument to \code{nlminb} (see documentation onthat function). Default is \code{getOption("verbose")}.}\item{\code{niterEM}:}{number of iterations for the EM algorithmused to refine the initial estimates of the random effectsvariance-covariance coefficients. Default is 15.}\item{\code{EMverbose}:}{a logical value indicating if verbose outputshould be produced during the EM iterations. Default is\code{getOption("verbose")}.}\item{\code{PQLmaxIt}:}{maximum number of iterations for the PQLalgorithm when fitting generalized linear mixed models.Default is 30.}%% unused currently?\item{\code{usePQL}:}{Should the PQL method be used beforeswitching to general optimization when fitting generalized linear mixedmodels using \code{method = "Laplace"}? Default is \code{TRUE}.}\item{\code{gradient}:}{a logical value indicating if theanalytic gradient of the objective should be used. Use of ananalytic gradient results in more stable convergence but can takelonger. For models with multiple grouping factors thedifference in time can be substantial.Default is \code{TRUE}.}\item{\code{Hessian}:}{a logical value indicating if theanalytic Hessian of the objective should be calculated. Thisis an experimental feature and at present the default is\code{FALSE}. In the future we may use the analytic Hessian inthe optimization.}}}\item{model, x}{logicals. If \code{TRUE} the correspondingcomponents of the fit (the model frame, the model matrices)are returned.}}}\value{An object of class \code{"\linkS4class{lmer}"}.There are many methods applicable to \code{"lmer"} objects, see theabove help page. %% Hmm.. or \code{\link{showMethods}(class = "lmer")}}%\references{ ~put references to the literature/web site here ~ }%\author{}%\note{}\seealso{\code{\link[Matrix]{lmer-class}}, \code{\link[stats]{lm}}}\examples{data(sleepstudy)(fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy))(fm2 <- lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject), sleepstudy))anova(fm1, fm2)}\keyword{models}\keyword{methods}