vcov.lm_betaselect: The 'vcov' Method for 'lm_betaselect' and 'glm_betaselect'...

View source: R/lm_betaselect_methods.R

vcov.lm_betaselectR Documentation

The 'vcov' Method for 'lm_betaselect' and glm_betaselect Objects

Description

Compute the variance-covariance matrix of estimates in the output of lm_betaselect() or glm_betaselect().

Usage

## S3 method for class 'lm_betaselect'
vcov(
  object,
  method = c("boot", "bootstrap", "ls", "default"),
  type = c("beta", "standardized", "raw", "unstandardized"),
  warn = TRUE,
  ...
)

## S3 method for class 'glm_betaselect'
vcov(
  object,
  method = c("boot", "bootstrap", "ls", "default"),
  type = c("beta", "standardized", "raw", "unstandardized"),
  warn = TRUE,
  ...
)

Arguments

object

The output of lm_betaselect() or an lm_betaselect-class object, or the output of glm_betaselect() or a glm_betaselect-class object.

method

The method used to compute the variance-covariance matrix. If bootstrapping was requested when calling lm_betaselect() or glm_betaselect() and this argument is set to "bootstrap" or "boot", the bootstrap variance-covariance matrix is returned. If bootstrapping was not requested or if this argument is set to "ls" or "default", then the usual lm or glm variance-covariance matrix is returned, with a warning raised unless type is "raw" or ⁠"unstandardized".⁠ Default is "boot".

type

String. If "unstandardized" or "raw", the variance-covariance matrix of the coefficients before standardization are returned. If "beta" or "standardized", then the variance-covariance matrix of the coefficients after selected variables standardized are returned. Default is "beta".

warn

Logical. WHether a warning will be raised is OLS (or WLS) variance-covariance matrix is requested for the model with some variables standardized (i.e., type is "beta" or "standardized"). Default is TRUE.

...

Other arguments to be passed to stats::vcov().

Details

The type of variance-covariance matrix depends on the object. If bootstrapping was requested, by default it returns the bootstrap variance-covariance matrix. Otherwise, it returns the default variance-covariance matrix and raises a warning.

Support for other type of variance-covariance matrix will be added.

Value

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

Author(s)

Shu Fai Cheung https://orcid.org/0000-0002-9871-9448

See Also

lm_betaselect() and glm_betaselect()

Examples


data(data_test_mod_cat)

# bootstrap should be set to 2000 or 5000 in real studies
lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1,
                           data = data_test_mod_cat,
                           to_standardize = "iv",
                           do_boot = TRUE,
                           bootstrap = 100,
                           iseed = 1234)
vcov(lm_beta_x)
# A warning is expected for the following call
vcov(lm_beta_x, method = "ls")
vcov(lm_beta_x, type = "raw")



data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1]
data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0,
                              yes = 1,
                              no = 0)
# bootstrap should be set to 2000 or 5000 in real studies
logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1,
                                  data = data_test_mod_cat,
                                  family = binomial,
                                  to_standardize = "iv",
                                  do_boot = TRUE,
                                  bootstrap = 100,
                                  iseed = 1234)
vcov(logistic_beta_x)
# A warning is expected for the following call
vcov(logistic_beta_x, method = "default")
vcov(logistic_beta_x, type = "raw")


betaselectr documentation built on April 3, 2025, 8:51 p.m.