Learn R Programming

lsmeans (version 2.12)

contrast: Methods for obtaining analyses ref.grid and lsmobj objects

Description

These methods provide for analyses of ref.grid objects, or follow-up analyses of lsmobj objects: Contrasts, pairwise comparisons, tests, and confidence intervals.

Usage

## S3 method for class 'ref.grid':
contrast(object, method = "eff", by, adjust, 
    options = getOption("lsmeans")$contrast, ...)
## S3 method for class 'lsm.list':
contrast(object, ..., which = 1)

## S3 method for class 'ref.grid':
test(object, parm = 0, joint = FALSE,
    verbose = FALSE, rows, ...)

## S3 method for class 'ref.grid':
confint(object, parm, level = 0.95, ...)

## S3 method for class 'ref.grid':
pairs(x, ...)

Arguments

object, x
An object of class "ref.grid" or its extension, "lsmobj".
method
Character value giving the root name of a contast method (e.g. "pairwise"). Alternatively, a named list of contrast coefficients that must each conform to the number of least-squares means in each by group. This is just like the
by
Character names of variable(s) to be used for ``by'' groups. The contrasts will be evaluated separately for each combination of these variables. If object was created with by groups, those are used unless overridden. Use by = NULL
adjust
Method to use for adjusting P values. This is passed to summary.
options
If non-NULL, a named list of arguments to pass to update, just after the object is constructed.
joint
Logical value. If FALSE, the arguments are passed to summary with infer=c(FALSE,TRUE). If TRUE, a joint test of the hypothesis L beta = parm is performed, where L is <
rows
Integer values. The rows of L to be tested in the joint test. If missing, all rows of L are used.
parm
This is a required argument for the generic confint) and test methods. In test, when joint is TRUE, it specifies the hypothesized values of the linea
verbose
Logical value. If TRUE and joint==TRUE, a table of the effects being tested is printed.
level
Numeric value of the desired confidence level.
...
Additional arguments passed to summary or to a contrast function.
which
When object is a list of lsmobj objects, this specifies which member of the list is analyzed.

Value

  • contrast and pairs return an object of class "lsmobj", which is an extension of "ref.grid". Consequently, they may be used as arguments to other "lsmobj" or "ref.grid" methods. The user may, for example, compute contrasts of contrasts, or re-summarize a set of confidence intervals with a different by grouping or confidence level. The ``grid'' for the returned value is simply the set of variables that identify the results. For example, contrast's return value is a reference grid for one factor named contrast. confint and test (when Joint==FALSE) return an object of class summary.ref.grid. When JOINT==TRUE, test returns a numeric vector with the test statistic, degrees of freedom, and P value.

Details

pairs is equivalent to contrast with method = "pairwise". confint and test (when JOINT==FALSE) are equivalent to calling summary with infer=c(TRUE,FALSE) and infer=c(FALSE,TRUE), respectively. When using test to do a joint test of L beta = parm, an error is thrown if any row of L is non-estimable. It is permissible for the rows of L to be linearly dependent as long as parm == 0; a reduced set of contrasts is tested. Linear dependence and nonzero parm cause an error.

See Also

Additional "lsmobj" methods having their own help pages are cld and glht. Also, the summary and other methods for "ref.grid" objects also work for "lsmobj" objects.

Examples

Run this code
require(lsmeans)
warp.lm <- lm(breaks ~ wool*tension, data = warpbreaks)
warp.lsm <- lsmeans(warp.lm, ~ tension | wool)

# Polynomial contrasts of tension, by wool
(warp.pl <- contrast(warp.lsm, "poly"))
# Same results with a different adjustment
summary(warp.pl, adjust = "fdr")

# Jointly test the tension effects for each wool
test(warp.pl, joint = TRUE, rows = 1:2)  # wool A
test(warp.pl, joint = TRUE, rows = 3:4)  # wool B

# Jointly test the linear and 
test(warp.pl, joint = TRUE, rows = 1:2)

# Compare the two contrasts for each degree
contrast(warp.pl, "revpairwise", by = "contrast")

# User-provided contrasts, ignoring the previous by grouping
contrast(warp.lsm, 
    list(c1=c(1,0,0,-1,0,0), c2=c(1,1,1,-1,-1,-1)/3), 
    by = NULL)

Run the code above in your browser using DataLab