Last chance! 50% off unlimited learning
Sale ends in
dynsim
dynsimGG
uses ggplot2 to plot dynamic simulation results
created by dynsim
.
dynsimGG(
obj,
lsize = 1,
color,
alpha = 0.5,
xlab = "\nTime",
ylab = "Predicted Value\n",
title = "",
leg.name = "Scenario",
leg.labels,
legend = "legend",
shockplot.var,
shockplot.ylab,
shockplot.heights = c(12, 4),
shockplot.heights.units = c("cm", "cm")
)
a dynsim
class object.
size of the smoothing line. Default is 1. See ggplot2.
character string. Specifies the color of the lines and ribbons.
If only one scenario is to be plotted then it can either be a single color
value using any color value allowed by ggplot2. The default is
the hexadecimal color "#2B8CBE"
. If more than one scenario is to be
plotted then a color brewer palette is set. The default is"Set1"
. See
scale_colour_brewer
.
numeric. Alpha (e.g. transparency) for the ribbons. Default is
alpha = 0.1
. See ggplot2.
a label for the plot's x-axis.
a label of the plot's y-axis.
the plot's main title.
name of the legend (if applicable).
character vector specifying the labels for each scenario in the legend.
specifies what type of legend to include (if applicable). The
default is legend = "legend"
. To hide the legend use
legend = FALSE
. See discrete_scale
for more details.
character string naming the one shock variable to plot fitted values of over time specified underneath the main plot.
character string for the shockplot's y-axis label.
numeric vector with of length 2 with units of the main and shockplot height plots.
a character vector of length 2 with the
unit types for the values in shockplot.heights
.
See unit
for details.
Plots dynamic simulations of autoregressive relationships from
dynsim
. The central line is the mean of the simulation
distributions. The outer ribbon is the furthest extent of the simulation
distributions' central intervals found in dynsim
with the
sig
argument. The middle ribbons plot the limits of the simulation
distributions' central 50
# NOT RUN {
# Load package
library(DataCombine)
# Load Grunfeld data
data(grunfeld, package = "dynsim")
# Create lag invest variable
grunfeld <- slide(grunfeld, Var = "invest", GroupVar = "company",
NewVar = "InvestLag")
# Convert company to factor for fixed-effects specification
grunfeld$company <- as.factor(grunfeld$company)
# Estimate basic model
M1 <- lm(invest ~ InvestLag + mvalue + kstock + company, data = grunfeld)
# Set up scenarios for company 4
attach(grunfeld)
Scen1 <- data.frame(InvestLag = mean(InvestLag, na.rm = TRUE),
mvalue = quantile(mvalue, 0.05),
kstock = quantile(kstock, 0.05),
company4 = 1)
Scen2 <- data.frame(InvestLag = mean(InvestLag, na.rm = TRUE),
mvalue = mean(mvalue),
kstock = mean(kstock),
company4 = 1)
Scen3 <- data.frame(InvestLag = mean(InvestLag, na.rm = TRUE),
mvalue = quantile(mvalue, 0.95),
kstock = quantile(kstock, 0.95),
company4 = 1)
detach(grunfeld)
# Combine into a single list
ScenComb <- list(Scen1, Scen2, Scen3)
## Run dynamic simulations without shocks
Sim1 <- dynsim(obj = M1, ldv = "InvestLag", scen = ScenComb, n = 20)
# Create plot legend label
Labels <- c("5th Percentile", "Mean", "95th Percentile")
# Plot
dynsimGG(Sim1, leg.labels = Labels)
## Run dynamic simulations with shocks
# Create data frame of shock values
mShocks <- data.frame(times = c(5, 10), kstock = c(100, 1000))
# Run simulations
Sim2 <- dynsim(obj = M1, ldv = "InvestLag", scen = ScenComb, n = 20,
shocks = mShocks)
# Plot
dynsimGG(Sim2, leg.labels = Labels)
# Plot with accompanying shock plot
dynsimGG(Sim2, leg.labels = Labels, shockplot.var = "kstock")
# }
Run the code above in your browser using DataLab