lsmean: Least Squares Means

Description Usage Arguments Value See Also Examples

Description

Caution: This routine is not fully tested for models with nested factors or mixed models. Please check results against another package (e.g. SAS proc mixed). It appears to correctly handle lme objects, but does not work well for aov objects that include Error() type nesting in the formula. Further, it does not properly handle polynomial terms–only the linear term is included. For now, create dummies like x2 = x*x manually and include x2 in your model.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
lsmean(object, ...)
## Default S3 method:
lsmean(object, ..., factors, effects = FALSE, se.fit = TRUE,
   adjust.covar = TRUE)
## S3 method for class 'lm'
lsmean(object, data, factors, expr, contrast, effects = FALSE,
   se.fit = TRUE, adjust.covar = TRUE, pdiff = FALSE, reorder = FALSE,
   lsd, level = .05, rdf, coef, cov, ...)
## S3 method for class 'lme'
lsmean(object, data, factors, ..., rdf, coef, cov)
## S3 method for class 'lmer'
lsmean(object, data, factors, expr, ..., rdf, coef, cov)
## S3 method for class 'listof'
lsmean(object, data, factors, stratum, expr, contrast, ...)

Arguments

object

response vector (default) or model object (lm).

...

factors and covariates (must be same length as y).

data

data frame in which to interpret variables(found from object if missing).

factors

character vector containing names of x.factor and trace.factoras first two entries. Must be in names(data) and labels(object).Default is all factor names.

effects

drop intercept if TRUE (only works properly with sum-to-zero contrasts).

se.fit

compute pointwise standard errors if T.

adjust.covar

adjust means to average covariate values if T; otherwise use covariate mean for each combination of factors.

pdiff

Include letters to signify significant differences.

reorder

Reorder means from largest to smallest.

lsd

Include average LSD if TRUE (also need pdiff=TRUE).

level

Significance level for pdiff calculations.

rdf

Residual degrees of freedom.

coef

Coefficients for fixed effects in object.

cov

Covariance matrix for fixed effects.

expr

Call expression (formula)

contrast

Type of contrasts (default is attribute contrasts of object)

stratum

Name of stratum for lsmean calculation as character string.

Value

Data frame containing unique factor levels of factors, predicted response (pred) and standard errors (se). WARNING: lsmean may not function properly if there are empty cells. Standard errors for mixed models using methods lmer and listof are not fully debugged.

See Also

predict.

Examples

1
2
3
4
5
6
7
8
## Not run: 
lsmean(y,x1,x2)
# the following does the same thing
fit <- lm(y~x1+x2)
data <- data.frame(y,x1,x2)
lsmean(fit,data,factors=c("x1","x2")

## End(Not run)

byandell/pda documentation built on May 13, 2019, 9:27 a.m.