Debian Codegraph @

man/linear_contrast.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/conf_int.R
3 \name{linear_contrast}
4 \alias{linear_contrast}
5 \title{Calculate confidence intervals and p-values for linear contrasts of
6 regression coefficients in a fitted model}
7 \usage{
8 linear_contrast(
9 obj,
10 vcov,
11 contrasts,
12 level = 0.95,
13 test = "Satterthwaite",
14 ...,
15 p_values = FALSE,
16 adjustment_method = "none"
17 )
18 }
19 \arguments{
20 \item{obj}{Fitted model for which to calculate confidence intervals.}
21
22 \item{vcov}{Variance covariance matrix estimated using \code{vcovCR} or a
23 character string specifying which small-sample adjustment should be used to
24 calculate the variance-covariance.}
25
26 \item{contrasts}{A contrast matrix, or a list of multiple contrast matrices
27 to test. See details and examples.}
28
29 \item{level}{Desired coverage level for confidence intervals.}
30
31 \item{test}{Character vector specifying which small-sample corrections to
32 calculate. \code{"z"} returns a z test (i.e., using a standard normal
33 reference distribution). \code{"naive-t"} returns a t test with \code{m -
34 1} degrees of freedom, where \code{m} is the number of unique clusters.
35 \code{"naive-tp"} returns a t test with \code{m - p} degrees of freedom,
36 where \code{p} is the number of regression coefficients in \code{obj}.
37 \code{"Satterthwaite"} returns a Satterthwaite correction. Unlike in
38 \code{coef_test()}, \code{"saddlepoint"} is not currently supported in
39 \code{conf_int()} because saddlepoint confidence intervals do not have a
40 closed-form solution.}
41
42 \item{...}{Further arguments passed to \code{\link{vcovCR}}, which are only
43 needed if \code{vcov} is a character string.}
44
45 \item{p_values}{Logical indicating whether to report p-values. The default
46 value is \code{FALSE}.}
47
48 \item{adjustment_method}{Correction method, a \code{\link{character}} string
49 from \code{p.adjust.methods}, which is passed to \code{\link{p.adjust}} to
50 correct p-values in the case of multiple comparisons. Defaults to
51 \code{"none"}. Any value given will be ignored if \code{p_values = FALSE}.}
52 }
53 \value{
54 A data frame containing estimated contrasts, standard
55 errors, confidence intervals, and (optionally) p-values.
56 }
57 \description{
58 \code{linear_contrast} reports confidence intervals and (optionally) p-values
59 for linear contrasts of regression coefficients from a fitted model, using a
60 sandwich estimator for the standard errors and (optionally) a small sample
61 correction for the critical values. The default small-sample correction is
62 based on a Satterthwaite approximation.
63 }
64 \details{
65 Constraints can be specified directly as q X p matrices or
66 indirectly through \code{\link{constrain_pairwise}},
67 \code{\link{constrain_equal}}, or \code{\link{constrain_zero}}.
68 }
69 \examples{
70
71 data("ChickWeight", package = "datasets")
72 lm_fit <- lm(weight ~ 0 + Diet + Time:Diet, data = ChickWeight)
73
74 # Pairwise comparisons of diet-by-time slopes
75 linear_contrast(lm_fit, vcov = "CR2", cluster = ChickWeight$Chick,
76 contrasts = constrain_pairwise("Diet.:Time", reg_ex = TRUE))
77
78
79 if (requireNamespace("carData", quietly = TRUE)) withAutoprint({
80
81 data(Duncan, package = "carData")
82 Duncan$cluster <- sample(LETTERS[1:8], size = nrow(Duncan), replace = TRUE)
83
84 Duncan_fit <- lm(prestige ~ 0 + type + income + type:income + type:education, data=Duncan)
85 # Note that type:income terms are interactions because main effect of income is included
86 # but type:education terms are separate slopes for each unique level of type
87
88 # Pairwise comparisons of type-by-education slopes
89 linear_contrast(Duncan_fit, vcov = "CR2", cluster = Duncan$cluster,
90 contrasts = constrain_pairwise(":education", reg_ex = TRUE),
91 test = "Satterthwaite")
92
93 # Repeat the above, but with p-values displayed and multiple comparisons adjustment applied.
94 linear_contrast(Duncan_fit, vcov = "CR2", cluster = Duncan$cluster,
95 contrasts = constrain_pairwise(":education", reg_ex = TRUE),
96 test = "Satterthwaite", p_values = TRUE, adjustment_method = "hochberg")
97
98 # Pairwise comparisons of type-by-income interactions
99 linear_contrast(Duncan_fit, vcov = "CR2", cluster = Duncan$cluster,
100 contrasts = constrain_pairwise(":income", reg_ex = TRUE, with_zero = TRUE),
101 test = "Satterthwaite")
102
103 })
104
105 }
106 \seealso{
107 \code{\link{vcovCR}}
108 }