simu_interact: Simulate conditional effect from models with interaction...

Description Usage Arguments Value Examples

View source: R/simu_interact.R

Description

Compute interaction effects through Monte-Carlo Simulation. Wrapper function of simu_pred.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
simu_interact(
  m,
  var1,
  var1.label = NULL,
  moveprof = NULL,
  var2 = NULL,
  steps = 100,
  y.label = "auto",
  show.ci = TRUE,
  level.ci = 0.95,
  vcov.est = NULL,
  robust.type = "HC1",
  cluster.var = NULL,
  iterate.num = 1000,
  iterate.seed = 578,
  rawbeta = NULL,
  ...
)

Arguments

m

Single model object.

var1

Variable of coeffcients to be simulated.

var1.label

Text label for var1 (optional).

moveprof

Data.frame object that specifies moving values for variables included in interaction terms other than var1. The first variable in data.frame is considered as the primary variable for simulation. All variables not included in moveprof are assumed not to be interacted. Alternatively, you can specify var2 if only two variables are interacted in the model and you want to simulate coefficients for full range of values for the second variable. (Note: You must give one of moveprof and var2).

var2

Character for the second variable name in interaction term. Must be given is moveprof is NULL.

steps

Maximum number of values to be simulated. (Applied if var2 is not NULL and moveprof is NULL).

y.label

The label of the dependent variable (optional, character).

show.ci

Show confidence interval (boulean). The default is TRUE.

level.ci

The level used for confidence interval (numeric: 0-1). The default is 0.95.

vcov.est

Variance-covariance matrix to draw coefficents. If "robust", use robust variance-covariance matrix (also see robust.type). If "cluster", use cluster robust variance-covariance matrix (also see cluster.var). If "boot", draw beta by non-parametric bootstrap method using Boot function. If "rawbeta", use pre-simulated beta given in rawbeta argument. If NULL (default), use the standard variance covariance matrix stored the model. You can also directly set the variance-covariance matrix created by vcov() or vcovHC().

robust.type

The type of leverage adjustment passed to vcovHC (applied only when vcov.est=="robust").

cluster.var

A vector, matrix, or data.frame of cluster variables, where each column is a separate variable. Alternatively, a formula specifying the cluster variables to be used (see Details in cluster.vcov. Applied only when vcov.est=="cluster".)

iterate.num

The number of iteration in simulation.

iterate.seed

The seed value for random number generator used for the draws from multivariate normal distribution.

rawbeta

The matrix of pre-simulated beta. Columns are variables, raws are simulated cases. Used only when vcov.est=="rawbeta".

...

Additional arguments passed to vcovHC, cluster.vcov, or Boot depending on the value of vcov.est.

Value

A list of:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Load Data
library(pscl)
data(vote92)

## Recode Variables
vote92$voteBush <- as.numeric(
factor(vote92$vote,levels=c("Clinton","Bush")))*1 - 1
vote92$bushdis <- sqrt(vote92$bushdis)
vote92$clintondis <- sqrt(vote92$clintondis)

## Estimate Logistic Regression with Interaction
fm <- formula(voteBush ~ dem*clintondis + 
                rep + bushdis +
                persfinance + natlecon)
m <- glm(fm, data = vote92,
         family = binomial("logit"))
         
# Moving Values
moveprof <- data.frame(clintondis = seq(0,4,length=50))
# Simulation
interactprof <- simu_interact(m, "dem", moveprof=moveprof,
                              var1.label = "Being Democrat",
                              y.label = "Bush Vote")
# Plot
plot_interact(interactprof, 
              label.var2="Ideological Distance from Clinton")

# Alternative Way
interactprof <- simu_interact(m, "dem", var2 = "clintondis",
                              var1.label = "Being Democrat",
                              y.label = "Bush Vote")
plot_interact(interactprof,
              label.var2="Ideological Distance from Clinton")

gentok/estvis documentation built on April 2, 2020, 1:58 p.m.