| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/Wald_test.R |
| 3 |
\name{Wald_test} |
| 4 |
\alias{Wald_test} |
| 5 |
\title{Test parameter constraints in a fitted linear regression model} |
| 6 |
\usage{ |
| 7 |
Wald_test( |
| 8 |
obj, |
| 9 |
constraints, |
| 10 |
vcov, |
| 11 |
null_constant = 0, |
| 12 |
test = "HTZ", |
| 13 |
tidy = FALSE, |
| 14 |
adjustment_method = "none", |
| 15 |
... |
| 16 |
) |
| 17 |
} |
| 18 |
\arguments{ |
| 19 |
\item{obj}{Fitted model for which to calculate Wald tests.} |
| 20 |
|
| 21 |
\item{constraints}{constraint or list of multiple constraints to test. See |
| 22 |
details and examples.} |
| 23 |
|
| 24 |
\item{vcov}{Variance covariance matrix estimated using \code{vcovCR} or a |
| 25 |
character string specifying which small-sample adjustment should be used to |
| 26 |
calculate the variance-covariance.} |
| 27 |
|
| 28 |
\item{null_constant}{vector of null values or list of such vectors for each |
| 29 |
set of constraints to test. For a single \code{constraint}, the null values |
| 30 |
must have length equal to the number of rows in the constraint. For lists |
| 31 |
of null values, each entry must have length equal to the number of rows in |
| 32 |
the corresponding entry of \code{constraints}. Default is \code{0}, in |
| 33 |
which case the null values are taken to be zero (for every entry, if |
| 34 |
\code{constraints} is a list).} |
| 35 |
|
| 36 |
\item{test}{Character vector specifying which small-sample correction(s) to |
| 37 |
calculate. The following corrections are available: \code{"chi-sq"}, |
| 38 |
\code{"Naive-F"}, \code{"Naive-Fp"}, \code{"HTA"}, \code{"HTB"}, |
| 39 |
\code{"HTZ"}, \code{"EDF"}, \code{"EDT"}. Default is \code{"HTZ"}.} |
| 40 |
|
| 41 |
\item{tidy}{Logical value controlling whether to tidy the test results. If |
| 42 |
\code{constraints} is a list with multiple constraints, the result will be |
| 43 |
coerced into a data frame when \code{tidy = TRUE}.} |
| 44 |
|
| 45 |
\item{adjustment_method}{A character string indicating a multiple comparisons |
| 46 |
correction to apply to p-values in instances where multiple tests are run. |
| 47 |
Possible options are from \code{\link[stats]{p.adjust.methods}}, which is |
| 48 |
passed to \code{\link[stats]{p.adjust}} to correct p-values for multiple |
| 49 |
comparisons. Defaults to \code{"none"}.} |
| 50 |
|
| 51 |
\item{...}{Further arguments passed to \code{\link{vcovCR}}, which are only |
| 52 |
needed if \code{vcov} is a character string.} |
| 53 |
} |
| 54 |
\value{ |
| 55 |
A list of test results. |
| 56 |
} |
| 57 |
\description{ |
| 58 |
\code{Wald_test} reports Wald-type tests of linear contrasts from a fitted |
| 59 |
linear regression model, using a sandwich estimator for the |
| 60 |
variance-covariance matrix and a small sample correction for the p-value. |
| 61 |
Several different small-sample corrections are available. |
| 62 |
} |
| 63 |
\details{ |
| 64 |
Constraints can be specified directly as q X p matrices or |
| 65 |
indirectly through \code{\link{constrain_equal}}, |
| 66 |
\code{\link{constrain_zero}}, or \code{\link{constrain_pairwise}}. By |
| 67 |
default, each constraint will be tested against the null hypothesis that it |
| 68 |
equal to a zero vector. Non-zero values for null-hypotheses can be |
| 69 |
specified using the \code{null_constant} argument. |
| 70 |
} |
| 71 |
\examples{ |
| 72 |
|
| 73 |
|
| 74 |
if (requireNamespace("carData", quietly = TRUE)) withAutoprint({ |
| 75 |
|
| 76 |
data(Duncan, package = "carData") |
| 77 |
Duncan$cluster <- sample(LETTERS[1:8], size = nrow(Duncan), replace = TRUE) |
| 78 |
|
| 79 |
Duncan_fit <- lm(prestige ~ 0 + type + income + type:income + type:education, data=Duncan) |
| 80 |
# Note that type:income terms are interactions because main effect of income is included |
| 81 |
# but type:education terms are separate slopes for each unique level of type |
| 82 |
|
| 83 |
# Test equality of intercepts |
| 84 |
Wald_test(Duncan_fit, |
| 85 |
constraints = constrain_equal(1:3), |
| 86 |
vcov = "CR2", cluster = Duncan$cluster) |
| 87 |
|
| 88 |
# Test equality of type-by-education slopes |
| 89 |
Wald_test(Duncan_fit, |
| 90 |
constraints = constrain_equal(":education", reg_ex = TRUE), |
| 91 |
vcov = "CR2", cluster = Duncan$cluster) |
| 92 |
|
| 93 |
# Pairwise comparisons of type-by-education slopes |
| 94 |
Wald_test(Duncan_fit, |
| 95 |
constraints = constrain_pairwise(":education", reg_ex = TRUE), |
| 96 |
vcov = "CR2", cluster = Duncan$cluster) |
| 97 |
|
| 98 |
# Test type-by-income interactions |
| 99 |
Wald_test(Duncan_fit, |
| 100 |
constraints = constrain_zero(":income", reg_ex = TRUE), |
| 101 |
vcov = "CR2", cluster = Duncan$cluster) |
| 102 |
|
| 103 |
# Pairwise comparisons of type-by-income interactions |
| 104 |
Wald_test(Duncan_fit, |
| 105 |
constraints = constrain_pairwise(":income", reg_ex = TRUE, with_zero = TRUE), |
| 106 |
vcov = "CR2", cluster = Duncan$cluster) |
| 107 |
|
| 108 |
# Pairwise comparisons of type-by-education slopes, with two tests and |
| 109 |
# multiple comparisons p-value adjustment |
| 110 |
Wald_test(Duncan_fit, |
| 111 |
constraints = constrain_pairwise(":education", reg_ex = TRUE), |
| 112 |
vcov = "CR2", |
| 113 |
cluster = Duncan$cluster, |
| 114 |
test = c("HTZ","chi-sq"), |
| 115 |
adjustment_method = "holm") |
| 116 |
|
| 117 |
}) |
| 118 |
|
| 119 |
} |
| 120 |
\seealso{ |
| 121 |
\code{\link{vcovCR}}, \code{\link{constrain_equal}}, |
| 122 |
\code{\link{constrain_zero}}, \code{\link{constrain_pairwise}} |
| 123 |
} |