linear_contrast | R Documentation |
linear_contrast
reports confidence intervals and (optionally) p-values
for linear contrasts of regression coefficients from a fitted model, using a
sandwich estimator for the standard errors and (optionally) a small sample
correction for the critical values. The default small-sample correction is
based on a Satterthwaite approximation.
linear_contrast(
obj,
vcov,
contrasts,
level = 0.95,
test = "Satterthwaite",
...,
p_values = FALSE
)
obj |
Fitted model for which to calculate confidence intervals. |
vcov |
Variance covariance matrix estimated using |
contrasts |
A contrast matrix, or a list of multiple contrast matrices to test. See details and examples. |
level |
Desired coverage level for confidence intervals. |
test |
Character vector specifying which small-sample corrections to
calculate. |
... |
Further arguments passed to |
p_values |
Logical indicating whether to report p-values. The default
value is |
Constraints can be specified directly as q X p matrices or
indirectly through constrain_pairwise
,
constrain_equal
, or constrain_zero
.
A data frame containing estimated contrasts, standard errors, confidence intervals, and (optionally) p-values.
vcovCR
data("ChickWeight", package = "datasets")
lm_fit <- lm(weight ~ 0 + Diet + Time:Diet, data = ChickWeight)
# Pairwise comparisons of diet-by-time slopes
linear_contrast(lm_fit, vcov = "CR2", cluster = ChickWeight$Chick,
contrasts = constrain_pairwise("Diet.:Time", reg_ex = TRUE))
if (requireNamespace("carData", quietly = TRUE)) withAutoprint({
data(Duncan, package = "carData")
Duncan$cluster <- sample(LETTERS[1:8], size = nrow(Duncan), replace = TRUE)
Duncan_fit <- lm(prestige ~ 0 + type + income + type:income + type:education, data=Duncan)
# Note that type:income terms are interactions because main effect of income is included
# but type:education terms are separate slopes for each unique level of type
# Pairwise comparisons of type-by-education slopes
linear_contrast(Duncan_fit, vcov = "CR2", cluster = Duncan$cluster,
contrasts = constrain_pairwise(":education", reg_ex = TRUE),
test = "Satterthwaite")
# Pairwise comparisons of type-by-income interactions
linear_contrast(Duncan_fit, vcov = "CR2", cluster = Duncan$cluster,
contrasts = constrain_pairwise(":income", reg_ex = TRUE, with_zero = TRUE),
test = "Satterthwaite")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.