contrast.lm {contrast} | R Documentation |
This function computes one or more contrasts of the estimated regression coefficients in a fit from one of the functions in Design, along with standard errors, confidence limits, t or Z statistics, P-values.
contrast(fit, ...) ## S3 method for class 'lm': contrast(fit, ...) ## S3 method for class 'gls': contrast(fit, ...) ## S3 method for class 'lme': contrast(fit, ...) ## S3 method for class 'geese': contrast(fit, ...) ## S3 method for class 'contrast': print(x, X=FALSE, fun=function(u)u, ...)
fit |
a fit of class "lm" , "glm" , etc.
|
... |
arguments to pass to the computational code. The arguments are listed in the Details section below. |
x |
result of contrast |
X |
set X=TRUE to print design matrix used in computing the contrasts (or
the average contrast)
|
fun |
a function to transform the contrast, SE, and lower and upper
confidence limits before printing. For example, specify fun=exp to
anti-log them for logistic models.
|
These functions mirror contrast.Design
.
There are some between-package inconsistencies regarding degrees of freedom in some models. See the package vignette for more details.
Fold changes are calculated for each hypothesis. When fcType =
"simple"
, the ratio of the a
group predictions over the
b
group predictions are used. When fcType = "signed"
, the
ratio is used if it is greater than 1; otherwise the negative inverse
(e.g., -1/ratio
) is returned.
Arguments to the contast functions are:
gendata
function will generate the
necessary combinations and default values for unspecified predictors.
a
,
unless one of the two lists generates only one observation. In that
case, the design matrix generated from the shorter list will have its
rows replicated so that the contrasts assess several differences
against the one set of predictor values. This is useful for comparing
multiple treatments with control, for example. If b
is missing, the
design matrix generated from a
is analyzed alone.
type="individual"
. Usually cnames
is not necessary as
contrast.Design
tries to name the contrasts by examining which
predictors are varying consistently in the two lists. cnames
will
be needed when you contrast "non-comparable" settings, e.g., you
compare list(treat="drug", age=c(20,30))
with
list(treat="placebo"), age=c(40,50)
type="average"
to average the individual contrasts (e.g., to
obtain a Type II or III contrast)
type="average"
, to obtain weighted contrasts
a list of class "contrast.Design"
containing the elements
Contrast
, SE
, Z
, var
, df.residual
Lower
, Upper
, Pvalue
, X
, cnames
, which denote the contrast
estimates, standard errors, Z or t-statistics, variance matrix,
residual degrees of freedom (this is NULL
if the model was not
ols
), lower and upper confidence limits, 2-sided P-value, design
matrix, and contrast names (or NULL
).
Also, an element called foldChange
.
contrast.Design
library(nlme) Orthodont2 <- Orthodont Orthodont2$newAge <- Orthodont$age - 11 fm1Orth.lme2 <- lme(distance ~ Sex*newAge, data = Orthodont2, random = ~ newAge | Subject) summary(fm1Orth.lme2) contrast( fm1Orth.lme2, a = list(Sex = levels(Orthodont2$Sex), newAge = 8 - 11), b = list(Sex = levels(Orthodont2$Sex), newAge = 10 - 11))