Compute the variance-covariance matrix of estimates in the output of std_selected() or std_selected_boot().

# S3 method for std_selected
vcov(object, type, ...)

Arguments

object

The output of std_selected() or std_selected_boot().

type

The type of variance-covariance matrix. If set to "lm", returns the results of the stats::vcov() method for the output of lm(). If set to "boot", the variance-covariance matrix of the bootstrap estimates is returned. Default depends on object. If bootstrap estimates were stored, then the default is "boot". Otherwise, the default is "lm".

...

Arguments to be passed to stats::vcov().

Value

A matrix of the variances and covariances of the parameter estimates.

Details

If bootstrapping was used to form the confidence intervals, users can request the variance-covariance matrix of the bootstrap estimates.

Examples

# Load a sample data set

dat <- test_x_1_w_1_v_1_cat1_n_500
head(dat)
#>         dv       iv       mod        v1 cat1
#> 1 4946.751 12.76737  96.85621 11.756899  gp1
#> 2 6635.081 14.89097 106.25696 11.371237  gp2
#> 3 6060.708 15.24101  97.85852  9.377471  gp2
#> 4 7240.781 16.65782 104.80266 10.508913  gp1
#> 5 5775.759 11.84448  95.85912 15.093480  gp3
#> 6 7725.783 16.31270 100.20561  3.442902  gp2

# Do a moderated regression by lm
lm_raw <- lm(dv ~ iv*mod + v1 + cat1, dat)

# Standardize all variables except for categorical variables.
# Interaction terms are formed after standardization.
lm_std <- std_selected(lm_raw, to_scale = ~ .,
                               to_center = ~ .)

# VCOV of lm output
vcov(lm_std)
#>               (Intercept)            iv           mod            v1
#> (Intercept)  2.328093e-03 -2.424492e-05 -4.453643e-05  5.904665e-07
#> iv          -2.424492e-05  7.487428e-04 -3.910411e-05 -1.570052e-06
#> mod         -4.453643e-05 -3.910411e-05  7.490437e-04  4.323374e-05
#> v1           5.904665e-07 -1.570052e-06  4.323374e-05  7.466559e-04
#> cat1gp2     -2.327318e-03 -5.104838e-06  9.054077e-05  3.534309e-05
#> cat1gp3     -2.327547e-03  7.491390e-05  2.729951e-05 -5.249772e-05
#> iv:mod      -3.979516e-05  5.489704e-05  4.037895e-05  4.206434e-05
#>                   cat1gp2       cat1gp3        iv:mod
#> (Intercept) -2.327318e-03 -2.327547e-03 -3.979516e-05
#> iv          -5.104838e-06  7.491390e-05  5.489704e-05
#> mod          9.054077e-05  2.729951e-05  4.037895e-05
#> v1           3.534309e-05 -5.249772e-05  4.206434e-05
#> cat1gp2      4.309522e-03  2.323477e-03 -1.319904e-06
#> cat1gp3      2.323477e-03  4.733274e-03  1.279117e-05
#> iv:mod      -1.319904e-06  1.279117e-05  6.477400e-04

# Standardize all variables as in std_selected above, and compute the
# nonparametric bootstrapping percentile confidence intervals.
lm_std_boot <- std_selected_boot(lm_raw,
                                 to_scale = ~ .,
                                 to_center = ~ .,
                                 conf = .95,
                                 nboot = 100)
# In real analysis, nboot should be at least 2000.

# VCOV of bootstrap estimates, default when bootstrap was conducted
vcov(lm_std_boot)
#>               (Intercept)            iv           mod            v1
#> (Intercept)  1.536489e-03  9.568250e-05 -1.095276e-04  0.0001865437
#> iv           9.568250e-05  4.146328e-04 -2.432351e-04  0.0000340697
#> mod         -1.095276e-04 -2.432351e-04  7.260336e-04  0.0001532043
#> v1           1.865437e-04  3.406970e-05  1.532043e-04  0.0010457165
#> cat1gp2     -2.410846e-03 -2.734371e-04  2.458697e-04 -0.0003150773
#> cat1gp3     -2.069590e-03  2.855683e-05  2.656795e-05 -0.0002051235
#> iv:mod       9.113406e-05  1.294361e-04 -1.132562e-04 -0.0001200609
#>                   cat1gp2       cat1gp3        iv:mod
#> (Intercept) -0.0024108465 -2.069590e-03  9.113406e-05
#> iv          -0.0002734371  2.855683e-05  1.294361e-04
#> mod          0.0002458697  2.656795e-05 -1.132562e-04
#> v1          -0.0003150773 -2.051235e-04 -1.200609e-04
#> cat1gp2      0.0045177085  2.407089e-03 -3.947109e-04
#> cat1gp3      0.0024070895  3.914567e-03  8.545288e-05
#> iv:mod      -0.0003947109  8.545288e-05  4.998478e-04

# For OLS VCOV
vcov(lm_std_boot, type = "lm")
#>               (Intercept)            iv           mod            v1
#> (Intercept)  2.328093e-03 -2.424492e-05 -4.453643e-05  5.904665e-07
#> iv          -2.424492e-05  7.487428e-04 -3.910411e-05 -1.570052e-06
#> mod         -4.453643e-05 -3.910411e-05  7.490437e-04  4.323374e-05
#> v1           5.904665e-07 -1.570052e-06  4.323374e-05  7.466559e-04
#> cat1gp2     -2.327318e-03 -5.104838e-06  9.054077e-05  3.534309e-05
#> cat1gp3     -2.327547e-03  7.491390e-05  2.729951e-05 -5.249772e-05
#> iv:mod      -3.979516e-05  5.489704e-05  4.037895e-05  4.206434e-05
#>                   cat1gp2       cat1gp3        iv:mod
#> (Intercept) -2.327318e-03 -2.327547e-03 -3.979516e-05
#> iv          -5.104838e-06  7.491390e-05  5.489704e-05
#> mod          9.054077e-05  2.729951e-05  4.037895e-05
#> v1           3.534309e-05 -5.249772e-05  4.206434e-05
#> cat1gp2      4.309522e-03  2.323477e-03 -1.319904e-06
#> cat1gp3      2.323477e-03  4.733274e-03  1.279117e-05
#> iv:mod      -1.319904e-06  1.279117e-05  6.477400e-04