Learn R Programming

insight (version 0.18.6)

get_varcov: Get variance-covariance matrix from models

Description

Returns the variance-covariance, as retrieved by stats::vcov(), but works for more model objects that probably don't provide a vcov()-method.

Usage

get_varcov(x, ...)

# S3 method for default get_varcov(x, verbose = TRUE, vcov = NULL, vcov_args = NULL, ...)

# S3 method for betareg get_varcov( x, component = c("conditional", "precision", "all"), verbose = TRUE, ... )

# S3 method for clm2 get_varcov(x, component = c("all", "conditional", "scale"), ...)

# S3 method for truncreg get_varcov(x, component = c("conditional", "all"), verbose = TRUE, ...)

# S3 method for hurdle get_varcov( x, component = c("conditional", "zero_inflated", "zi", "all"), vcov = NULL, vcov_args = NULL, verbose = TRUE, ... )

# S3 method for glmmTMB get_varcov( x, component = c("conditional", "zero_inflated", "zi", "dispersion", "all"), verbose = TRUE, ... )

# S3 method for MixMod get_varcov( x, effects = c("fixed", "random"), component = c("conditional", "zero_inflated", "zi", "dispersion", "auxiliary", "all"), verbose = TRUE, ... )

# S3 method for brmsfit get_varcov(x, component = "conditional", verbose = TRUE, ...)

# S3 method for betamfx get_varcov( x, component = c("conditional", "precision", "all"), verbose = TRUE, ... )

# S3 method for aov get_varcov(x, complete = FALSE, verbose = TRUE, ...)

# S3 method for mixor get_varcov(x, effects = c("all", "fixed", "random"), verbose = TRUE, ...)

Value

The variance-covariance matrix, as matrix-object.

Arguments

x

A model.

...

Currently not used.

verbose

Toggle warnings.

vcov

Variance-covariance matrix used to compute uncertainty estimates (e.g., for robust standard errors). This argument accepts a covariance matrix, a function which returns a covariance matrix, or a string which identifies the function to be used to compute the covariance matrix.

  • A covariance matrix

  • A function which returns a covariance matrix (e.g., stats::vcov())

  • A string which indicates the kind of uncertainty estimates to return.

    • Heteroskedasticity-consistent: "vcovHC", "HC", "HC0", "HC1", "HC2", "HC3", "HC4", "HC4m", "HC5". See ?sandwich::vcovHC

    • Cluster-robust: "vcovCR", "CR0", "CR1", "CR1p", "CR1S", "CR2", "CR3". See ?clubSandwich::vcovCR()

    • Bootstrap: "vcovBS", "xy", "residual", "wild", "mammen", "webb". See ?sandwich::vcovBS

    • Other sandwich package functions: "vcovHAC", "vcovPC", "vcovCL", "vcovPL".

vcov_args

List of arguments to be passed to the function identified by the vcov argument. This function is typically supplied by the sandwich or clubSandwich packages. Please refer to their documentation (e.g., ?sandwich::vcovHAC) to see the list of available arguments. If no estimation type (argument type) is given, the default type for "HC" (or "vcovHC") equals the default from the sandwich package; for type "CR" (or "vcoCR"), the default is set to "CR3".

component

Should the complete variance-covariance matrix of the model be returned, or only for specific model components only (like count or zero-inflated model parts)? Applies to models with zero-inflated component, or models with precision (e.g. betareg) component. component may be one of "conditional", "zi", "zero-inflated", "dispersion", "precision", or "all". May be abbreviated. Note that the conditional component is also called count or mean component, depending on the model.

effects

Should the complete variance-covariance matrix of the model be returned, or only for specific model parameters only? Currently only applies to models of class mixor.

complete

Logical, if TRUE, for aov, returns the full variance-covariance matrix.

Examples

Run this code
data(mtcars)
m <- lm(mpg ~ wt + cyl + vs, data = mtcars)
get_varcov(m)

# vcov of zero-inflation component from hurdle-model
if (require("pscl")) {
  data("bioChemists", package = "pscl")
  mod <- hurdle(art ~ phd + fem | ment, data = bioChemists, dist = "negbin")
  get_varcov(mod, component = "zero_inflated")
}

# robust vcov of, count component from hurdle-model
if (require("pscl") && require("sandwich")) {
  data("bioChemists", package = "pscl")
  mod <- hurdle(art ~ phd + fem | ment, data = bioChemists, dist = "negbin")
  get_varcov(
    mod,
    component = "conditional",
    vcov = "BS",
    vcov_args = list(R = 50)
  )
}

Run the code above in your browser using DataLab