Learn R Programming

bucky (version 1.0.7)

robustify: Robustify a model

Description

Create a robustified object that includes robust or clustered robust standard errors.

Usage

robustify(x, cluster, type, omega, ...)

Arguments

x

A model of class lm, glm, or any other class which contains a call object and methods for estfun and nobs.

cluster

The variable on which to cluster (if any). If this is not specified, unclustered robust standard errors using vcovHC are used. If this is specified, clustered robust standard errors using vcovCR are used.

type

A character string specifying the estimation type. The default for linear models of class lm but not glm is to use "HC1" for vcovHC or "CR1" for vcovCR, depending on whether cluster is specified. For other models, the default is to use "HC" for vcovHC or "CR" for vcovCR, depending on whether cluster is specified. This mirrors the defaults used by Stata as closely as possible. For details, see vcovHC or vcovCR.

omega

A vector or a function depending on the arguments `residuals' (the working residuals of the model), `diaghat' (the diagonal of the corresponding hat matrix) and `df' (the residual degrees of freedom). For details, see vcovHC or vcovCR.

Any additional arguments to be passed to coeftest.

Value

An object of class robustified with the method attribute specifying the type of standard errors used.

Details

This function creates a robustified object containing the model, coefficients, and variance-covariance matrix based on vcovHC or vcovCR, respectively. If the cluster option is specified, the variance-covariance matrix is computed using vcovCR with clustering on cluster. If not, the variance-covariance matrix is computed using vcovHC. For generating formatted tables of regression coefficients, the outputted objects should be compatible with the 'texreg' package. When used with lm, glm or a few other types of models, these objects are also compatible with the 'stargazer' package.

References

Cameron, A. Colin, and Douglas L. Miller. “A Practitioner's Guide to Cluster-Robust Inference.” Journal of Human Resources 50, no. 2 (Spring 2015): 317-372. 10.3368/jhr.50.2.317

See Also

See Also summary.robustified, vcovHC, vcovCR and coeftest.

Examples

Run this code
# NOT RUN {
## With clustering
clotting <- data.frame(
    cl = 1:9,
    u = c(5,10,15,20,30,40,60,80,100),
    lot = c(118,58,42,35,27,25,21,19,18,
            69,35,26,21,18,16,13,12,12))
clot.model <- glm(lot ~ log(u), data = clotting, family = Gamma)
robust.clot.model <- robustify(clot.model, cluster=cl)
robust.clot.model
summary(robust.clot.model)

## Without clustering
data(swiss)
model1 <- robustify(lm(Fertility ~ ., data = swiss))
model1
summary(model1)
# }

Run the code above in your browser using DataLab