plot_simu: Plotting Simulated Outcome

Description Usage Arguments Value Examples

Description

Plotting Simulated Outcome

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
plot_simu(
  predprof,
  name.x,
  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",
  label.x = "name.x",
  label.y = "auto",
  titletxt = NULL
)

Arguments

predprof

Predictions in either simupred (exported from simu_pred 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.x

Column name for the predictor to be on the x axis.

addprof

Optional data.frame that adds or replaces values of predictor. Must have the same number of cases as predprof. If variable name is found in predprof, values are replaced. If not, additional variable is added to predprof. Added variables can be used in name.x, 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 prediction 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.x. 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.x. 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.

label.x

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

label.y

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

titletxt

Title Text.

Value

ggplot object of simulated outcome plot.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
## 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
fm <- formula(voteBush ~ dem + rep +
                clintondis + bushdis +
                persfinance + natlecon)
m <- glm(fm, data = vote92,
         family = binomial("logit"))

## Comparing Partisans

# Profile
prof1 <- data.frame(dem=c(1,0,0),rep=c(0,0,1))

# Prediction (Missing Variables are Fixed at Mean/Mode)
predprof1 <- simu_pred(m, prof1, y.label = "Bush Vote")
summary(predprof1)

# Additional Profile to Give Labels
addprof1 <- data.frame(pid=c("Democrat","Independent","Republican"))
addprof1$pid <- factor(addprof1$pid, levels=unique(addprof1$pid))

# Plot 
plot_simu(predprof1, name.x="pid", addprof=addprof1, label.x = "Party ID")
# Change it to Point Graph
plot_simu(predprof1, name.x="pid", addprof=addprof1, 
          label.x = "Party ID", type.est = "point")

## Comparing Effects of Ideological Distance by Party ID

# Profile
prof2 <- data.frame(dem=rep(rep(c(1,0,0),each=50),2),
                    rep=rep(rep(c(0,0,1),each=50),2),
                    bushdis=c(rep(seq(0,4,length=50),3), 
                              rep(0.5,150)),
                    clintondis=c(rep(0.5,150), 
                                 rep(seq(0,4,length=50),3)))

# Prediction (Missing Variables are Fixed at Mean/Mode)
predprof2 <- simu_pred(m, prof2, y.label = "Bush Vote")
summary(predprof2)

# Additional Profile to Give Labels
addprof2 <- data.frame(pid=rep(c("Democrat","Independent","Republican"),each=50),
                       dis=rep(seq(0,4,length=50),6),
                       labdis=rep(c("Ideological Distance from Bush",
                                    "Ideological Distance from Clinton"),each=150))
addprof2$pid <- factor(addprof2$pid, levels=rev(unique(addprof2$pid)))

# Plot 
plot_simu(predprof2, name.x="dis", addprof=addprof2,
          name.facet.x = "labdis", name.linetype="pid",
          label.x = NULL, label.linetype="Party ID")
# Change Color of CIs
plot_simu(predprof2, name.x="dis", addprof=addprof2,
          name.facet.x = "labdis", name.linetype="pid", name.fill="pid",
          label.x = NULL, label.linetype="Party ID")

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