diff --git a/NAMESPACE b/NAMESPACE index 47ed488..b474671 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/summary.R b/R/summary.R index eda3f24..a552228 100644 --- a/R/summary.R +++ b/R/summary.R @@ -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]], ...) +} diff --git a/man/summary.PosteriorFEVDPANEL.Rd b/man/summary.PosteriorFEVDPANEL.Rd new file mode 100644 index 0000000..bee35ff --- /dev/null +++ b/man/summary.PosteriorFEVDPANEL.Rd @@ -0,0 +1,61 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/summary.R +\name{summary.PosteriorFEVDPANEL} +\alias{summary.PosteriorFEVDPANEL} +\title{Provides posterior summary of forecast error variance decompositions} +\usage{ +\method{summary}{PosteriorFEVDPANEL}(object, which_c, ...) +} +\arguments{ +\item{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.} + +\item{which_c}{a positive integer or a character string specifying the country +for which the forecast should be plotted.} + +\item{...}{additional arguments affecting the summary produced.} +} +\value{ +A list reporting the posterior mean of the forecast error variance +decompositions of each variable at all horizons. +} +\description{ +Provides posterior means of the forecast error variance +decompositions of each variable at all horizons. +} +\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") + +} +\seealso{ +\code{\link{compute_variance_decompositions.PosteriorBVARPANEL}}, \code{\link{plot}} +} +\author{ +Tomasz Woźniak \email{wozniak.tom@pm.me} +}