Computes LS-means or pairwise differences of LS-mean for all factors in a
linear mixed model. lsmeansLT is provided as an alias for
ls_means for backward compatibility.
# S3 method for class 'lmerModLmerTest'
ls_means(
model,
which = NULL,
level = 0.95,
ddf = c("Satterthwaite", "Kenward-Roger"),
pairwise = FALSE,
...
)
# S3 method for class 'lmerModLmerTest'
lsmeansLT(
model,
which = NULL,
level = 0.95,
ddf = c("Satterthwaite", "Kenward-Roger"),
pairwise = FALSE,
...
)
# S3 method for class 'lmerModLmerTest'
difflsmeans(
model,
which = NULL,
level = 0.95,
ddf = c("Satterthwaite", "Kenward-Roger"),
...
)a model object fitted with lmer (of class
"lmerModLmerTest").
optional character vector naming factors for which LS-means should
be computed. If NULL (default) LS-means for all factors are computed.
confidence level.
method for computation of denominator degrees of freedom.
compute pairwise differences of LS-means instead?
currently not used.
An LS-means table in the form of a data.frame. Formally an object
of class c("ls_means", "data.frame") with a number of attributes set.
Confidence intervals and p-values are based on the t-distribution using degrees of freedom based on Satterthwaites or Kenward-Roger methods.
LS-means is SAS terminology for predicted/estimated marginal means, i.e. means for levels of factors which are averaged over the levels of other factors in the model. A flat (i.e. unweighted) average is taken which gives equal weight to all levels of each of the other factors. Numeric/continuous variables are set at their mean values. See emmeans package for more options and greater flexibility.
LS-means contrasts are checked for estimability and unestimable contrasts appear
as NAs in the resulting table.
LS-means objects (of class "ls_means" have a print method).
show_tests for display of the
underlying LS-means contrasts.
# Get data and fit model:
data("cake", package="lme4")
model <- lmer(angle ~ recipe * temp + (1|recipe:replicate), cake)
# Compute LS-means:
ls_means(model)
#> Least Squares Means table:
#>
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> recipeA 33.1222 1.7368 42 19.070 29.6172 36.6273 < 2.2e-16 ***
#> recipeB 31.6444 1.7368 42 18.220 28.1394 35.1495 < 2.2e-16 ***
#> recipeC 31.6000 1.7368 42 18.194 28.0949 35.1051 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Confidence level: 95%
#> Degrees of freedom method: Satterthwaite
# Get LS-means contrasts:
show_tests(ls_means(model))
#> $recipe
#> (Intercept) recipeB recipeC temp recipeB:temp recipeC:temp
#> recipeA 1 0 0 200 0 0
#> recipeB 1 1 0 200 200 0
#> recipeC 1 0 1 200 0 200
#>
# Compute pairwise differences of LS-means for each factor:
ls_means(model, pairwise=TRUE)
#> Least Squares Means table:
#>
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> recipeA - recipeB 1.477778 2.456253 42 0.6016 -3.479142 6.434698 0.5506
#> recipeA - recipeC 1.522222 2.456253 42 0.6197 -3.434698 6.479142 0.5388
#> recipeB - recipeC 0.044444 2.456253 42 0.0181 -4.912476 5.001364 0.9856
#>
#> Confidence level: 95%
#> Degrees of freedom method: Satterthwaite
difflsmeans(model) # Equivalent.
#> Least Squares Means table:
#>
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> recipeA - recipeB 1.477778 2.456253 42 0.6016 -3.479142 6.434698 0.5506
#> recipeA - recipeC 1.522222 2.456253 42 0.6197 -3.434698 6.479142 0.5388
#> recipeB - recipeC 0.044444 2.456253 42 0.0181 -4.912476 5.001364 0.9856
#>
#> Confidence level: 95%
#> Degrees of freedom method: Satterthwaite