Skip to content

Commit

Permalink
Merge pull request #25 from bsvars/21-truncated-normal-forecasts
Browse files Browse the repository at this point in the history
21 truncated normal forecasts
  • Loading branch information
donotdespair authored Sep 21, 2024
2 parents 0e8c35f + 3fe3ddc commit 499c634
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion R/bvarPANELs-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
#' specification = specify_bvarPANEL$new(
#' ilo_dynamic_panel,
#' exogenous = ilo_exogenous_variables,
#' type = c("real", rep("rates", 3))
#' type = c("real", rep("rate", 3))
#' )
#' burn_in = estimate(specification, S = 10) # run the burn-in; use say S = 10000
#' posterior = estimate(burn_in, S = 10) # estimate the model; use say S = 10000
Expand Down
10 changes: 5 additions & 5 deletions R/forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
#' of these exogenous variables in the argument \code{exogenous_forecast} of the
#' \code{\link{forecast.PosteriorBVARPANEL}} function.
#'
#' \strong{Truncated forecasts for variables of type 'rates'.}
#' \strong{Truncated forecasts for variables of type 'rate'.}
#' The package provides the option to truncate the forecasts for variables of
#' for which the corresponding element of argument \code{type} of the function
#' \code{specify_bvarPANEL$new()} is set to \code{"rates"}. The one-period-ahead
#' \code{specify_bvarPANEL$new()} is set to \code{"rate"}. The one-period-ahead
#' predictive normal density for such variables is truncated to values from
#' interval \eqn{[0,100]}.
#'
Expand Down Expand Up @@ -123,7 +123,7 @@
#' data(ilo_conditional_forecasts) # load the conditional forecasts of dgdp
#' specification = specify_bvarPANEL$new(
#' ilo_dynamic_panel,
#' type = c("real", rep("rates", 3))
#' type = c("real", rep("rate", 3))
#' ) # specify the model
#' burn_in = estimate(specification, 10) # run the burn-in; use say S = 10000
#' posterior = estimate(burn_in, 10) # estimate the model; use say S = 10000
Expand All @@ -134,7 +134,7 @@
#' ############################################################
#' set.seed(123)
#' ilo_dynamic_panel |>
#' specify_bvarPANEL$new(type = c("real", rep("rates", 3))) |>
#' specify_bvarPANEL$new(type = c("real", rep("rate", 3))) |>
#' estimate(S = 10) |>
#' estimate(S = 20) |>
#' forecast(
Expand Down Expand Up @@ -205,7 +205,7 @@ forecast.PosteriorBVARPANEL = function(
type = posterior$last_draw$data_matrices$type
LB = rep(-Inf, N)
UB = rep(Inf, N)
rates_id = which(type == "rates")
rates_id = which(type == "rate")
if (length(rates_id) > 0) {
LB[rates_id] = 0
UB[rates_id] = 100
Expand Down
10 changes: 5 additions & 5 deletions R/specify_bvarpanel.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ specify_panel_data_matrices = R6::R6Class(
#' regressors, \eqn{\mathbf{X}_c}.
X = list(),

#' @field type an \code{N} character vector with elements set to "rates" or "real"
#' @field type an \code{N} character vector with elements set to "rate" or "real"
#' determining the truncation of the predictive density to \code{[0, 100]} and
#' \code{(-Inf, Inf)} (no truncation) for each of the variables.
type = character(),
Expand All @@ -318,7 +318,7 @@ specify_panel_data_matrices = R6::R6Class(
#' @param exogenous a list containing \code{(T_c+p)xd} matrices with
#' country-specific of exogenous variables. This matrix should not include a
#' constant term.
#' @param type an \code{N} character vector with elements set to "rates" or "real"
#' @param type an \code{N} character vector with elements set to "rate" or "real"
#' determining the truncation of the predictive density to \code{[0, 100]} and
#' \code{(-Inf, Inf)} (no truncation) for each of the variables.
#' @return New data matrices DataMatricesBVARPANEL
Expand All @@ -332,8 +332,8 @@ specify_panel_data_matrices = R6::R6Class(
}
stopifnot("Argument p must be a positive integer number." = p > 0 & p %% 1 == 0)

stopifnot("Argument type must include elements 'rates' or 'real'."
= all(unique(type) %in% c("rates", "real")) )
stopifnot("Argument type must include elements 'rate' or 'real'."
= all(unique(type) %in% c("rate", "real")) )
stopifnot("Argument type must be of length corresponding to the numbers of variables."
= length(type) == ncol(data[[1]]) )

Expand Down Expand Up @@ -443,7 +443,7 @@ specify_bvarPANEL = R6::R6Class(
#' @param stationary an \code{N} logical vector - its element set to
#' \code{FALSE} sets the prior mean for the autoregressive parameters of the
#' \code{N}th equation to the white noise process, otherwise to random walk.
#' @param type an \code{N} character vector with elements set to "rates" or "real"
#' @param type an \code{N} character vector with elements set to "rate" or "real"
#' determining the truncation of the predictive density to \code{[0, 100]} and
#' \code{(-Inf, Inf)} (no truncation) for each of the variables.
#' @return A new complete specification for the Bayesian Panel VAR model BVARPANEL.
Expand Down
6 changes: 3 additions & 3 deletions inst/tinytest/test_forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,20 @@ expect_error(
# truncated forecasts

expect_identical(
class(specify_bvarPANEL$new(ilo_dynamic_panel, type = c("real",rep("rates",3))))[1],
class(specify_bvarPANEL$new(ilo_dynamic_panel, type = c("real",rep("rate",3))))[1],
"BVARPANEL",
info = "truncated forecast: good specification of argument type."
)

expect_error(
specify_bvarPANEL$new(ilo_dynamic_panel, type = rep("rates",3)),
specify_bvarPANEL$new(ilo_dynamic_panel, type = rep("rate",3)),
pattern = "length",
info = "truncated forecast: wrong specification of argument type."
)

set.seed(1)
suppressMessages(
specification_no1 <- specify_bvarPANEL$new(ilo_dynamic_panel, type = c("real",rep("rates",3)))
specification_no1 <- specify_bvarPANEL$new(ilo_dynamic_panel, type = c("real",rep("rate",3)))
)
run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE)
suppressMessages(
Expand Down
2 changes: 1 addition & 1 deletion man/bvarPANELs-package.Rd

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

8 changes: 4 additions & 4 deletions man/forecast.PosteriorBVARPANEL.Rd

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

2 changes: 1 addition & 1 deletion man/specify_bvarPANEL.Rd

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

4 changes: 2 additions & 2 deletions man/specify_panel_data_matrices.Rd

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

0 comments on commit 499c634

Please sign in to comment.