I want to draw multiple error bands in a single plot.
Specifically, there should be drawn a plot from top to down upper95, upper 68, impulse response, lower 68, lower 95. However, it is impossible to calculate and suggest more than one as I know.
irf_result95 <- irf(structural, impulse = c("pcnt_hh_sa", "wti.ts", "opu.ts"), n.ahead = 20,
response = "pcnt_hh_sa",
cumulative = FALSE,
boot = TRUE, runs = 1000, ci = 0.95)
This is usual usage of irf function.
But what I wanna do is like below.(but it shows error if you use the code below)
irf_result95 <- irf(structural, impulse = c("pcnt_hh_sa", "wti.ts", "opu.ts"), n.ahead = 20,
response = "pcnt_hh_sa",
cumulative = FALSE,
boot = TRUE, runs = 1000, ci = c(0.68, 0.95)
Can anyone suggest a good method to draw a plot?
What I tried was the following codes, but it still doesn’t work.
irf_result68 <- irf(structural, impulse = c("pcnt_total_sa", "r_oilp", "opu_jo"), n.ahead = 36,
response = "pcnt_total_sa",
cumulative = TRUE,
boot = TRUE, runs = 1000, ci = 0.68)
irf_result95 <- irf(structural, impulse = c("pcnt_total_sa", "r_oilp", "opu_jo"), n.ahead = 36,
response = "pcnt_total_sa",
cumulative = TRUE,
boot = TRUE, runs = 1000, ci = 0.95)
irf_df <- bind_rows(lapply(vars, function(var) {
bind_rows(
data.frame(
period = 1:length(irf_result95$irf[[var]]),
shock = var,
type = "irf95",
val = irf_result95$irf[[var]]
),
data.frame(
period = 1:length(irf_result95$Lower[[var]]),
shock = var,
type = "lower95",
val = irf_result95$Lower[[var]]
),
data.frame(
period = 1:length(irf_result95$Upper[[var]]),
shock = var,
type = "upper95",
val = irf_result95$Upper[[var]]
),
data.frame(
period = 1:length(irf_result68$irf[[var]]),
shock = var,
type = "irf68",
val = irf_result95$irf[[var]]
),
data.frame(
period = 1:length(irf_result68$Lower[[var]]),
shock = var,
type = "lower68",
val = irf_result95$Lower[[var]]
),
data.frame(
period = 1:length(irf_result68$Upper[[var]]),
shock = var,
type = "upper68",
val = irf_result95$Upper[[var]]
)
)
}))
ggplot(irf_df, aes(x = period, y = pcnt_total_sa, color = shock, linetype = type)) +
geom_line(size = 0.1) +
facet_wrap(~shock, ncol = 3, labeller = labeller(shock = c(`opu_jo`="Oil Price Uncertainty",
`energy_sa`="Emission",
`wti.ts`="WTI"))) +
labs(
x = "shocks",
y = "Impulse Response of total emission",
color = "Shock",
linetype = "Type",
) +
scale_color_manual(values = c("blue", "green", "red"),
labels = c("WTI", "Emission", "Oil price")) +
theme_bw()+
theme(legend.position = "none")
I tried the things attached above.