Simulate coefficients from a GLM by making draws from the multivariate normal distribution

Share:

Description

Simulate coefficients from a GLM by making draws from the multivariate normal distribution

Usage

1
b_sim(obj, mu, Sigma, nsim = 1000)

Arguments

obj

a fitted model object.

mu

an optional vector giving the means of the variables. If obj is supplied then mu is ignored.

Sigma

an optional positive-definite symmetric matrix specifying the covariance matrix of the variables. If obj is supplied then Sigma is ignored. If your model includes an intercept, this should be given the name intercept_.

nsim

number of simulations to draw.

Value

A data frame of simulated coefficients from obj.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(car)

# Estimate model
m1 <- lm(prestige ~ education + type, data = Prestige)

# Create fitted values
prestige_sims <- b_sim(m1)

# Manually supply coefficient means and covariance matrix
coefs <- coef(m1)
vcov_matrix <- vcov(m1)

prestige_sims_manual <- b_sim(mu = coefs, Sigma = vcov_matrix)