Plot dynamic simulation results from dynsim

Description

dynsimGG uses ggplot2 to plot dynamic simulation results created by dynsim.

Usage

1
2
3
4
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"))

Arguments

obj

a dynsim class object.

lsize

size of the smoothing line. Default is 1. See ggplot2.

color

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.

alpha

numeric. Alpha (e.g. transparency) for the ribbons. Default is alpha = 0.1. See ggplot2.

xlab

a label for the plot's x-axis.

ylab

a label of the plot's y-axis.

title

the plot's main title.

leg.name

name of the legend (if applicable).

leg.labels

character vector specifying the labels for each scenario in the legend.

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.

shockplot.var

character string naming the one shock variable to plot fitted values of over time specified underneath the main plot.

shockplot.ylab

character string for the shockplot's y-axis label.

shockplot.heights

numeric vector with of length 2 with units of the main and shockplot height plots.

shockplot.heights.units

a character vector of length 2 with the unit types for the values in shockplot.heights. See unit for details.

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

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
# 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")

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.