model_vcov: Compute model variance-covariance matrix

Description Usage Arguments Details Value See Also Examples

View source: R/model_vcov.r

Description

The function model_vcov computes a variance-covariance matrix for a linear regression model. The user can provide a cluster variable to cluster the variance-covariance matrix and can select to use bootstraping for clustering. The output can serve as input for the model_summary and plot_interaction functions.

Usage

1
  model_vcov(model, type, var_cluster)

Arguments

model

Linear regression model for which the variance-covariance matrix is to be computed, requires class "lm" or "glm"

type

Indicator which type of variance-covariance matrix is to be computed: 0 - no clustering, 1 - clustering using var_cluster, 2 - clustering using var_cluster with bootstraping

var_cluster

Vector, matrix, or data.frame containing the variables that are used for clustering

Details

The option type == 0 uses vcov from the base package. When type == 1 is selected, the variance-covariance matrix is computed using the cluster.vcov command from the multiwayvcov package: multiwayvcov::cluster.vcov(model, var_cluster). For type == 2, the variance-covariance matrix is computed using the cluster.boot command from the multiwayvcov package: multiwayvcov::cluster.boot(model, var_cluster, R = 1000, boot_type = "wild", wild_type = function() sample(c(-1, 1), 1)).

Value

A list of class ("mod_vcov" "list") containing two items:

model

The linear regression model supplied as input

vcov_mat

A variance-covariance matrix for the linear regression model supplied in the function

For output's attributes depend on the type selected in the function call:

type == 0

The attribute "type" is set to "standard"

type == 1

The attribute "type" is set to "robust", the attribute "var_cluster" takes the value supplied as variable var_cluster

type == 2

The attribute "type" is set to "robust_boot", the attribute "var_cluster" takes the value supplied as variable var_cluster

See Also

cluster.vcov, cluster.boot

Examples

1
2
3
4
5
6
7
8
  data <- supportR::create_data()

  mod1 <- lm(firm_value ~ profit + cogs + rnd + competition * board_size, data = data)
  model_vcov(model = mod1, type = 0, var_cluster = NULL)
  model_vcov(model = mod1, type = 1, var_cluster = data$country)

  mod2 <- glm(female_ceo ~ profit + cogs + rnd + ceo_age * board_size, data = data, family = "binomial")
  model_vcov(model = mod2, type = 2, var_cluster = data$industry)

ha-pu/supportR documentation built on Sept. 13, 2020, 5:52 p.m.