Package 'lsmeans'

Title: Least-Squares Means
Description: Obtain least-squares means for linear, generalized linear, and mixed models. Compute contrasts or linear functions of least-squares means, and comparisons of slopes. Plots and compact letter displays. Least-squares means were proposed in Harvey, W (1960) "Least-squares analysis of data with unequal subclass numbers", Tech Report ARS-20-8, USDA National Agricultural Library, and discussed further in Searle, Speed, and Milliken (1980) "Population marginal means in the linear model: An alternative to least squares means", The American Statistician 34(4), 216-221 <doi:10.1080/00031305.1980.10483031>. NOTE: lsmeans now relies primarily on code in the 'emmeans' package. 'lsmeans' will be archived in the near future.
Authors: Russell Lenth [aut, cre, cph]
Maintainer: Russell Lenth <[email protected]>
License: GPL-2 | GPL-3
Version: 2.30-1
Built: 2024-11-26 02:50:18 UTC
Source: https://github.com/rvlenth/lsmeans

Help Index


Least-squares means

Description

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.

Almost the entire codebase for lsmeans now resides in the emmeans package (named for the more general term, “estimated marginal means”). lsmeans exists only as a transitional entity for the few remaining packages that depend on it.

Author(s)

Russell V. Lenth (author), Maxime Hervé (contributor)

Maintainer: Russ Lenth <[email protected]>

References

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.


Data sets

Description

The datasets ‘auto.noise’, ‘feedlot’, ‘fiber’, ‘MOats’, ‘nutrition’, and ‘oranges’ are provided in case a user customarily loads the data from lsmeans. But the same datasets are provided in the emmeans package, and they are documented there.

Usage

auto.noise

Author(s)

Russell V. Lenth


Create a reference grid from a fitted model

Description

These functions are provided in lsmeans because they have been renamed in emmeans

Usage

ref.grid(object, ...)
    
recover.data(object, ...)
lsm.basis(object, ...)

Arguments

object

A model object in a supported class.

...

Additional arguments passed to companion functions in the emmeans package.

Value

lsmeans now passes all its computations to emmeans, and the return values are thus what is returned by the corresponding functions ref_grid, recover_data, and emm_basis, respectively.

Author(s)

Russell V. Lenth

Examples

fiber.lm <- lm(strength ~ machine + diameter, data = fiber)
  rg <- ref.grid(fiber.lm, at = list(diameter = c(20, 24, 28)))
  rg
  
  # Note this is an emmGrid object defined in emmeans. The old "ref.grid"
  # class is now an extension of this:
  r.g. <- new("ref.grid", rg)
  lsmeans(r.g., "machine")

The ref.grid and lsmobj classes

Description

The codebase for lsmeans is now mostly in emmeans. These two classes are simple extensions of the emmGrid class defined in emmeans, and are provided as support for objects created in older versions of lsmeans. For details, see emmGrid-class.

Author(s)

Russell V. Lenth


Transition to emmeans

Description

The lsmeans package is being deprecated and further development will take place in its successor, emmeans. Users may use emmeans in almost exactly the same way as lsmeans, but a few function names and internal details are changed.

Details

In transitioning to emmeans, users will find that the vignettes are constructed quite differently and that, in those and in the documentation, emphasis is placed on “estimated marginal means” rather than “least-squares means”. The term “estimated marginal means” is broader and more appropriate for use with some models, e.g. ordinal regression, that don't really involve least-squares methods. That is the reason for the change.

Accordingly, emmeans users are encouraged to use the functions emmeans(), emtrends(), emmip(), etc. in lieu of lsmeans(), etc. The latter functions are still available in emmeans; they run the corresponding emmxxxx function and relabel the results.

The emmeans package provides some functions that help convert scripts and R Markdown files containing lsmeans code so they will work in emmeans. There is also a function to convert ref.grid and lsmobj objects to the emmGrid objects used in emmeans. More extensive information is given in vignette("transition-from-lsmeans", package = "emmeans").

Author(s)

Russell V. Lenth