Skip to content

Commit

Permalink
developed summary.PosteriorFEVDPANEL #17
Browse files Browse the repository at this point in the history
  • Loading branch information
donotdespair committed Jul 25, 2024
1 parent dadfa88 commit 9dca468
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ S3method(forecast,PosteriorBVARPANEL)
S3method(plot,ForecastsPANEL)
S3method(plot,PosteriorFEVDPANEL)
S3method(summary,PosteriorBVARPANEL)
S3method(summary,PosteriorFEVDPANEL)
export(specify_bvarPANEL)
export(specify_panel_data_matrices)
export(specify_posterior_bvarPANEL)
Expand Down
74 changes: 74 additions & 0 deletions R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,77 @@ summary.PosteriorBVARPANEL = function(

return(out)
} # END summary.PosteriorBVARPANEL






#' @title Provides posterior summary of forecast error variance decompositions
#'
#' @description Provides posterior means of the forecast error variance
#' decompositions of each variable at all horizons.
#'
#' @param object an object of class \code{PosteriorFEVDPANEL} obtained using the
#' \code{compute_variance_decompositions()} function containing draws from the
#' posterior distribution of the 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 ... additional arguments affecting the summary produced.
#'
#' @return A list reporting the posterior mean of the forecast error variance
#' decompositions of each variable at all horizons.
#'
#' @method summary PosteriorFEVDPANEL
#'
#' @seealso \code{\link{compute_variance_decompositions.PosteriorBVARPANEL}}, \code{\link{plot}}
#'
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me}
#'
#' @examples
#' # upload data
#' data(ilo_cubic_panel)
#'
#' # specify the model and set seed
#' set.seed(123)
#' specification = specify_bvarPANEL$new(ilo_cubic_panel, p = 1)
#'
#' # 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)
#' summary(fevd, which_c = "POL")
#'
#' # workflow with the pipe |>
#' ############################################################
#' set.seed(123)
#' ilo_cubic_panel |>
#' specify_bvarPANEL$new(p = 1) |>
#' estimate(S = 10) |>
#' estimate(S = 20) |>
#' compute_variance_decompositions(horizon = 4) |>
#' summary(which_c = "global")
#'
#' @export
summary.PosteriorFEVDPANEL = function(
object,
which_c,
...
) {

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(object))
} else if (is.character(which_c)) {
stopifnot("Argument which_c must be a character string indicating one of the countries."
= which_c %in% names(object))
} else {
stop("Argument which_c must be either a positive integer or a character string.")
}

summary(object[[which_c]], ...)
}
61 changes: 61 additions & 0 deletions man/summary.PosteriorFEVDPANEL.Rd

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

0 comments on commit 9dca468

Please sign in to comment.