plot_interact: Plot Interaction Effects

Description Usage Arguments Value Examples

View source: R/simu_interact.R

Description

Drawing interaction plot. This function is a wrapper for plot_simu function.

Usage

 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
plot_interact(
  interactprof,
  name.var2 = NULL,
  label.var2 = "name.var2",
  label.y = "auto",
  hline0 = TRUE,
  addprof = NULL,
  name.est = "Mean",
  show.ci = TRUE,
  name.lowerCI = "lowerCI",
  name.upperCI = "upperCI",
  type.est = "auto",
  type.ci = "auto",
  name.facet.x = NULL,
  name.facet.y = NULL,
  name.color = NULL,
  name.linetype = NULL,
  name.fill = NULL,
  name.shape = NULL,
  line.width = 0.7,
  barpoint.gapwidth = 0.5,
  point.size = 2,
  errorbar.width = 0.5,
  ribbon.alpha = 0.5,
  label.color = "name.color",
  label.linetype = "name.linetype",
  label.fill = "name.fill",
  label.shape = "name.shape",
  titletxt = NULL
)

Arguments

interactprof

Conditional coefficients in either simuinteract (exported from simu_interact function), data.frame or matrix class. If in data.frame or matrix, it should have rows as predcion cases and columns for mean/median prediction, lower and upper confidence intervals (if show.ci==TRUE), and values for predictors that varies across profiles.

name.var2

Column name for the main variable that conditions the coeffient of target variable (plotted on x axis). If not given, the information will be extracted from interactprof (only when it is simuinteract object).

label.var2

X axis label. If "name.var2" (default), use the variable name defined in name.var2.

label.y

Y axis label. If "auto" (default) and interactprof being simuinteract object, the label is automatically determined.

hline0

If TRUE, add horizontal line at the value of zero.

addprof

Optional data.frame that adds or replaces values of conditions. Must have the same number of cases as interactprof. If variable name is found in interactprof, values are replaced. If not, additional variable is added to interactprof. Added variables can be used in name.var2, name.color, name.linetype, name.fill, and name.shape. Define variable as factor if you want to control order of appearance in legend.

name.est

Column name for mean/median conditional coefficient estiamte.

show.ci

If TRUE (default), plot confidence intervals.

name.lowerCI

Column name for the upper limit of confidence interval (applied if show.ci==TRUE).

name.upperCI

Column name for the upper limit of confidence interval (applied if show.ci==TRUE).

type.est

Plotting type of estimates. If "auto", the type is determined automatically chosen by the class of the variable defined by name.var2. If not, choose manually from "line", "bar", or "point".

type.ci

Plotting type of confidence intervals. If "auto", the type is determined automatically chosen by the class of the variable defined by name.var2. If not, choose manually from "errorbar" (Error Bars) or "ribbon" (Appropriate if type.est == "line").

name.facet.x

Column name for the predictor that controls facets horizontally (optional).

name.facet.y

Column name for the predictor that controls facets vertically (optional).

name.color

Column name for the predictor that controls line colors (optional).

name.linetype

COlumn name for the predictor that controls line types (optional).

name.fill

Column name for the predictor that controls fill colors (optional).

name.shape

Column name for the predictor that controls point shapes (optional).

line.width

The width of line in line plot.

barpoint.gapwidth

The gap between bars/points if plot is clustered.

point.size

The size of points in point plot.

errorbar.width

The width of errorbar.

ribbon.alpha

The transparency of ribbon plot.

label.color

Optional label if name.color==TRUE. If "name.color", the value assigned to name.color will be used for name in legend.

label.linetype

Optional label if name.linetype==TRUE. If "name.linetype", the value assigned to name.linetype will be used for name in legend.

label.fill

Optional label if name.fill==TRUE. If "name.fill", the value assigned to name.fill will be used for name in legend.

label.shape

Optional label if name.shape==TRUE. If "name.shape", the value assigned to name.shape will be used for name in legend.

titletxt

Title Text.

Value

ggplot object (axis and theme settings can be added later).

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.