Description Usage Arguments Value Examples
Plotting Simulated Outcome
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
)
|
predprof |
Predictions in either |
name.x |
Column name for the predictor to be on the x axis. |
addprof |
Optional |
name.est |
Column name for mean/median prediction estiamte. |
show.ci |
If |
name.lowerCI |
Column name for the upper limit of confidence interval (applied if |
name.upperCI |
Column name for the upper limit of confidence interval (applied if |
type.est |
Plotting type of estimates. If |
type.ci |
Plotting type of confidence intervals. If |
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 |
label.linetype |
Optional label if |
label.fill |
Optional label if |
label.shape |
Optional label if |
label.x |
X axis label. If |
label.y |
Y axis label. If |
titletxt |
Title Text. |
ggplot
object of simulated outcome plot.
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.