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.
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)
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.
String, indicating the name of the vcov*()
-function
from the sandwich-package, e.g. vcov.fun = "vcovCL"
.
Character vector, specifying the estimation type for the
robust covariance matrix estimation (see vcovHC
for details).
List of named vectors, used as additional arguments that
are passed down to vcov.fun
.
Logical, TRUE
if confidence intervals based on robust
standard errors should be included.
Logical, whether to exponentiate the coefficient estimates and confidence intervals (typical for logistic regression).
A summary of the model, including estimates, robust standard error, p-value and - optionally - the confidence intervals.
# 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