Debian Codegraph @

man/vcovCR.lm.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/lm.R
3 \name{vcovCR.lm}
4 \alias{vcovCR.lm}
5 \title{Cluster-robust variance-covariance matrix for an lm object.}
6 \usage{
7 \method{vcovCR}{lm}(
8 obj,
9 cluster,
10 type,
11 target = NULL,
12 inverse_var = NULL,
13 form = "sandwich",
14 ...
15 )
16 }
17 \arguments{
18 \item{obj}{Fitted model for which to calculate the variance-covariance matrix}
19
20 \item{cluster}{Expression or vector indicating which observations belong to
21 the same cluster. Required for \code{lm} objects.}
22
23 \item{type}{Character string specifying which small-sample adjustment should
24 be used, with available options \code{"CR0"}, \code{"CR1"}, \code{"CR1p"},
25 \code{"CR1S"}, \code{"CR2"}, or \code{"CR3"}. See "Details" section of
26 \code{\link{vcovCR}} for further information.}
27
28 \item{target}{Optional matrix or vector describing the working
29 variance-covariance model used to calculate the \code{CR2} and \code{CR4}
30 adjustment matrices. If a vector, the target matrix is assumed to be
31 diagonal. If not specified, the target is taken to be an identity matrix.}
32
33 \item{inverse_var}{Optional logical indicating whether the weights used in
34 fitting the model are inverse-variance. If not specified, \code{vcovCR}
35 will attempt to infer a value.}
36
37 \item{form}{Controls the form of the returned matrix. The default
38 \code{"sandwich"} will return the sandwich variance-covariance matrix.
39 Alternately, setting \code{form = "meat"} will return only the meat of the
40 sandwich and setting \code{form = B}, where \code{B} is a matrix of
41 appropriate dimension, will return the sandwich variance-covariance matrix
42 calculated using \code{B} as the bread. \code{form = "estfun"} will return the
43 (appropriately scaled) estimating function, the transposed crossproduct of
44 which is equal to the sandwich variance-covariance matrix.}
45
46 \item{...}{Additional arguments available for some classes of objects.}
47 }
48 \value{
49 An object of class \code{c("vcovCR","clubSandwich")}, which consists
50 of a matrix of the estimated variance of and covariances between the
51 regression coefficient estimates.
52 }
53 \description{
54 \code{vcovCR} returns a sandwich estimate of the variance-covariance matrix
55 of a set of regression coefficient estimates from an \code{\link{lm}} object.
56 }
57 \examples{
58
59 data("ChickWeight", package = "datasets")
60 lm_fit <- lm(weight ~ Time + Diet:Time, data = ChickWeight)
61 vcovCR(lm_fit, cluster = ChickWeight$Chick, type = "CR2")
62
63 if (requireNamespace("plm", quietly = TRUE)) withAutoprint({
64
65 data("Produc", package = "plm")
66 lm_individual <- lm(log(gsp) ~ 0 + state + log(pcap) + log(pc) + log(emp) + unemp, data = Produc)
67 individual_index <- !grepl("state", names(coef(lm_individual)))
68 vcovCR(lm_individual, cluster = Produc$state, type = "CR2")[individual_index,individual_index]
69
70 # compare to plm()
71 plm_FE <- plm::plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp,
72 data = Produc, index = c("state","year"),
73 effect = "individual", model = "within")
74 vcovCR(plm_FE, type="CR2")
75
76 })
77
78 }
79 \seealso{
80 \code{\link{vcovCR}}
81 }