linear_contrast {clubSandwich} | R Documentation |
Calculate confidence intervals and p-values for linear contrasts of regression coefficients in a fitted model
Description
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.
Usage
linear_contrast(
obj,
vcov,
contrasts,
level = 0.95,
test = "Satterthwaite",
...,
p_values = FALSE
)
Arguments
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 |
Details
Constraints can be specified directly as q X p matrices or
indirectly through constrain_pairwise
,
constrain_equal
, or constrain_zero
.
Value
A data frame containing estimated contrasts, standard errors, confidence intervals, and (optionally) p-values.
See Also
Examples
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")
})