Learn R Programming

sjstats (version 0.10.2)

robust: Robust standard errors for regression models

Description

robust() computes robust standard error for regression models. This method wraps the coeftest-function with robust covariance matrix estimators based on the vcovHC-function, and returns the result 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 = c("HC3", "const", "HC", "HC0", "HC1", "HC2", "HC4", "HC4m",
  "HC5"), conf.int = FALSE, exponentiate = FALSE)

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

Arguments

x

A fitted model of any class that is supported by the coeftest()-function. For svy(), x must be lm object, fitted with weights.

vcov

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

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 = "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