Learn R Programming

sjstats (version 0.17.6)

robust: Robust standard errors for regression models

Description

robust() computes robust standard error for regression models. This method calls one of the vcov*()-functions from the sandwich-package for robust covariance matrix estimators. Results are returned as tidy data frame.

svy() is intended to compute standard errors for survey designs (complex samples) fitted with regular lm or glm functions, as alternative to the survey-package. It simulates sampling weights by adjusting the residual degrees of freedom based on the precision weights used to fit x, and then calls robust() with the adjusted model.

Usage

robust(x, vcov.fun = "vcovHC", vcov.type = c("HC3", "const", "HC",
  "HC0", "HC1", "HC2", "HC4", "HC4m", "HC5"), vcov.args = NULL,
  conf.int = FALSE, exponentiate = FALSE)

svy(x, vcov.fun = "vcovHC", vcov.type = c("HC1", "const", "HC", "HC0", "HC3", "HC2", "HC4", "HC4m", "HC5"), vcov.args = NULL, conf.int = FALSE, exponentiate = FALSE)

Arguments

x

A fitted model of any class that is supported by the vcov*()-functions from the sandwich package. For svy(), x must be lm object, fitted with weights.

vcov.fun

String, indicating the name of the vcov*()-function from the sandwich-package, e.g. vcov.fun = "vcovCL".

vcov.type

Character vector, specifying the estimation type for the robust covariance matrix estimation (see vcovHC for details).

vcov.args

List of named vectors, used as additional arguments that are passed down to vcov.fun.

conf.int

Logical, TRUE if confidence intervals based on robust standard errors should be included.

exponentiate

Logical, whether to exponentiate the coefficient estimates and confidence intervals (typical for logistic regression).

Value

A summary of the model, including estimates, robust standard error, p-value and - optionally - the confidence intervals.

Examples

Run this code
# NOT RUN {
data(efc)
fit <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)
summary(fit)
robust(fit)

confint(fit)
robust(fit, conf.int = TRUE)
robust(fit, vcov.type = "HC1", conf.int = TRUE) # "HC1" should be Stata default

library(sjmisc)
# dichtomozize service usage by "service usage yes/no"
efc$services <- sjmisc::dicho(efc$tot_sc_e, dich.by = 0)
fit <- glm(services ~ neg_c_7 + c161sex + e42dep,
           data = efc, family = binomial(link = "logit"))

robust(fit)
robust(fit, conf.int = TRUE, exponentiate = TRUE)

# }

Run the code above in your browser using DataLab