Skip to content

Commit

Permalink
developed plot.PosteriorFEVDPANEL #17
Browse files Browse the repository at this point in the history
  • Loading branch information
donotdespair committed Jul 20, 2024
1 parent 065470f commit 7980a0e
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 7 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ S3method(estimate,BVARPANEL)
S3method(estimate,PosteriorBVARPANEL)
S3method(forecast,PosteriorBVARPANEL)
S3method(plot,ForecastsPANEL)
S3method(plot,PosteriorFEVDPANEL)
export(specify_bvarPANEL)
export(specify_panel_data_matrices)
export(specify_posterior_bvarPANEL)
Expand Down
100 changes: 94 additions & 6 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @description Plots of fitted values of dependent variables including their
#' median and percentiles.
#'
#' @param x an object of class Forecasts obtained using the
#' @param x an object of class \code{ForecastsPANEL} obtained using the
#' \code{forecast()} function containing posterior draws of
#' fitted values of dependent variables.
#' @param which_c a positive integer or a character string specifying the country
Expand All @@ -31,6 +31,7 @@
#' specification = specify_bvarPANEL$new(ilo_cubic_panel) # specify the model
#' burn_in = estimate(specification, 10) # run the burn-in
#' posterior = estimate(burn_in, 10) # estimate the model
#'
#' # forecast 6 years ahead
#' predictive = forecast(posterior, 6, conditional_forecast = ilo_conditional_forecasts)
#' plot(predictive, which_c = "POL") # plot forecasts
Expand Down Expand Up @@ -71,13 +72,100 @@ plot.ForecastsPANEL = function(

plot(
x[[which_c]],
probability = 0.9,
data_in_plot = 1,
col = "#ff69b4",
probability,
data_in_plot,
col,
main,
xlab,
mar.multi = c(1, 4.6, 0, 2.1),
mar.multi,
oma.multi,
...
)
} # END plot.ForecastsPANEL








#' @title Plots forecast error variance decompositions
#'
#' @description Plots of the posterior means of the forecast error variance
#' decompositions.
#'
#' @param x an object of class \code{PosteriorFEVDPANEL} obtained using the
#' \code{compute_variance_decompositions()} function containing posterior draws of
#' forecast error variance decompositions.
#' @param which_c a positive integer or a character string specifying the country
#' for which the forecast should be plotted.
#' @param cols an \code{N}-vector with colours of the plot
#' @param main an alternative main title for the plot
#' @param xlab an alternative x-axis label for the plot
#' @param mar.multi the default \code{mar} argument setting in \code{graphics::par}. Modify with care!
#' @param oma.multi the default \code{oma} argument setting in \code{graphics::par}. Modify with care!
#' @param ... additional arguments affecting the summary produced.
#'
#' @method plot PosteriorFEVDPANEL
#'
#' @seealso \code{\link{compute_variance_decompositions.PosteriorBVARPANEL}}
#'
#' @author Tomasz Woźniak \email{[email protected]}
#'
#' @examples
#' set.seed(123)
#' specification = specify_bvarPANEL$new(ilo_cubic_panel)
#'
#' # run the burn-in
#' burn_in = estimate(specification, 10)
#'
#' # estimate the model
#' posterior = estimate(burn_in, 20)
#'
#' # compute forecast error variance decomposition 4 years ahead
#' fevd = compute_variance_decompositions(posterior, horizon = 4)
#' plot(fevd, which_c = "POL")
#'
#' # workflow with the pipe |>
#' ############################################################
#' set.seed(123)
#' ilo_cubic_panel |>
#' specify_bvarPANEL$new() |>
#' estimate(S = 10) |>
#' estimate(S = 20) |>
#' compute_variance_decompositions(horizon = 4) |>
#' plot(which_c = "POL")
#'
#' @export
plot.PosteriorFEVDPANEL = function(
x,
which_c,
cols,
main,
xlab,
mar.multi = c(1, 4.6, 0, 4.6),
oma.multi = c(6, 0, 5, 0),
...
) {

if (is.numeric(which_c)) {
stopifnot("Argument which_c must be a positive integer indicating one of the countries."
= length(which_c) == 1 & which_c %% 1 == 0 & which_c > 0 & which_c <= length(x))
} else if (is.character(which_c)) {
stopifnot("Argument which_c must be a character string indicating one of the countries."
= which_c %in% names(x))
} else {
stop("Argument which_c must be either a positive integer or a character string.")
}

plot(
x[[which_c]],
cols,
main,
xlab,
mar.multi,
oma.multi,
...
)
}
} # END plot.PosteriorFEVDPANEL
3 changes: 2 additions & 1 deletion man/plot.ForecastsPANEL.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions man/plot.PosteriorFEVDPANEL.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7980a0e

Please sign in to comment.