From b7a7d34ffe30b41030353dd3d7033c4dc298b6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sat, 11 May 2024 23:58:08 +1000 Subject: [PATCH] included tests for Gibbs sampler #2 --- DESCRIPTION | 6 +++- inst/tinytest/test_estimate_bvarpanel.R | 44 +++++++++++++++++++++++++ tests/tinytest.R | 7 ++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 inst/tinytest/test_estimate_bvarpanel.R create mode 100644 tests/tinytest.R diff --git a/DESCRIPTION b/DESCRIPTION index 171bf5e..e364d28 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,10 @@ Title: Forecasting with Bayesian Hierarchical Panel Vector Autoregressions Description: Forecasting a multi-country time series panel data using Bayesian Vector Autoregressions with a three-level country-global hierarchical prior structure. Version: 0.0.1.9000 Date: 2024-04-27 -Author: c(person(given="Tomasz", family="Woźniak", email="wozniak.tom@pm.me", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2212-2378")), person(given="Miguel", family="Sanchez-Martinez", role = "ctb"), person(given="International Labour Organization", role = "cph")) +Author: c(person(given="Tomasz", family="Woźniak", email="wozniak.tom@pm.me", role = + c("aut", "cre"), comment = c(ORCID = "0000-0003-2212-2378")), + person(given="Miguel", family="Sanchez-Martinez", role = "ctb"), + person(given="International Labour Organization", role = "cph")) Maintainer: Tomasz Woźniak License: GPL (>= 3) Depends: @@ -16,6 +19,7 @@ Imports: RcppProgress, RcppTN LinkingTo: bsvars, Rcpp, RcppArmadillo, RcppProgress, RcppTN +Suggests: tinytest LazyData: true Encoding: UTF-8 RoxygenNote: 7.3.1 diff --git a/inst/tinytest/test_estimate_bvarpanel.R b/inst/tinytest/test_estimate_bvarpanel.R new file mode 100644 index 0000000..3dd8fdd --- /dev/null +++ b/inst/tinytest/test_estimate_bvarpanel.R @@ -0,0 +1,44 @@ +data(ilo_cubic_panel) + +set.seed(1) +specification_no1 <- specify_bvarPANEL$new(ilo_cubic_panel) +run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) + +set.seed(1) +specification_no2 <- specify_bvarPANEL$new(ilo_cubic_panel) +run_no2 <- estimate(specification_no2, 3, 1, show_progress = FALSE) + +set.seed(1) +run_no3 <- ilo_cubic_panel |> + specify_bvarPANEL$new() |> + estimate(S = 3, thin = 1, show_progress = FALSE) + +expect_identical( + run_no1$last_draw$starting_values$A[1,1], + run_no2$last_draw$starting_values$A[1,1], + info = "estimate_bvarPANEL: the last_draw(s) of two runs to be identical." +) + +expect_identical( + run_no1$posterior$A[1,1,1], + run_no2$posterior$A[1,1,1], + info = "estimate_bvarPANEL: the first draws of two runs to be identical." +) + +expect_identical( + run_no1$last_draw$starting_values$A[1,1], + run_no3$last_draw$starting_values$A[1,1], + info = "estimate_bvarPANEL: the last_draw(s) of a normal and pipe run to be identical." +) + +# a test of a good setting of S and thin +expect_error( + estimate(specification_no1, 3, 2, show_progress = FALSE), + info = "Argument S is not a positive integer multiplication of argument thin." +) + +expect_error( + estimate(specification_no1, 2, 3, show_progress = FALSE), + info = "Argument S is not a positive integer multiplication of argument thin." +) + diff --git a/tests/tinytest.R b/tests/tinytest.R new file mode 100644 index 0000000..b1418c8 --- /dev/null +++ b/tests/tinytest.R @@ -0,0 +1,7 @@ + +if ( requireNamespace("tinytest", quietly=TRUE) ){ + # To skip running the tests on CRAN make them run only on the developer version + home <- length(unclass(packageVersion("bsvars"))[[1]]) == 4 + tinytest::test_package("bvarPANELs") +} +