Debian Codegraph @

man/vcovCR.plm.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/plm.R
3 \name{vcovCR.plm}
4 \alias{vcovCR.plm}
5 \title{Cluster-robust variance-covariance matrix for a plm object.}
6 \usage{
7 \method{vcovCR}{plm}(
8 obj,
9 cluster,
10 type,
11 target,
12 inverse_var,
13 form = "sandwich",
14 ignore_FE = FALSE,
15 ...
16 )
17 }
18 \arguments{
19 \item{obj}{Fitted model for which to calculate the variance-covariance matrix}
20
21 \item{cluster}{Optional character string, expression, or vector indicating
22 which observations belong to the same cluster. For fixed-effect models that
23 include individual effects or time effects (but not both), the cluster will
24 be taken equal to the included fixed effects if not otherwise specified.
25 Clustering on individuals can also be obtained by specifying the name of
26 the individual index (e.g., \code{cluster = "state"}) or \code{cluster =
27 "individual"}; clustering on time periods can be obtained by specifying the
28 name of the time index (e.g., \code{cluster = "year"}) or \code{cluster =
29 "time"}; if a group index is specified, clustering on groups (in which
30 individuals are nested) can be obtained by specifying the name of the group
31 index or \code{cluster = "group"}. For random-effects models, the cluster
32 will be taken equal to the included random effect identifier if not
33 otherwise specified.}
34
35 \item{type}{Character string specifying which small-sample adjustment should
36 be used, with available options \code{"CR0"}, \code{"CR1"}, \code{"CR1p"},
37 \code{"CR1S"}, \code{"CR2"}, or \code{"CR3"}. See "Details" section of
38 \code{\link{vcovCR}} for further information.}
39
40 \item{target}{Optional matrix or vector describing the working
41 variance-covariance model used to calculate the \code{CR2} and \code{CR4}
42 adjustment matrices. By default, the target is taken to be an identity
43 matrix for fixed effect models or the estimated compound-symmetric
44 covariance matrix for random effects models.}
45
46 \item{inverse_var}{Optional logical indicating whether the weights used in
47 fitting the model are inverse-variance. If not specified, \code{vcovCR}
48 will attempt to infer a value.}
49
50 \item{form}{Controls the form of the returned matrix. The default
51 \code{"sandwich"} will return the sandwich variance-covariance matrix.
52 Alternately, setting \code{form = "meat"} will return only the meat of the
53 sandwich and setting \code{form = B}, where \code{B} is a matrix of
54 appropriate dimension, will return the sandwich variance-covariance matrix
55 calculated using \code{B} as the bread. \code{form = "estfun"} will return the
56 (appropriately scaled) estimating function, the transposed crossproduct of
57 which is equal to the sandwich variance-covariance matrix.}
58
59 \item{ignore_FE}{Optional logical controlling whether fixed effects are
60 ignored when calculating small-sample adjustments in models where fixed
61 effects are estimated through absorption.}
62
63 \item{...}{Additional arguments available for some classes of objects.}
64 }
65 \value{
66 An object of class \code{c("vcovCR","clubSandwich")}, which consists
67 of a matrix of the estimated variance of and covariances between the
68 regression coefficient estimates.
69 }
70 \description{
71 \code{vcovCR} returns a sandwich estimate of the variance-covariance matrix
72 of a set of regression coefficient estimates from a \code{\link[plm]{plm}}
73 object.
74 }
75 \examples{
76
77 if (requireNamespace("plm", quietly = TRUE)) withAutoprint({
78
79 library(plm)
80 # fixed effects
81 data("Produc", package = "plm")
82 plm_FE <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp,
83 data = Produc, index = c("state","year","region"),
84 effect = "individual", model = "within")
85 vcovCR(plm_FE, type="CR2")
86 vcovCR(plm_FE, type = "CR2", cluster = Produc$region) # clustering on region
87
88 # random effects
89 plm_RE <- update(plm_FE, model = "random")
90 vcovCR(plm_RE, type = "CR2")
91 vcovCR(plm_RE, type = "CR2", cluster = Produc$region) # clustering on region
92
93 # nested random effects
94 plm_nested <- update(plm_FE, effect = "nested", model = "random")
95 vcovCR(plm_nested, type = "CR2") # clustering on region
96 })
97
98 pkgs_available <- requireNamespace("plm", quietly = TRUE) & requireNamespace("AER", quietly = TRUE)
99
100 if (pkgs_available) withAutoprint({
101 # first differencing
102 data(Fatalities, package = "AER")
103 Fatalities <- within(Fatalities, {
104 frate <- 10000 * fatal / pop
105 drinkagec <- cut(drinkage, breaks = 18:22, include.lowest = TRUE, right = FALSE)
106 drinkagec <- relevel(drinkagec, ref = 4)
107 })
108
109 plm_FD <- plm(frate ~ beertax + drinkagec + miles + unemp + log(income),
110 data = Fatalities, index = c("state", "year"),
111 model = "fd")
112 vcovHC(plm_FD, method="arellano", type = "sss", cluster = "group")
113 vcovCR(plm_FD, type = "CR1S")
114 vcovCR(plm_FD, type = "CR2")
115
116 })
117
118 }
119 \seealso{
120 \code{\link{vcovCR}}
121 }