Debian Codegraph @

man/vcovCR.lme.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/lme.R
3 \name{vcovCR.lme}
4 \alias{vcovCR.lme}
5 \title{Cluster-robust variance-covariance matrix for an lme object.}
6 \usage{
7 \method{vcovCR}{lme}(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
14 \code{getGroups(obj)}.}
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{lme} object.}
25
26 \item{inverse_var}{Optional logical indicating whether the weights used in
27 fitting the model are inverse-variance. If not specified, \code{vcovCR}
28 will attempt to infer a value.}
29
30 \item{form}{Controls the form of the returned matrix. The default
31 \code{"sandwich"} will return the sandwich variance-covariance matrix.
32 Alternately, setting \code{form = "meat"} will return only the meat of the
33 sandwich and setting \code{form = B}, where \code{B} is a matrix of
34 appropriate dimension, will return the sandwich variance-covariance matrix
35 calculated using \code{B} as the bread. \code{form = "estfun"} will return the
36 (appropriately scaled) estimating function, the transposed crossproduct of
37 which is equal to the sandwich variance-covariance matrix.}
38
39 \item{...}{Additional arguments available for some classes of objects.}
40 }
41 \value{
42 An object of class \code{c("vcovCR","clubSandwich")}, which consists
43 of a matrix of the estimated variance of and covariances between the
44 regression coefficient estimates.
45 }
46 \description{
47 \code{vcovCR} returns a sandwich estimate of the variance-covariance matrix
48 of a set of regression coefficient estimates from a \code{\link[nlme]{lme}} object.
49 }
50 \examples{
51
52 if (requireNamespace("nlme", quietly = TRUE)) {
53
54 library(nlme)
55 rat_weight <- lme(weight ~ Time * Diet, data=BodyWeight, ~ Time | Rat)
56 vcovCR(rat_weight, type = "CR2")
57
58 }
59
60 pkgs_available <-
61 requireNamespace("nlme", quietly = TRUE) &
62 requireNamespace("mlmRev", quietly = TRUE)
63
64 if (pkgs_available) {
65
66 data(egsingle, package = "mlmRev")
67 subset_ids <- levels(egsingle$schoolid)[1:10]
68 egsingle_subset <- subset(egsingle, schoolid \%in\% subset_ids)
69
70 math_model <- lme(math ~ year * size + female + black + hispanic,
71 random = list(~ year | schoolid, ~ 1 | childid),
72 data = egsingle_subset)
73
74 vcovCR(math_model, type = "CR2")
75
76 }
77
78 }
79 \seealso{
80 \code{\link{vcovCR}}
81 }