This package provides methods for obtaining so-called least-squares means for factor combinations in a variety of fitted linear models. It can also compute contrasts or linear combinations of these least-squares means, (several standard contrast families are provided), and in addition can estimate and contrast slopes of trend lines. Popular adjustments for multiple-comparisons are provided, as well as graphical ways of displaying the results.
Least-squares means (see Searle et al. 1980, who prefer the term “predicted marginal means” (PMM)) are popular for summarizing linear models that include factors. For balanced experimental designs, they are just the marginal means. For unbalanced data, they in essence estimate what you would have observed that the data arisen from a balanced experiment.
The implementation in lsmeans relies on our own concept of a reference grid, which is an array of factor and predictor levels.
Predictions are made on this grid, and least-squares means are defined as averages of these predictions over zero or more dimensions of the grid. The function ref.grid
explicitly creates a reference grid (ref.grid
object) that can subsequently be used to obtain least-squares means. The update
method is used to change its properties.
Our reference-grid framework expands slightly upon Searle et al.'s definitions of PMMs, in that it is possible to include multiple levels of covariates in the grid.
Many linear models are supported by the package, including lm
, glm
, aovList
, and mlm
in the stats package, as well as fitted-model objects from several contributed packages including nlme, lme4, survival, and geepack. The help page for models
provides more details, including, in some cases, additional ref.grid
arguments that might affect the subsequent analysis. Also, some models require other packages be installed in order to obtain all the available features.
The lsmeans
function computes least-squares means given a ref.grid
object or a fitted model, and a specification indicating what factors to include. The lstrends
function creates the same sort of results for estimating and comparing slopes of fitted lines. Both return an lsmobj
object very much like a reference grid, but with possibly fewer factors involved.
The summary
method may be used to display a ref.grid
or an lsmobj
. Special-purpose summaries are available via confint
and test
, the latter of which can also do a joint test of several estimates. The user may specify by variables, multiplicity-adjustment methods, confidence levels, etc., and if a transformation or link function is involved, may reverse-transform the results to the response scale.
The contrast
method is used to obtain contrasts among the estimates; several standard contrast families are available such as deviations from the mean, polynomial contrasts, and comparisons with one or more controls. Another lsmobj
object is returned, which can be summarized or further analyzed. For convenience, a pairs
method is provided for the case of pairwise comparisons. Related to this is the cld
method, which provides a compact letter display for grouping pairs of means that are not significantly different. cld
requires the multcompView package.
The plot
method will display side-by-side confidence intervals for the estimates, and/or ‘comparison arrows’ whereby the significance of pairwise differences can be judged by how much they overlap. The lsmip
function displays estimates like an interaction plot, multi-paneled if there are by variables. These graphics capabilities require the lattice package be installed.
The as.glht
function and glht
method for lsmobj
s provide an interface to the glht
function in the multcomp package, thus providing for more exacting simultaneous estimation or testing. The package also provides an lsm
method that works as an alternative to mcp
in a call to glht
.
Examples and discussion are available via vignette("using-lsmeans", package="lsmeans")
.
Some features of the lsmeans require (or are enhanced by) additional packages that are loaded when needed. Since they are not “required” packages, they are not automatically installed with lsmeans. We highly recommend that users also install the following packages: multcomp (if cld
, glht
, or as.glht
are to be used), multcompView (for cld
), lattice (for plot
and lsmip
), and lmerTest or pbkrtest (for models fitted by the lme4 package).
Starting with lsmeans version 2, a new object framework based on reference grids is used that increases flexibility and provides for extending its capabilities to additional model objects. Use vignette("lsmeans-changes")
for information on the user impact of these changes.
It is possible to write your own interfaces for models not yet supported by lsmeans. See the help page extending-lsmeans
and vignette("extending")
for details on how to do this.
Package: | lsmeans |
Type: | Package |
License: | GPL-2 |
Other information: | See DESCRIPTION |
Russell V. Lenth (2016) Least-Squares Means: The R Package lsmeans. Journal of Statistical Software, 69(1), 1-33. doi:10.18637/jss.v069.i01
Searle S.R. Speed F.M. Milliken G.A. (1980) Population marginal means in the linear model: An alternative to least squares means. The American Statistician 34(4), 216-221.