Learn R Programming

marginaleffects (version 0.29.0)

get_vcov: Get a named variance-covariance matrix from a model object

Description

Mostly for internal use, but can be useful because the output is consistent across model classes.

Usage

get_vcov(model, ...)

# S3 method for default get_vcov(model, vcov = NULL, ...)

# S3 method for MCMCglmm get_vcov(model, vcov = NULL, ...)

# S3 method for afex_aov get_vcov(model, vcov = NULL, ...)

# S3 method for glimML get_vcov(model, vcov = NULL, ...)

# S3 method for biglm get_vcov(model, vcov = NULL, ...)

# S3 method for brmsfit get_vcov(model, vcov = NULL, ...)

# S3 method for bart get_vcov(model, vcov = NULL, ...)

# S3 method for gamlss get_vcov(model, ...)

# S3 method for glmmTMB get_vcov(model, vcov, ...)

# S3 method for mhurdle get_vcov(model, vcov = NULL, ...)

# S3 method for Learner get_vcov(model, ...)

# S3 method for orm get_vcov(model, vcov = NULL, ...)

# S3 method for stpm2 get_vcov(model, ...)

# S3 method for pstpm2 get_vcov(model, ...)

# S3 method for gsm get_vcov(model, ...)

# S3 method for aft get_vcov(model, ...)

# S3 method for scam get_vcov(model, vcov = NULL, ...)

# S3 method for systemfit get_vcov(model, ...)

# S3 method for systemfit get_predict(model, newdata = NULL, type = NULL, ...)

# S3 method for model_fit get_vcov(model, vcov, type = NULL, ...)

# S3 method for workflow get_vcov(model, vcov, type = NULL, ...)

Value

A named square matrix of variance and covariances. The names must match the coefficient names.

Arguments

model

Model object

...

Additional arguments are passed to the predict() method supplied by the modeling package.These arguments are particularly useful for mixed-effects or bayesian models (see the online vignettes on the marginaleffects website). Available arguments can vary from model to model, depending on the range of supported arguments by each modeling package. See the "Model-Specific Arguments" section of the ?slopes documentation for a non-exhaustive list of available arguments.

vcov

Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values:

  • FALSE: Do not compute standard errors. This can speed up computation considerably.

  • TRUE: Unit-level standard errors using the default vcov(model) variance-covariance matrix.

  • String which indicates the kind of uncertainty estimates to return.

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

    • Heteroskedasticity and autocorrelation consistent: "HAC"

    • Mixed-Models degrees of freedom: "satterthwaite", "kenward-roger"

    • Other: "NeweyWest", "KernHAC", "OPG". See the sandwich package documentation.

    • "rsample", "boot", "fwb", and "simulation" are passed to the method argument of the inferences() function. To customize the bootstrap or simulation process, call inferences() directly.

  • One-sided formula which indicates the name of cluster variables (e.g., ~unit_id). This formula is passed to the cluster argument of the sandwich::vcovCL function.

  • Square covariance matrix

  • Function which returns a covariance matrix (e.g., stats::vcov(model))

newdata

Grid of predictor values at which we evaluate the slopes.

  • Warning: Please avoid modifying your dataset between fitting the model and calling a marginaleffects function. This can sometimes lead to unexpected results.

  • NULL (default): Unit-level slopes for each observed value in the dataset (empirical distribution). The dataset is retrieved using insight::get_data(), which tries to extract data from the environment. This may produce unexpected results if the original data frame has been altered since fitting the model.

  • datagrid() call to specify a custom grid of regressors. For example:

    • newdata = datagrid(cyl = c(4, 6)): cyl variable equal to 4 and 6 and other regressors fixed at their means or modes.

    • See the Examples section and the datagrid() documentation.

  • subset() call with a single argument to select a subset of the dataset used to fit the model, ex: newdata = subset(treatment == 1)

  • dplyr::filter() call with a single argument to select a subset of the dataset used to fit the model, ex: newdata = filter(treatment == 1)

  • string:

    • "mean": Slopes evaluated when each predictor is held at its mean or mode.

    • "median": Slopes evaluated when each predictor is held at its median or mode.

    • "balanced": Slopes evaluated on a balanced grid with every combination of categories and numeric variables held at their means.

    • "tukey": Slopes evaluated at Tukey's 5 numbers.

    • "grid": Slopes evaluated on a grid of representative numbers (Tukey's 5 numbers and unique values of categorical predictors).

type

string indicates the type (scale) of the predictions used to compute contrasts or slopes. This can differ based on the model type, but will typically be a string such as: "response", "link", "probs", or "zero". When an unsupported string is entered, the model-specific list of acceptable values is returned in an error message. When type is NULL, the first entry in the error message is used by default.