## Registered S3 method overwritten by 'clubSandwich':
##   method    from    
##   bread.mlm sandwich

This vignette demonstrate how to compute confidence intervals based on (cluster) robust variance-covariance matrices for standard errors.

First, we load the required packages and create a sample data set with a binomial and continuous variable as predictor as well as a group factor. To avoid convergence warnings, the continuous variable is standardized.

library(ggeffects)
set.seed(123)

# example taken from "?clubSandwich::vcovCR"
m <- 8
cluster <- factor(rep(LETTERS[1:m], 3 + rpois(m, 5)))
n <- length(cluster)
X <- matrix(rnorm(3 * n), n, 3)
nu <- rnorm(m)[cluster]
e <- rnorm(n)
y <- X %*% c(.4, .3, -.3) + nu + e
dat <- data.frame(y, X, cluster, row = 1:n)

# fit linear model
model <- lm(y ~ X1 + X2 + X3, data = dat)

Predictions with HC-estimated standard errors

Now, we use sandwich::vcovHC() to estimate heteroskedasticity-consistent standard errors. To do so, first the function name, vcovHC(), must be supplied to the vcov.fun-argument. sandwich::vcovHC(), in turn, has different types of estimation. This must be specified in vcov.type.

me <- ggpredict(model, "X1", vcov.fun = "vcovHC", vcov.type = "HC0")
plot(me)