| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/mmrm.R |
| 3 |
\name{vcovCR.mmrm} |
| 4 |
\alias{vcovCR.mmrm} |
| 5 |
\title{Cluster-robust variance-covariance matrix for an mmrm object.} |
| 6 |
\usage{ |
| 7 |
\method{vcovCR}{mmrm}(obj, cluster, type, target, inverse_var, form = "sandwich", ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{obj}{Fitted model for which to calculate the variance-covariance matrix} |
| 11 |
|
| 12 |
\item{cluster}{Optional expression or vector indicating which observations |
| 13 |
belong to the same cluster. If not specified, will be set to the subject |
| 14 |
variable from the \code{mmrm} model formula.} |
| 15 |
|
| 16 |
\item{type}{Character string specifying which small-sample adjustment should |
| 17 |
be used, with available options \code{"CR0"}, \code{"CR1"}, \code{"CR1p"}, |
| 18 |
\code{"CR1S"}, \code{"CR2"}, or \code{"CR3"}. See "Details" section of |
| 19 |
\code{\link{vcovCR}} for further information.} |
| 20 |
|
| 21 |
\item{target}{Optional matrix or vector describing the working |
| 22 |
variance-covariance model used to calculate the \code{CR2} and \code{CR4} |
| 23 |
adjustment matrices. If not specified, the target is taken to be the |
| 24 |
estimated variance-covariance structure of the \code{mmrm} object, with |
| 25 |
weights applied if present.} |
| 26 |
|
| 27 |
\item{inverse_var}{Optional logical indicating whether the weights used in |
| 28 |
fitting the model are inverse-variance. If not specified, \code{vcovCR} |
| 29 |
will attempt to infer a value.} |
| 30 |
|
| 31 |
\item{form}{Controls the form of the returned matrix. The default |
| 32 |
\code{"sandwich"} will return the sandwich variance-covariance matrix. |
| 33 |
Alternately, setting \code{form = "meat"} will return only the meat of the |
| 34 |
sandwich and setting \code{form = B}, where \code{B} is a matrix of |
| 35 |
appropriate dimension, will return the sandwich variance-covariance matrix |
| 36 |
calculated using \code{B} as the bread. \code{form = "estfun"} will return the |
| 37 |
(appropriately scaled) estimating function, the transposed crossproduct of |
| 38 |
which is equal to the sandwich variance-covariance matrix.} |
| 39 |
|
| 40 |
\item{...}{Additional arguments available for some classes of objects.} |
| 41 |
} |
| 42 |
\value{ |
| 43 |
An object of class \code{c("vcovCR","clubSandwich")}, which consists |
| 44 |
of a matrix of the estimated variance of and covariances between the |
| 45 |
regression coefficient estimates. |
| 46 |
} |
| 47 |
\description{ |
| 48 |
\code{vcovCR} returns a sandwich estimate of the variance-covariance matrix |
| 49 |
of a set of regression coefficient estimates from an |
| 50 |
\code{\link[mmrm]{mmrm}} object. |
| 51 |
} |
| 52 |
\examples{ |
| 53 |
|
| 54 |
if (requireNamespace("mmrm", quietly = TRUE)) withAutoprint({ |
| 55 |
|
| 56 |
library(mmrm) |
| 57 |
data(fev_data, package = "mmrm") |
| 58 |
|
| 59 |
# Fit an mmrm model with unstructured covariance |
| 60 |
mmrm_fit <- mmrm( |
| 61 |
FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID), |
| 62 |
data = fev_data |
| 63 |
) |
| 64 |
|
| 65 |
# CR2 cluster-robust variance estimator (cluster auto-detected) |
| 66 |
vcovCR(mmrm_fit, type = "CR2") |
| 67 |
|
| 68 |
# Coefficient tests with Satterthwaite degrees of freedom |
| 69 |
coef_test(mmrm_fit, vcov = "CR2", test = "Satterthwaite") |
| 70 |
|
| 71 |
# Fit a weighted mmrm model |
| 72 |
fev_data$wt <- 1 + rpois(nrow(fev_data), lambda = 3) |
| 73 |
mmrm_wt <- mmrm( |
| 74 |
FEV1 ~ RACE + SEX + ARMCD + us(AVISIT | USUBJID), |
| 75 |
data = fev_data, |
| 76 |
weights = fev_data$wt |
| 77 |
) |
| 78 |
|
| 79 |
# CR2 works with weighted models |
| 80 |
vcovCR(mmrm_wt, type = "CR2") |
| 81 |
|
| 82 |
}) |
| 83 |
|
| 84 |
} |
| 85 |
\seealso{ |
| 86 |
\code{\link{vcovCR}} |
| 87 |
} |