LSM: Least Squares Means

View source: R/LSM.R

LSMR Documentation

Least Squares Means

Description

Estimates least squares means using the g2 inverse.

Usage

  LSM(Formula, Data, Term, conf.level=0.95, adj="lsd", hideNonEst=TRUE, 
      PLOT=FALSE, descend=FALSE, ...)

Arguments

Formula

a conventional formula for a linear model

Data

a data.frame to be analyzed

Term

a term name to be returned. If there is only one independent variable, this can be omitted.

conf.level

confidence level for the confidence limit

adj

adjustment method for grouping; "lsd" (default), "tukey", "bon", "duncan", and "scheffe" are available. This does not affect the SE, Lower CL, and Upper CL of the output table.

hideNonEst

logical. whether to hide non-estimable values

PLOT

logical. whether to plot LSMs and their confidence intervals

descend

logical. This specifies whether the plotting order is ascending or descending.

...

arguments to be passed to plot

Details

It is equivalent to the LSMEANS statement of SAS PROC GLM. The result of the second example below may be different from emmeans. This is because SAS and this function calculate the mean of the transformed continuous variable. However, emmeans calculates the average before the transformation. An interaction of three variables is not supported yet. For the "dunnett" adjustment method, see the PDIFF function.

Value

Returns a table of expectations, t values and p-values.

Group

group character. This appears when the model is one-way ANOVA or when the Term or adj argument is provided.

LSmean

point estimate of the least squares mean

LowerCL

lower confidence limit at the given confidence level by the "lsd" method

UpperCL

upper confidence limit at the given confidence level by the "lsd" method

SE

standard error of the point estimate

Df

degrees of freedom of the point estimate

Author(s)

Kyun-Seop Bae k@acr.kr

See Also

PDIFF, Diffogram

Examples

  LSM(uptake ~ Type, CO2[-1,])
  LSM(uptake ~ Type - 1, CO2[-1,])
  LSM(uptake ~ Type*Treatment + conc, CO2[-1,])
  LSM(uptake ~ Type*Treatment + conc - 1, CO2[-1,])
  LSM(log(uptake) ~ Type*Treatment + log(conc), CO2[-1,])
  LSM(log(uptake) ~ Type*Treatment + log(conc) - 1, CO2[-1,])
  LSM(log(uptake) ~ Type*Treatment + as.factor(conc), CO2[-1,])
  LSM(log(uptake) ~ Type*Treatment + as.factor(conc) - 1, CO2[-1,])
  LSM(log(CMAX) ~ SEQ/SUBJ + PRD + TRT, BEdata)
  LSM(log(CMAX) ~ SEQ/SUBJ + PRD + TRT - 1, BEdata)

sasLM documentation built on June 15, 2026, 9:07 a.m.