| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/coef_test.R |
| 3 |
\name{coef_test} |
| 4 |
\alias{coef_test} |
| 5 |
\title{Test all or selected regression coefficients in a fitted model} |
| 6 |
\usage{ |
| 7 |
coef_test( |
| 8 |
obj, |
| 9 |
vcov, |
| 10 |
test = "Satterthwaite", |
| 11 |
alternative = c("two-sided", "greater", "less"), |
| 12 |
coefs = "All", |
| 13 |
null_constants = 0, |
| 14 |
p_values = TRUE, |
| 15 |
... |
| 16 |
) |
| 17 |
} |
| 18 |
\arguments{ |
| 19 |
\item{obj}{Fitted model for which to calculate t-tests.} |
| 20 |
|
| 21 |
\item{vcov}{Variance covariance matrix estimated using \code{vcovCR} or a |
| 22 |
character string specifying which small-sample adjustment should be used to |
| 23 |
calculate the variance-covariance.} |
| 24 |
|
| 25 |
\item{test}{Character vector specifying which small-sample corrections to |
| 26 |
calculate. \code{"z"} returns a z test (i.e., using a standard normal |
| 27 |
reference distribution). \code{"naive-t"} returns a t test with \code{m - |
| 28 |
1} degrees of freedom, where \code{m} is the number of unique clusters. |
| 29 |
\code{"naive-tp"} returns a t test with \code{m - p} degrees of freedom, |
| 30 |
where \code{p} is the number of regression coefficients in \code{obj}. |
| 31 |
\code{"Satterthwaite"} returns a Satterthwaite correction. |
| 32 |
\code{"saddlepoint"} returns a saddlepoint correction. Default is |
| 33 |
\code{"Satterthwaite"}.} |
| 34 |
|
| 35 |
\item{alternative}{Character string specifying the alternative hypothesis, |
| 36 |
with options "two-sided" (the default), "greater" or "less".} |
| 37 |
|
| 38 |
\item{coefs}{Character, integer, or logical vector specifying which |
| 39 |
coefficients should be tested. The default value \code{"All"} will test all |
| 40 |
estimated coefficients.} |
| 41 |
|
| 42 |
\item{null_constants}{vector of null values for each coefficient to test. |
| 43 |
Must have length equal to the number of coefficients specified in |
| 44 |
\code{coefs}. Default is \code{0}, in which case the null values are taken |
| 45 |
to be zero.} |
| 46 |
|
| 47 |
\item{p_values}{Logical indicating whether to report p-values. The default |
| 48 |
value is \code{TRUE}.} |
| 49 |
|
| 50 |
\item{...}{Further arguments passed to \code{\link{vcovCR}}, which are only |
| 51 |
needed if \code{vcov} is a character string.} |
| 52 |
} |
| 53 |
\value{ |
| 54 |
A data frame containing estimated regression coefficients, standard |
| 55 |
errors, specified values of null hypotheses, and test results. For the |
| 56 |
Satterthwaite approximation, degrees of freedom and a p-value are reported. |
| 57 |
For the saddlepoint approximation, the saddlepoint and a p-value are |
| 58 |
reported. |
| 59 |
} |
| 60 |
\description{ |
| 61 |
\code{coef_test} reports one- or two-sided t-tests for each coefficient |
| 62 |
estimate in a fitted linear regression model, using a sandwich estimator for |
| 63 |
the standard errors and (optionally) a small sample correction for the |
| 64 |
p-value. Available small-sample corrections include Satterthwaite |
| 65 |
approximation or a saddlepoint approximation. Coefficients can be tested |
| 66 |
against non-zero null values by specifying \code{null_constants}. |
| 67 |
} |
| 68 |
\examples{ |
| 69 |
|
| 70 |
data("ChickWeight", package = "datasets") |
| 71 |
lm_fit <- lm(weight ~ Diet * Time, data = ChickWeight) |
| 72 |
diet_index <- grepl("Diet.:Time", names(coef(lm_fit))) |
| 73 |
coef_test(lm_fit, vcov = "CR2", cluster = ChickWeight$Chick, coefs = diet_index) |
| 74 |
|
| 75 |
V_CR2 <- vcovCR(lm_fit, cluster = ChickWeight$Chick, type = "CR2") |
| 76 |
coef_test(lm_fit, vcov = V_CR2, coefs = diet_index) |
| 77 |
|
| 78 |
# non-inferiority test whether time-by-diet interaction effects are 2 or greater |
| 79 |
coef_test(lm_fit, vcov = V_CR2, coefs = diet_index, null_constants = 2, alternative = "greater") |
| 80 |
|
| 81 |
} |
| 82 |
\seealso{ |
| 83 |
\code{\link{vcovCR}} |
| 84 |
} |