The model_parameters()
function also allows the computation of standard errors, confidence intervals and p-values based on robust covariance matrix estimation from model parameters. Robust estimation is based on the packages sandwich and clubSandwich, so all models supported by either of these packages work with model_parameters()
when robust = TRUE
.
By default, when model_parameters(robust = TRUE)
, it internally calls sandwich::vcovHC(type = "HC3")
. However, there are three arguments that allow for choosing different methods and options of robust estimation: vcov_estimation
, vcov_type
and vcov_args
(see ?standard_error_robust
for further details).
Let us start with a simple example, which uses a heteroskedasticity-consistent covariance matrix estimation with estimation-type “HC3” (i.e. sandwich::vcovHC(type = "HC3")
is called):
data(iris)
model <- lm(Petal.Length ~ Sepal.Length * Species + Sepal.Width, data = iris)
# model parameters, where SE, CI and p-values are based on robust estimation
mp <- model_parameters(model, robust = TRUE)
mp
#> Parameter | Coefficient | SE | 95% CI | t(143) | p
#> ------------------------------------------------------------------------------------------
#> (Intercept) | 0.87 | 0.45 | [-0.03, 1.76] | 1.91 | 0.059
#> Sepal.Length | 0.04 | 0.12 | [-0.19, 0.28] | 0.37 | 0.711
#> Species [versicolor] | -0.78 | 0.69 | [-2.15, 0.59] | -1.12 | 0.265
#> Species [virginica] | -0.41 | 0.63 | [-1.66, 0.83] | -0.66 | 0.513
#> Sepal.Width | 0.11 | 0.08 | [-0.05, 0.27] | 1.32 | 0.190
#> Sepal.Length * Species [versicolor] | 0.61 | 0.13 | [ 0.35, 0.87] | 4.65 | < .001
#> Sepal.Length * Species [virginica] | 0.68 | 0.12 | [ 0.45, 0.91] | 5.75 | < .001
#> [1] 0.454 0.119 0.693 0.630 0.083 0.130 0.118
#> [1] 0.454 0.119 0.693 0.630 0.083 0.130 0.118
If another covariance matrix estimation is required, use the vcov_estimation
-argument. This argument needs the suffix for the related vcov*()
-functions as value, i.e. vcov_estimation = "CL"
would call sandwich::vcovCL()
, or vcov_estimation = "HAC"
would call sandwich::vcovHAC()
.
The specific estimation type can be changed with vcov_type
. E.g., sandwich::vcovCL()
accepts estimation types HC0 to HC3. In the next example, we use a clustered covariance matrix estimation with HC1-estimation type.
# change estimation-type
mp <- model_parameters(model, robust = TRUE, vcov_estimation = "CL", vcov_type = "HC1")
mp
#> Parameter | Coefficient | SE | 95% CI | t(143) | p
#> ------------------------------------------------------------------------------------------
#> (Intercept) | 0.87 | 0.42 | [ 0.03, 1.70] | 2.05 | 0.042
#> Sepal.Length | 0.04 | 0.11 | [-0.18, 0.26] | 0.40 | 0.692
#> Species [versicolor] | -0.78 | 0.65 | [-2.07, 0.51] | -1.19 | 0.237
#> Species [virginica] | -0.41 | 0.59 | [-1.57, 0.75] | -0.70 | 0.483
#> Sepal.Width | 0.11 | 0.08 | [-0.05, 0.27] | 1.38 | 0.170
#> Sepal.Length * Species [versicolor] | 0.61 | 0.12 | [ 0.37, 0.85] | 4.96 | < .001
#> Sepal.Length * Species [virginica] | 0.68 | 0.11 | [ 0.46, 0.90] | 6.15 | < .001
#> [1] 0.422 0.111 0.653 0.587 0.079 0.123 0.111
#> [1] 0.422 0.111 0.653 0.587 0.079 0.123 0.111
Usually, clustered covariance matrix estimation is used when there is a cluster-structure in the data. The variable indicating the cluster-structure can be defined in sandwich::vcovCL()
with the cluster
-argument. In model_parameters()
, additional arguments that should be passed down to functions from the sandwich package can be specified in vcov_args
:
iris$cluster <- factor(rep(LETTERS[1:8], length.out = nrow(iris)))
# change estimation-type, defining additional arguments
mp <- model_parameters(
model,
robust = TRUE,
vcov_estimation = "CL",
vcov_type = "HC1",
vcov_args = list(cluster = iris$cluster)
)
mp
#> Parameter | Coefficient | SE | 95% CI | t(143) | p
#> ------------------------------------------------------------------------------------------
#> (Intercept) | 0.87 | 0.34 | [ 0.20, 1.53] | 2.57 | 0.011
#> Sepal.Length | 0.04 | 0.07 | [-0.10, 0.19] | 0.61 | 0.540
#> Species [versicolor] | -0.78 | 0.52 | [-1.80, 0.25] | -1.49 | 0.137
#> Species [virginica] | -0.41 | 0.26 | [-0.94, 0.11] | -1.56 | 0.120
#> Sepal.Width | 0.11 | 0.07 | [-0.03, 0.25] | 1.52 | 0.131
#> Sepal.Length * Species [versicolor] | 0.61 | 0.10 | [ 0.42, 0.80] | 6.29 | < .001
#> Sepal.Length * Species [virginica] | 0.68 | 0.05 | [ 0.58, 0.78] | 13.28 | < .001
#> [1] 0.337 0.072 0.519 0.264 0.072 0.097 0.051
#> [1] 0.337 0.072 0.519 0.264 0.072 0.097 0.051
Finally, robust estimation can be combined with standardization. However, robust covariance matrix estimation only works for standardize = "refit"
.
# model parameters, robust estimation on standardized model
model_parameters(model, standardize = "refit", robust = TRUE)
#> Parameter | Coefficient | SE | 95% CI | t(143) | p
#> -------------------------------------------------------------------------------------------
#> (Intercept) | -1.30 | 0.07 | [-1.44, -1.16] | -18.70 | < .001
#> Sepal.Length | 0.02 | 0.06 | [-0.09, 0.13] | 0.37 | 0.711
#> Species [versicolor] | 1.57 | 0.09 | [ 1.40, 1.74] | 17.84 | < .001
#> Species [virginica] | 2.02 | 0.09 | [ 1.84, 2.20] | 22.49 | < .001
#> Sepal.Width | 0.03 | 0.02 | [-0.01, 0.07] | 1.32 | 0.190
#> Sepal.Length * Species [versicolor] | 0.28 | 0.06 | [ 0.16, 0.41] | 4.65 | < .001
#> Sepal.Length * Species [virginica] | 0.32 | 0.06 | [ 0.21, 0.43] | 5.75 | < .001