From 8402c6f23311694c14f1e7fa2563f3bc2a7c2482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sat, 29 Jun 2024 18:58:02 +1000 Subject: [PATCH 01/11] change name from ilo_conditiona_forecast to ilo_conditional_forecasts #12 #3 --- R/forecast.R | 6 +++--- ...al_forecast.R => ilo_conditional_forecasts.R} | 6 +++--- data/ilo_conditional_forecast.rda | Bin 5956 -> 0 bytes data/ilo_conditional_forecasts.rda | Bin 0 -> 5957 bytes inst/tinytest/test_forecast.R | 10 +++++----- ...al_forecast.R => ilo_conditional_forecasts.R} | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) rename R/{ilo_conditional_forecast.R => ilo_conditional_forecasts.R} (89%) delete mode 100644 data/ilo_conditional_forecast.rda create mode 100644 data/ilo_conditional_forecasts.rda rename inst/varia/{ilo_conditional_forecast.R => ilo_conditional_forecasts.R} (75%) diff --git a/R/forecast.R b/R/forecast.R index 9063b6f..b405207 100644 --- a/R/forecast.R +++ b/R/forecast.R @@ -49,8 +49,8 @@ #' # provided future values for the Gross Domestic Product #' # growth rate #' ############################################################ -#' #' data(ilo_conditional_forecast) # load the conditional forecasts of dgdp -#' predictive = forecast(posterior, 6, conditional_forecast = ilo_conditional_forecast) +#' #' data(ilo_conditional_forecasts) # load the conditional forecasts of dgdp +#' predictive = forecast(posterior, 6, conditional_forecast = ilo_conditional_forecasts) #' #' # workflow with the pipe |> #' ############################################################ @@ -61,7 +61,7 @@ #' estimate(S = 20) |> #' forecast( #' horizon = 6, -#' conditional_forecast = ilo_conditional_forecast +#' conditional_forecast = ilo_conditional_forecasts #' ) -> predictive #' #' @export diff --git a/R/ilo_conditional_forecast.R b/R/ilo_conditional_forecasts.R similarity index 89% rename from R/ilo_conditional_forecast.R rename to R/ilo_conditional_forecasts.R index a416393..bf728d7 100644 --- a/R/ilo_conditional_forecast.R +++ b/R/ilo_conditional_forecasts.R @@ -7,7 +7,7 @@ #' conditional forecasts of labour market outcomes given the provided projected #' paths of output. Last data update was implemented on 2024-05-11. #' -#' @usage data(ilo_conditional_forecast) +#' @usage data(ilo_conditional_forecasts) #' #' @format A list of 189 \code{ts} objects with time series of 6 observations #' on 4 variables: @@ -24,6 +24,6 @@ #' ILOSTAT [database]. Available from \url{https://ilostat.ilo.org/data/}. #' #' @examples -#' data(ilo_conditional_forecast) # upload the data +#' data(ilo_conditional_forecasts) # upload the data #' -"ilo_conditional_forecast" \ No newline at end of file +"ilo_conditional_forecasts" \ No newline at end of file diff --git a/data/ilo_conditional_forecast.rda b/data/ilo_conditional_forecast.rda deleted file mode 100644 index 2449300d55b470514a98e644a787a9cfc8febaa9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5956 zcmXX}cRbYpACE|`3vt9ZJLAsC%!or|Zzr;IcJ|&QSsi7DvW1JRQ)brTvd7^fduL{y z5#e{&H~=bJ75=Cyy{^_`sHfTy^3?Zcs~a;Y;8Ua1kB29HZ^ z(DjZd0ChD*)~K1RYo*jQAOYc9QiI?|P7XTsXQ zHF&Yx|4`6M({BKUe3m|u6TDc{Y$VJ(Hs&xO=dihLGFCF2B^Uf7jpR!J+=stzh~PIqLZzK2^Z4 z*q<8!a!fk5w7-%mz!1CYZttvn%lNxPwJNXAlhxUsb5K}Q*kSA`=} zawTV3V>fEAdUjYq?$Gh(Nr>q38Dd^xC8KjTc`7{iZ+qOwy1^?kIY$3^JY4qx8DZFN`v;XT5 zPZhhaB+Zr4d=oVp?aj*il@;#IR$+?TmuEjV!q3D^_$mH9_cLxxD_~68I=C_8F7K)q zwDiTT5k(1~H7jG&vZRXcmXW79)jj`Z=P_NLdww?tUWhE}q}RN=7D{apfTX#aP9ZEV zboTn=%RAwEZA(kF^HqFM+?Exav;@+!y*6;~Gn+2!ZMR_1^nP#*oV3s0Y`7`}ww<%S zPK7#ma(Kiu`WR*ityI%; z+S6*7R}3vyF({W(kQqUH4?nZhb|HML^e~4_?MmsOCc7-w#|2>h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_b0rtA10x#(U zmbKos^>+_*`(yR}9vs}issB} zQamaP?G&6DUg0Rrf+>ByNa3u%#YfnK>1>JHu|~0=Os$emYdh^+*`jLJ#BZ;U9EjUp ziPAcyvoDbPcDmkL9@C9%Vs2Jl$e+QPvmeyAM&85 zx&&7}x=JiN^{Eh_z;3GAn$-l2>ulMmm$BS9va4k8<@#`v_4FW`8liMQ)wRXO;Jh`)(diiPg bCM`9qked5P$BuzRXDthk6sOpSWLN$N@eq|s literal 0 HcmV?d00001 diff --git a/inst/tinytest/test_forecast.R b/inst/tinytest/test_forecast.R index 2d2750b..0791110 100644 --- a/inst/tinytest/test_forecast.R +++ b/inst/tinytest/test_forecast.R @@ -41,21 +41,21 @@ expect_error( # conditional forecasting -data(ilo_conditional_forecast) +data(ilo_conditional_forecasts) set.seed(1) suppressMessages( specification_no1 <- specify_bvarPANEL$new(ilo_cubic_panel) ) run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) -ff <- forecast(run_no1, 6, conditional_forecast = ilo_conditional_forecast) +ff <- forecast(run_no1, 6, conditional_forecast = ilo_conditional_forecasts) set.seed(1) suppressMessages( ff2 <- ilo_cubic_panel |> specify_bvarPANEL$new() |> estimate(S = 3, thin = 1, show_progress = FALSE) |> - forecast(horizon = 6, conditional_forecast = ilo_conditional_forecast) + forecast(horizon = 6, conditional_forecast = ilo_conditional_forecasts) ) @@ -70,13 +70,13 @@ expect_true( ) expect_error( - forecast(run_no1, horizon = 4, conditional_forecast = ilo_conditional_forecast), + forecast(run_no1, horizon = 4, conditional_forecast = ilo_conditional_forecasts), pattern = "horizon", info = "conditional forecast: provided forecasts different from horizon." ) expect_error( - forecast(run_no1, horizon = 6, conditional_forecast = ilo_conditional_forecast[-1]), + forecast(run_no1, horizon = 6, conditional_forecast = ilo_conditional_forecasts[-1]), info = "conditional forecast: uneven number of countries in forecasts and data." ) diff --git a/inst/varia/ilo_conditional_forecast.R b/inst/varia/ilo_conditional_forecasts.R similarity index 75% rename from inst/varia/ilo_conditional_forecast.R rename to inst/varia/ilo_conditional_forecasts.R index 60106fd..49d6df6 100644 --- a/inst/varia/ilo_conditional_forecast.R +++ b/inst/varia/ilo_conditional_forecasts.R @@ -14,13 +14,13 @@ data_cv <- all_cv %>% # Create a list with the country data countries = unique(data_cv$iso3code) countries = countries[order(countries)] -ilo_conditional_forecast = list() +ilo_conditional_forecasts = list() for (i in 1:length(countries)) { - ilo_conditional_forecast[[i]] <- data_cv %>% + ilo_conditional_forecasts[[i]] <- data_cv %>% filter(iso3code == countries[i]) %>% select(UR, EPR, LFPR, dgdp) %>% ts(start = 2024, frequency = 1) - names(ilo_conditional_forecast)[i] <- countries[i] + names(ilo_conditional_forecasts)[i] <- countries[i] } -save(ilo_conditional_forecast, file = "data/ilo_conditional_forecast.rda") +save(ilo_conditional_forecasts, file = "data/ilo_conditional_forecasts.rda") From 8861733b616b8efab706328614a99c9fc51ee588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sat, 29 Jun 2024 21:00:12 +1000 Subject: [PATCH 02/11] scripts to create exogenous variables and forecasts #12 #3 --- inst/varia/ilo_exogenous.R | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 inst/varia/ilo_exogenous.R diff --git a/inst/varia/ilo_exogenous.R b/inst/varia/ilo_exogenous.R new file mode 100644 index 0000000..34f2490 --- /dev/null +++ b/inst/varia/ilo_exogenous.R @@ -0,0 +1,40 @@ + +devtools::load_all() + +# dummy panel variables +################################################ +data(ilo_cubic_panel) +countries = names(ilo_cubic_panel) + +dummies = matrix(0, nrow(ilo_cubic_panel$POL), 3) +colnames(dummies) = c("2008", "2020", "2021") +dummies = ts(dummies, start = 1991, frequency = 1) +dummies[18,1] = dummies[30,2] = dummies[31,3] = 1 + +ilo_exogenous_variables = list() +for (c in 1:length(ilo_cubic_panel)) { + ilo_exogenous_variables[[c]] = dummies + names(ilo_exogenous_variables)[c] = countries[c] +} + + + +# dummy panel forecasts +################################################ +data(ilo_conditional_forecasts) + +dummy_forecasts = matrix(0, nrow(ilo_conditional_forecasts$POL), 3) +colnames(dummy_forecasts) = c("2024", "2025", "2026") +dummy_forecasts = ts(dummy_forecasts, start = 2024, frequency = 1) + +ilo_exogenous_forecasts = list() +for (c in 1:length(ilo_conditional_forecasts)) { + ilo_exogenous_forecasts[[c]] = dummy_forecasts + names(ilo_exogenous_forecasts)[c] = countries[c] +} + + +# save +################################################ +save(ilo_exogenous_variables, file = "data/ilo_exogenous_variables.rda") +save(ilo_exogenous_forecasts, file = "data/ilo_exogenous_forecasts.rda") From 2f5caf54a164448456e42660a9b60bda0deeebbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sat, 29 Jun 2024 21:00:32 +1000 Subject: [PATCH 03/11] include exogenous variables and forecasts #12 #3 --- data/ilo_exogenous_forecasts.rda | Bin 0 -> 1333 bytes data/ilo_exogenous_variables.rda | Bin 0 -> 2321 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 data/ilo_exogenous_forecasts.rda create mode 100644 data/ilo_exogenous_variables.rda diff --git a/data/ilo_exogenous_forecasts.rda b/data/ilo_exogenous_forecasts.rda new file mode 100644 index 0000000000000000000000000000000000000000..2e48aefec289a273db836a08e7e541d5a200271e GIT binary patch literal 1333 zcmb2|=3oE==C{}G=3P#cIbL{qS%&kimSYFkC0#law`KE0tG>yI+4r)))8+5l8~=#Uv)N|v7kleubAF!fj;Sgq>x`s$ z|JzC&dy;U|fB!EYjs{E7chbJw+eR=X-gZq`+ z-+le?{M+rV)3e>m_wW1tcI(gG*`L3^m;dzh-OUe03pdxlfBHWE{L6c%?eFdT_v1PH z`A-inPJWyB{oRbkt84w(-<~e?zkK%c+s~hm>#wuhZfk%4Us>fo`Oj}}R8Ow?AonJI z&wu$d?&9e zIRD6vtU0mLrCSdF^huWFKGl27Rc39k^OknQW0qeG*KIYE^-sRiR3gTm7TJ^9v$1U7 zrHGd*myfC(vpIGnQSttkPT45WW!|x_Rd+IYzItxEQn94p_mxw!Owy){tf?#Qrae6_ z_4q)fdH2T7z;e6STNA9NA2vCcDD_=Q{sr@x_eeitUQohfgJs&q#Mjw;lj+%ROPdDq_brtts8}%Qv zI=Q%2Ovd!q8j083aYxPvOgz5Z_-()uzN1m)D`ZY@w^@^%lRU+5=BqQOl#c0@z4+Ry zIi25R-Ii@q%MD)%TvZYC`6RJ4F7?(LttZh_KTDK4hW<$jEfq_CvwMQy)nmsWoeW)@ zd_Q?_^zpqbg70p(x_t3fOnBh=(wU_zKd*hvcE$J2hKoB^lrYaK6inVD?VkOJ^YW3c zrXR0lJUYH5GkNolN6W7E=2|(L9!IZ^y(yb{qQT>IgdZ~ zkJHOjI&OF0>CJPCwOO#+Z&IxMY+ct&Yr7;KA9!tXB&vL$^|j-_LVkby7`?u~-M4;8 z?Qf^_YtxHfh+9S7KhF2D=EY-`-=%w`{cok#luv8DruUdncXz}F!IN57WusWXX04MA r+j_2CbbtT#x%X_(ndCkCep_wc%Gr(YKixN7|DWmm%c~sgI2joL2s!Cu literal 0 HcmV?d00001 diff --git a/data/ilo_exogenous_variables.rda b/data/ilo_exogenous_variables.rda new file mode 100644 index 0000000000000000000000000000000000000000..ba4937962a9302c6b966c9238fe5ca4895b09cd4 GIT binary patch literal 2321 zcmeH{>rYw-0L67}(w`LQ0^_vz^IY)g0&zb^d3Z+uTDJu^XPQcW9{Z*4t_xp?Qy_pNE+-Hb0S z-5$YoOEjTtj+}S=)E&o62?Ck_z}1_=3ibUD23zvGJ2+-qc6XIWIQV8XgNpk_+O!8C&VyOeW#hbdr|KZ&S1h@ZA7{B^={)8 z#S$$Zp`dJZ!fRSm4`qW4PYX?yESvvUp29WA6=DRDRup>2G|W*`Io=w@v+8&RF#l$j zvmLDAv3^n2C&KBrK=XAir)>lfMdYYur5J~4kPFytgB&IO?vT3+mm654q9&MMS!K}h zy*RtIxKpg5*j^GAVT@oE%FT0Q_O9}aw6QTD{vKy+F zx2X@4KZEFqF4M)zH1U~SjOA-%%~MaEcAf4A0#46}yH4O+;UjvfWmw(6U zS1&zqSksr^Cy3(JMgz8p4Da&_ovgIb*(?!G(K18`T2l#vKW?pXmwn7M#P$;cQ|ei0 z&Y3C~5vtCMmDP`DSR8gP_=Nqb%iF3-2DKp!z(MSBM;I zg_5=j7A*$~$W`mg8{$R41`F~r%FB3>e5R)tFbV_qF?`4BC~j(XT2Pz*m^#_Nsw+BY z@rnb-3dZ3`EhUqvIr$`E1zwZeD+_(d#4|zd`aPVk)WF{(Tkmb8>2whT~K*g%T_x; zEKDl~orEg6Jwkl;UdOjUHX`1;Aac}Aj%gV$*oj1vbt>P4De)P}+TZ{k_{r%FX_;>1 M({YtD+WbM-zeR^5T>t<8 literal 0 HcmV?d00001 From 586bb58a167e4067e98a4372ebb52d0ab07fd760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sat, 29 Jun 2024 21:01:11 +1000 Subject: [PATCH 04/11] update documentation for exogenous forecasts #12 #3 --- R/ilo_conditional_forecasts.R | 3 ++- ...nal_forecast.Rd => ilo_conditional_forecasts.Rd} | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) rename man/{ilo_conditional_forecast.Rd => ilo_conditional_forecasts.Rd} (78%) diff --git a/R/ilo_conditional_forecasts.R b/R/ilo_conditional_forecasts.R index bf728d7..5b638bf 100644 --- a/R/ilo_conditional_forecasts.R +++ b/R/ilo_conditional_forecasts.R @@ -5,7 +5,8 @@ #' @description For each of the countries a time series of 6 observations on #' GDP growth rates (sgdp) #' formatted so they is provided to generate #' conditional forecasts of labour market outcomes given the provided projected -#' paths of output. Last data update was implemented on 2024-05-11. +#' paths of output. +#' Last data update was implemented on 2024-05-11. #' #' @usage data(ilo_conditional_forecasts) #' diff --git a/man/ilo_conditional_forecast.Rd b/man/ilo_conditional_forecasts.Rd similarity index 78% rename from man/ilo_conditional_forecast.Rd rename to man/ilo_conditional_forecasts.Rd index 9c58d81..4fa64fd 100644 --- a/man/ilo_conditional_forecast.Rd +++ b/man/ilo_conditional_forecasts.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ilo_conditional_forecast.R +% Please edit documentation in R/ilo_conditional_forecasts.R \docType{data} -\name{ilo_conditional_forecast} -\alias{ilo_conditional_forecast} +\name{ilo_conditional_forecasts} +\alias{ilo_conditional_forecasts} \title{Data containing conditional projections for growth rate of GDP (dgdp) for 189 United Nations countries from 2024 to 2029} \format{ @@ -21,16 +21,17 @@ International Labour Organization. (2020). ILO modelled estimates database, ILOSTAT [database]. Available from \url{https://ilostat.ilo.org/data/}. } \usage{ -data(ilo_conditional_forecast) +data(ilo_conditional_forecasts) } \description{ For each of the countries a time series of 6 observations on GDP growth rates (sgdp) #' formatted so they is provided to generate conditional forecasts of labour market outcomes given the provided projected -paths of output. Last data update was implemented on 2024-05-11. +paths of output. +Last data update was implemented on 2024-05-11. } \examples{ -data(ilo_conditional_forecast) # upload the data +data(ilo_conditional_forecasts) # upload the data } \keyword{datasets} From 650bf3901b18eeb4f99464d7c4116e2f5f80d91e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sat, 29 Jun 2024 21:01:37 +1000 Subject: [PATCH 05/11] include documentation for exogenous variables and forecasts #12 33 --- R/ilo_exogenous_forecasts.R | 25 +++++++++++++++++++++++ R/ilo_exogenous_variables.R | 23 +++++++++++++++++++++ man/forecast.PosteriorBVARPANEL.Rd | 6 +++--- man/ilo_exogenous_forecasts.Rd | 32 ++++++++++++++++++++++++++++++ man/ilo_exogenous_variables.Rd | 30 ++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 R/ilo_exogenous_forecasts.R create mode 100644 R/ilo_exogenous_variables.R create mode 100644 man/ilo_exogenous_forecasts.Rd create mode 100644 man/ilo_exogenous_variables.Rd diff --git a/R/ilo_exogenous_forecasts.R b/R/ilo_exogenous_forecasts.R new file mode 100644 index 0000000..f3d9de9 --- /dev/null +++ b/R/ilo_exogenous_forecasts.R @@ -0,0 +1,25 @@ + +#' @title Data containing future observations for 189 United Nations countries +#' from 2024 to 2029 to be used to forecast with models with +#' \code{ilo_exogenous_variables} +#' +#' @description For each of the countries a time series of 6 observations on +#' On the dummies is provided. These future values are all equal to zero. They +#' provide benchmark for the objects to be used when \code{exogenous_variables} +#' are used. +#' Last data update was implemented on 2024-05-11. +#' +#' @usage data(ilo_exogenous_forecasts) +#' +#' @format A list of 189 \code{ts} objects with time series of 6 observations +#' on 3 variables: +#' \describe{ +#' \item{2008}{the aftermath of the Global Financial Crisis} +#' \item{2020}{the COVID pandemic} +#' \item{2021}{the aftermath of the COVID pandemic} +#' } +#' +#' @examples +#' data(ilo_exogenous_forecasts) # upload the data +#' +"ilo_exogenous_forecasts" \ No newline at end of file diff --git a/R/ilo_exogenous_variables.R b/R/ilo_exogenous_variables.R new file mode 100644 index 0000000..71ccb96 --- /dev/null +++ b/R/ilo_exogenous_variables.R @@ -0,0 +1,23 @@ + +#' @title A 3-variable annual system for of dummy observations for 2008, 2020, +#' and 2021 to be used in the estimation of the Panel VAR model for +#' 189 United Nations countries from 1991 to 2023 +#' +#' @description For each of the countries a time series of 33 observations on 3 +#' dummy variables for the years 2008, 2020, and 2021 is provided. +#' Last data update was implemented on 2024-06-29. +#' +#' @usage data(ilo_exogenous_variables) +#' +#' @format A list of 189 \code{ts} objects with time series of 33 observations +#' on 3 variables: +#' \describe{ +#' \item{2008}{the aftermath of the Global Financial Crisis} +#' \item{2020}{the COVID pandemic} +#' \item{2021}{the aftermath of the COVID pandemic} +#' } +#' +#' @examples +#' data(ilo_exogenous_variables) # upload the data +#' +"ilo_exogenous_variables" diff --git a/man/forecast.PosteriorBVARPANEL.Rd b/man/forecast.PosteriorBVARPANEL.Rd index 6c3fb43..644b960 100644 --- a/man/forecast.PosteriorBVARPANEL.Rd +++ b/man/forecast.PosteriorBVARPANEL.Rd @@ -62,8 +62,8 @@ ilo_cubic_panel |> # provided future values for the Gross Domestic Product # growth rate ############################################################ -#' data(ilo_conditional_forecast) # load the conditional forecasts of dgdp -predictive = forecast(posterior, 6, conditional_forecast = ilo_conditional_forecast) +#' data(ilo_conditional_forecasts) # load the conditional forecasts of dgdp +predictive = forecast(posterior, 6, conditional_forecast = ilo_conditional_forecasts) # workflow with the pipe |> ############################################################ @@ -74,7 +74,7 @@ ilo_cubic_panel |> estimate(S = 20) |> forecast( horizon = 6, - conditional_forecast = ilo_conditional_forecast + conditional_forecast = ilo_conditional_forecasts ) -> predictive } diff --git a/man/ilo_exogenous_forecasts.Rd b/man/ilo_exogenous_forecasts.Rd new file mode 100644 index 0000000..725cf9d --- /dev/null +++ b/man/ilo_exogenous_forecasts.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ilo_exogenous_forecasts.R +\docType{data} +\name{ilo_exogenous_forecasts} +\alias{ilo_exogenous_forecasts} +\title{Data containing future observations for 189 United Nations countries +from 2024 to 2029 to be used to forecast with models with +\code{ilo_exogenous_variables}} +\format{ +A list of 189 \code{ts} objects with time series of 6 observations +on 3 variables: +\describe{ + \item{2008}{the aftermath of the Global Financial Crisis} + \item{2020}{the COVID pandemic} + \item{2021}{the aftermath of the COVID pandemic} +} +} +\usage{ +data(ilo_exogenous_forecasts) +} +\description{ +For each of the countries a time series of 6 observations on +On the dummies is provided. These future values are all equal to zero. They +provide benchmark for the objects to be used when \code{exogenous_variables} +are used. +Last data update was implemented on 2024-05-11. +} +\examples{ +data(ilo_exogenous_forecasts) # upload the data + +} +\keyword{datasets} diff --git a/man/ilo_exogenous_variables.Rd b/man/ilo_exogenous_variables.Rd new file mode 100644 index 0000000..e6b0275 --- /dev/null +++ b/man/ilo_exogenous_variables.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ilo_exogenous_variables.R +\docType{data} +\name{ilo_exogenous_variables} +\alias{ilo_exogenous_variables} +\title{A 3-variable annual system for of dummy observations for 2008, 2020, +and 2021 to be used in the estimation of the Panel VAR model for +189 United Nations countries from 1991 to 2023} +\format{ +A list of 189 \code{ts} objects with time series of 33 observations +on 3 variables: +\describe{ + \item{2008}{the aftermath of the Global Financial Crisis} + \item{2020}{the COVID pandemic} + \item{2021}{the aftermath of the COVID pandemic} +} +} +\usage{ +data(ilo_exogenous_variables) +} +\description{ +For each of the countries a time series of 33 observations on 3 +dummy variables for the years 2008, 2020, and 2021 is provided. +Last data update was implemented on 2024-06-29. +} +\examples{ +data(ilo_exogenous_variables) # upload the data + +} +\keyword{datasets} From 246ba26be2b5d4903109eab53231da3452c00686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sat, 29 Jun 2024 21:36:00 +1000 Subject: [PATCH 06/11] included exogenous in the specify #12 #3 --- R/specify_bvarpanel.R | 53 +++++++++++++++++++----- man/specify_bvarPANEL.Rd | 4 +- man/specify_panel_data_matrices.Rd | 6 ++- man/specify_prior_bvarPANEL.Rd | 4 +- man/specify_starting_values_bvarPANEL.Rd | 4 +- 5 files changed, 57 insertions(+), 14 deletions(-) diff --git a/R/specify_bvarpanel.R b/R/specify_bvarpanel.R index a7f1f93..30ce479 100644 --- a/R/specify_bvarpanel.R +++ b/R/specify_bvarpanel.R @@ -76,20 +76,22 @@ specify_prior_bvarPANEL = R6::R6Class( #' @param C a positive integer - the number of countries in the data. #' @param N a positive integer - the number of dependent variables in the model. #' @param p a positive integer - the autoregressive lag order of the SVAR model. + #' @param d a positive integer - the number of \code{exogenous} variables in the model. #' @return A new prior specification PriorBVARPANEL. #' @examples #' # a prior for 2-country, 3-variable example with one lag and stationary data #' prior = specify_prior_bvarPANEL$new(C = 2, N = 3, p = 1) #' prior$M #' - initialize = function(C, N, p){ + initialize = function(C, N, p, d = 0){ stopifnot("Argument C must be a positive integer number." = C > 0 & C %% 1 == 0) stopifnot("Argument N must be a positive integer number." = N > 0 & N %% 1 == 0) stopifnot("Argument p must be a positive integer number." = p > 0 & p %% 1 == 0) + stopifnot("Argument d must be a non-negative integer number." = d >= 0 & d %% 1 == 0) - K = N * p + 1 + K = N * p + 1 + d self$M = t(cbind(diag(N), matrix(0, N, K - N))) - self$W = diag(c(kronecker((1:p)^2, rep(1, N) ), rep(10, 1))) + self$W = diag(c(kronecker((1:p)^2, rep(1, N) ), rep(10, 1 + d))) self$S_inv = diag(N) self$S_Sigma_inv = diag(N) self$eta = N + 1 @@ -194,17 +196,19 @@ specify_starting_values_bvarPANEL = R6::R6Class( #' @param C a positive integer - the number of countries in the data. #' @param N a positive integer - the number of dependent variables in the model. #' @param p a positive integer - the autoregressive lag order of the SVAR model. + #' @param d a positive integer - the number of \code{exogenous} variables in the model. #' @return Starting values StartingValuesBVARPANEL #' @examples #' # starting values for Bayesian Panel VAR 2-country model with 4 lags for a 3-variable system. #' sv = specify_starting_values_bvarPANEL$new(C = 2, N = 3, p = 4) #' - initialize = function(C, N, p){ + initialize = function(C, N, p, d = 0){ stopifnot("Argument C must be a positive integer number." = C > 0 & C %% 1 == 0) stopifnot("Argument N must be a positive integer number." = N > 0 & N %% 1 == 0) stopifnot("Argument p must be a positive integer number." = p > 0 & p %% 1 == 0) + stopifnot("Argument d must be a non-negative integer number." = d >= 0 & d %% 1 == 0) - K = N * p + 1 + K = N * p + 1 + d self$A_c = array(stats::rnorm(C * K * N, sd = 0.001), c(K, N, C)) self$Sigma_c = stats::rWishart(C, N + 1, diag(N)) self$A = matrix(stats::rnorm(K * N, sd = 0.001), K, N) + diag(K)[,1:N] @@ -302,8 +306,11 @@ specify_panel_data_matrices = R6::R6Class( #' @param data a list containing \code{(T_c+p)xN} matrices with country-specific #' time series data. #' @param p a positive integer providing model's autoregressive lag order. + #' @param exogenous a list containing \code{(T_c+p)xd} matrices with + #' country-specificof exogenous variables. This matrix should not include a + #' constant term. #' @return New data matrices DataMatricesBVARPANEL - initialize = function(data, p = 1L) { + initialize = function(data, p = 1L, exogenous = NULL) { if (missing(data)) { stop("Argument data has to be specified") } else { @@ -314,6 +321,23 @@ specify_panel_data_matrices = R6::R6Class( stopifnot("Argument p must be a positive integer number." = p > 0 & p %% 1 == 0) C = length(data) + if (is.null(exogenous)) { + d = 0 + } else { + stopifnot("Argument exogenous has to be a list of matrices." = is.list(exogenous) & all(simplify2array(lapply(exogenous, function(x){is.matrix(x) & is.numeric(x)})))) + stopifnot("Argument exogenous has to contain matrices with the same number of rows as argument data." = unique(simplify2array(lapply(exogenous, function(x){ncol(x)}))) >= 1 & unique(simplify2array(lapply(data, function(x){nrow(x)}))) == unique(simplify2array(lapply(exogenous, function(x){nrow(x)})))) + stopifnot("Argument exogenous cannot include missing values." = unique(simplify2array(lapply(exogenous, function(x){any(is.na(x))}))) == FALSE ) + d = ncol(exogenous[[1]]) + Td = nrow(exogenous[[1]]) + test_exogenous = 0 + for (c in 1:C) { + for (i in 1:d) { + test_exogenous = test_exogenous + prod(exogenous[[c]][,i] - mean(exogenous[[c]][,i]) == rep(0,Td)) + } + } + stopifnot("Argument exogenous cannot include a constant term." = test_exogenous == 0 ) + } + for (c in 1:C) { TT = nrow(data[[c]]) T_c = TT - p @@ -324,6 +348,9 @@ specify_panel_data_matrices = R6::R6Class( X = cbind(X, data[[c]][(p + 1):TT - i,]) } X = cbind(X, rep(1, T_c)) + if (!is.null(exogenous)) { + X = cbind(X, exogenous[[c]][(p + 1):TT,]) + } self$X[[c]] = X } # END c loop names(self$Y) = names(self$X) = names(data) @@ -393,10 +420,12 @@ specify_bvarPANEL = R6::R6Class( #' @param data a list with \code{C} elements of \code{(T_c+p)xN} matrices #' with time series data. #' @param p a positive integer providing model's autoregressive lag order. + #' @param exogenous a \code{(T+p)xd} matrix of exogenous variables. #' @return A new complete specification for the Bayesian Panel VAR model BVARPANEL. initialize = function( data, - p = 1L + p = 1L, + exogenous = NULL ) { stopifnot("Argument data has to contain matrices with the same number of columns." = length(unique(simplify2array(lapply(data, ncol)))) == 1) stopifnot("Argument p has to be a positive integer." = ((p %% 1) == 0 & p > 0)) @@ -404,10 +433,14 @@ specify_bvarPANEL = R6::R6Class( self$p = p C = length(data) N = unique(simplify2array(lapply(data, ncol))) + d = 0 + if (!is.null(exogenous)) { + d = ncol(exogenous[[1]]) + } - self$data_matrices = specify_panel_data_matrices$new(data, self$p) - self$prior = specify_prior_bvarPANEL$new(C, N, self$p) - self$starting_values = specify_starting_values_bvarPANEL$new(C, N, self$p) + self$data_matrices = specify_panel_data_matrices$new(data, self$p, exogenous) + self$prior = specify_prior_bvarPANEL$new(C, N, self$p, d) + self$starting_values = specify_starting_values_bvarPANEL$new(C, N, self$p, d) self$adaptiveMH = c(0.6, 0.4, 10, 0.1) }, # END initialize diff --git a/man/specify_bvarPANEL.Rd b/man/specify_bvarPANEL.Rd index 13dd39e..b3d0a7a 100644 --- a/man/specify_bvarPANEL.Rd +++ b/man/specify_bvarPANEL.Rd @@ -97,7 +97,7 @@ start adapting, the initial scaling rate} \subsection{Method \code{new()}}{ Create a new specification of the Bayesian Panel VAR model BVARPANEL. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{specify_bvarPANEL$new(data, p = 1L)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{specify_bvarPANEL$new(data, p = 1L, exogenous = NULL)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -107,6 +107,8 @@ Create a new specification of the Bayesian Panel VAR model BVARPANEL. with time series data.} \item{\code{p}}{a positive integer providing model's autoregressive lag order.} + +\item{\code{exogenous}}{a \code{(T+p)xd} matrix of exogenous variables.} } \if{html}{\out{}} } diff --git a/man/specify_panel_data_matrices.Rd b/man/specify_panel_data_matrices.Rd index 219f061..e68c4cc 100644 --- a/man/specify_panel_data_matrices.Rd +++ b/man/specify_panel_data_matrices.Rd @@ -48,7 +48,7 @@ regressors, \eqn{\mathbf{X}_c}.} \subsection{Method \code{new()}}{ Create new data matrices DataMatricesBVARPANEL \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{specify_panel_data_matrices$new(data, p = 1L)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{specify_panel_data_matrices$new(data, p = 1L, exogenous = NULL)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -58,6 +58,10 @@ Create new data matrices DataMatricesBVARPANEL time series data.} \item{\code{p}}{a positive integer providing model's autoregressive lag order.} + +\item{\code{exogenous}}{a list containing \code{(T_c+p)xd} matrices with +country-specificof exogenous variables. This matrix should not include a +constant term.} } \if{html}{\out{}} } diff --git a/man/specify_prior_bvarPANEL.Rd b/man/specify_prior_bvarPANEL.Rd index cb03743..aa743f8 100644 --- a/man/specify_prior_bvarPANEL.Rd +++ b/man/specify_prior_bvarPANEL.Rd @@ -92,7 +92,7 @@ inverted-gamma 2 prior distribution for parameter \eqn{s}.} \subsection{Method \code{new()}}{ Create a new prior specification PriorBVARPANEL. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{specify_prior_bvarPANEL$new(C, N, p)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{specify_prior_bvarPANEL$new(C, N, p, d = 0)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -103,6 +103,8 @@ Create a new prior specification PriorBVARPANEL. \item{\code{N}}{a positive integer - the number of dependent variables in the model.} \item{\code{p}}{a positive integer - the autoregressive lag order of the SVAR model.} + +\item{\code{d}}{a positive integer - the number of \code{exogenous} variables in the model.} } \if{html}{\out{}} } diff --git a/man/specify_starting_values_bvarPANEL.Rd b/man/specify_starting_values_bvarPANEL.Rd index 8c821d9..ff5b670 100644 --- a/man/specify_starting_values_bvarPANEL.Rd +++ b/man/specify_starting_values_bvarPANEL.Rd @@ -88,7 +88,7 @@ parameter \eqn{\mathbf{\Sigma}_c}.} \subsection{Method \code{new()}}{ Create new starting values StartingValuesBVARPANEL \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{specify_starting_values_bvarPANEL$new(C, N, p)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{specify_starting_values_bvarPANEL$new(C, N, p, d = 0)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -99,6 +99,8 @@ Create new starting values StartingValuesBVARPANEL \item{\code{N}}{a positive integer - the number of dependent variables in the model.} \item{\code{p}}{a positive integer - the autoregressive lag order of the SVAR model.} + +\item{\code{d}}{a positive integer - the number of \code{exogenous} variables in the model.} } \if{html}{\out{}} } From 106a11a9e5504975127f60f6287e248acfc587b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sat, 29 Jun 2024 21:41:14 +1000 Subject: [PATCH 07/11] just updated estimate example to include exogenous #12 #3 --- R/estimate.bvarPANEL.R | 4 +++- man/estimate.BVARPANEL.Rd | 4 +++- man/estimate.PosteriorBVARPANEL.Rd | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/R/estimate.bvarPANEL.R b/R/estimate.bvarPANEL.R index d6f5539..5e5251e 100644 --- a/R/estimate.bvarPANEL.R +++ b/R/estimate.bvarPANEL.R @@ -38,8 +38,10 @@ #' #' @examples #' data(ilo_cubic_panel) # load the data +#' data(ilo_exogenous_variables) # load the exogenous variables #' set.seed(123) -#' specification = specify_bvarPANEL$new(ilo_cubic_panel) # specify the model +#' # specify the model +#' specification = specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) #' burn_in = estimate(specification, 10) # run the burn-in #' posterior = estimate(burn_in, 10) # estimate the model #' diff --git a/man/estimate.BVARPANEL.Rd b/man/estimate.BVARPANEL.Rd index 333e327..0288b8c 100644 --- a/man/estimate.BVARPANEL.Rd +++ b/man/estimate.BVARPANEL.Rd @@ -43,8 +43,10 @@ coefficients and parameters on deterministic terms in \eqn{X_c}. } \examples{ data(ilo_cubic_panel) # load the data +data(ilo_exogenous_variables) # load the exogenous variables set.seed(123) -specification = specify_bvarPANEL$new(ilo_cubic_panel) # specify the model +# specify the model +specification = specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) burn_in = estimate(specification, 10) # run the burn-in posterior = estimate(burn_in, 10) # estimate the model diff --git a/man/estimate.PosteriorBVARPANEL.Rd b/man/estimate.PosteriorBVARPANEL.Rd index b940a76..5e591b5 100644 --- a/man/estimate.PosteriorBVARPANEL.Rd +++ b/man/estimate.PosteriorBVARPANEL.Rd @@ -45,8 +45,10 @@ coefficients and parameters on deterministic terms in \eqn{X_c}. } \examples{ data(ilo_cubic_panel) # load the data +data(ilo_exogenous_variables) # load the exogenous variables set.seed(123) -specification = specify_bvarPANEL$new(ilo_cubic_panel) # specify the model +# specify the model +specification = specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) burn_in = estimate(specification, 10) # run the burn-in posterior = estimate(burn_in, 10) # estimate the model From 3caf3ec011b9ad7705f948d69ee32612020e8fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sun, 30 Jun 2024 17:40:52 +1000 Subject: [PATCH 08/11] fixed forecasting! #12 + just one forecasting function forecast_bvarPANEL + mvnrnd_cond used from bsvars:: mvnrnd_cond + severe changes to forecast method! + corrected examples for the new setup --- R/bvarPANELs-package.R | 12 ++- R/forecast.R | 55 ++++++++--- inst/include/bvarPANELs_RcppExports.h | 50 +--------- man/bvarPANELs-package.Rd | 12 ++- man/forecast.PosteriorBVARPANEL.Rd | 14 ++- src/RcppExports.cpp | 94 ++---------------- src/forecast_panel.cpp | 137 ++++++++------------------ src/forecast_panel.h | 16 +-- 8 files changed, 123 insertions(+), 267 deletions(-) diff --git a/R/bvarPANELs-package.R b/R/bvarPANELs-package.R index 9f2e7aa..0609b73 100644 --- a/R/bvarPANELs-package.R +++ b/R/bvarPANELs-package.R @@ -41,11 +41,15 @@ #' #' @examples #' @examples #' data(ilo_cubic_panel) # load the data +#' data(ilo_exogenous_variables) # load the exogenous variables +#' data(ilo_exogenous_forecasts) # load the exogenous forecast #' set.seed(123) -#' specification = specify_bvarPANEL$new(ilo_cubic_panel) # specify the model -#' burn_in = estimate(specification, 20) # run the burn-in -#' posterior = estimate(burn_in, 20) # estimate the model -#' predictive = forecast(posterior, 2) # forecast 2 years ahead +#' # specify the model +#' specification = specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) +#' 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, exogenous_forecast = ilo_exogenous_forecasts) #' #' # workflow with the pipe |> #' ############################################################ diff --git a/R/forecast.R b/R/forecast.R index b405207..54d1156 100644 --- a/R/forecast.R +++ b/R/forecast.R @@ -30,11 +30,15 @@ #' #' @examples #' data(ilo_cubic_panel) # load the data +#' data(ilo_exogenous_variables) # load the exogenous variables +#' data(ilo_exogenous_forecasts) # load the exogenous forecast #' set.seed(123) -#' specification = specify_bvarPANEL$new(ilo_cubic_panel) # specify the model +#' # specify the model +#' specification = specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) #' burn_in = estimate(specification, 10) # run the burn-in #' posterior = estimate(burn_in, 10) # estimate the model -#' predictive = forecast(posterior, 2) # forecast 2 years ahead +#' # forecast 6 years ahead +#' predictive = forecast(posterior, 6, exogenous_forecast = ilo_exogenous_forecasts) #' #' # workflow with the pipe |> #' ############################################################ @@ -49,7 +53,11 @@ #' # provided future values for the Gross Domestic Product #' # growth rate #' ############################################################ -#' #' data(ilo_conditional_forecasts) # load the conditional forecasts of dgdp +#' data(ilo_conditional_forecasts) # load the conditional forecasts of dgdp +#' 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) #' #' # workflow with the pipe |> @@ -77,13 +85,30 @@ forecast.PosteriorBVARPANEL = function( X_c = posterior$last_draw$data_matrices$X Y_c = posterior$last_draw$data_matrices$Y N = dim(Y_c[[1]])[2] + K = dim(X_c[[1]])[2] + C = length(Y_c) - do_conditional_forecasting = !is.null(conditional_forecast) + d = K - N * posterior$last_draw$p - 1 + if (d == 0 ) { + # this will not be used for forecasting, but needs to be provided + exogenous_forecast = list() + for (c in 1:C) exogenous_forecast[[c]] = matrix(NA, horizon, 1) + } else { + stopifnot("Forecasted values of exogenous variables are missing." + = (d > 0) & !is.null(exogenous_forecast)) + stopifnot("The matrix of exogenous_forecast does not have a correct number of columns." + = unique(simplify2array(lapply(exogenous_forecast, function(x){ncol(x)}))) == d) + stopifnot("Provide exogenous_forecast for all forecast periods specified by argument horizon." + = unique(simplify2array(lapply(exogenous_forecast, function(x){nrow(x)}))) == horizon) + stopifnot("Argument exogenous has to be a matrix." + = all(simplify2array(lapply(exogenous_forecast, function(x){is.matrix(x) & is.numeric(x)})))) + stopifnot("Argument exogenous cannot include missing values." + = unique(simplify2array(lapply(exogenous_forecast, function(x){any(is.na(x))}))) == FALSE) + } - if (!do_conditional_forecasting) { - # perform forecasting - fore = .Call(`_bvarPANELs_forecast_bvarPANEL`, - posterior_A_c_cpp, posterior_Sigma_c_cpp, X_c, horizon) + if ( is.null(conditional_forecast) ) { + conditional_forecast = list() + for (c in 1:C) conditional_forecast[[c]] = matrix(NA, horizon, N) } else { stopifnot("Argument conditional_forecast must be a list with the same countries as in the provided data." @@ -104,12 +129,18 @@ forecast.PosteriorBVARPANEL = function( the same number of columns equal to the number of columns in the used data." = unique(sapply(conditional_forecast, function(x) ncol(x) )) == N ) - - # perform conditional forecasting - fore = .Call(`_bvarPANELs_forecast_conditional_bvarPANEL`, - posterior_A_c_cpp, posterior_Sigma_c_cpp, X_c, conditional_forecast, horizon) } + # perform forecasting + fore = .Call(`_bvarPANELs_forecast_bvarPANEL`, + posterior_A_c_cpp, + posterior_Sigma_c_cpp, + X_c, + conditional_forecast, + exogenous_forecast, + horizon + ) + S = dim(posterior_A_c_cpp)[1] C = length(Y_c) forecasts = array(NA, c(horizon, N, S, C)) diff --git a/inst/include/bvarPANELs_RcppExports.h b/inst/include/bvarPANELs_RcppExports.h index 7b78d45..0b9de79 100644 --- a/inst/include/bvarPANELs_RcppExports.h +++ b/inst/include/bvarPANELs_RcppExports.h @@ -25,59 +25,17 @@ namespace bvarPANELs { } } - inline Rcpp::List forecast_bvarPANEL(arma::field& posterior_A_c_cpp, arma::field& posterior_Sigma_c_cpp, Rcpp::List& X_c, const int horizon) { - typedef SEXP(*Ptr_forecast_bvarPANEL)(SEXP,SEXP,SEXP,SEXP); + inline Rcpp::List forecast_bvarPANEL(arma::field& posterior_A_c_cpp, arma::field& posterior_Sigma_c_cpp, Rcpp::List& X_c, Rcpp::List& cond_forecasts, Rcpp::List& exog_forecasts, const int horizon) { + typedef SEXP(*Ptr_forecast_bvarPANEL)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_forecast_bvarPANEL p_forecast_bvarPANEL = NULL; if (p_forecast_bvarPANEL == NULL) { - validateSignature("Rcpp::List(*forecast_bvarPANEL)(arma::field&,arma::field&,Rcpp::List&,const int)"); + validateSignature("Rcpp::List(*forecast_bvarPANEL)(arma::field&,arma::field&,Rcpp::List&,Rcpp::List&,Rcpp::List&,const int)"); p_forecast_bvarPANEL = (Ptr_forecast_bvarPANEL)R_GetCCallable("bvarPANELs", "_bvarPANELs_forecast_bvarPANEL"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; - rcpp_result_gen = p_forecast_bvarPANEL(Shield(Rcpp::wrap(posterior_A_c_cpp)), Shield(Rcpp::wrap(posterior_Sigma_c_cpp)), Shield(Rcpp::wrap(X_c)), Shield(Rcpp::wrap(horizon))); - } - if (rcpp_result_gen.inherits("interrupted-error")) - throw Rcpp::internal::InterruptedException(); - if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) - throw Rcpp::LongjumpException(rcpp_result_gen); - if (rcpp_result_gen.inherits("try-error")) - throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); - return Rcpp::as(rcpp_result_gen); - } - - inline arma::vec mvnrnd_cond(arma::vec x, arma::vec mu, arma::mat Sigma) { - typedef SEXP(*Ptr_mvnrnd_cond)(SEXP,SEXP,SEXP); - static Ptr_mvnrnd_cond p_mvnrnd_cond = NULL; - if (p_mvnrnd_cond == NULL) { - validateSignature("arma::vec(*mvnrnd_cond)(arma::vec,arma::vec,arma::mat)"); - p_mvnrnd_cond = (Ptr_mvnrnd_cond)R_GetCCallable("bvarPANELs", "_bvarPANELs_mvnrnd_cond"); - } - RObject rcpp_result_gen; - { - RNGScope RCPP_rngScope_gen; - rcpp_result_gen = p_mvnrnd_cond(Shield(Rcpp::wrap(x)), Shield(Rcpp::wrap(mu)), Shield(Rcpp::wrap(Sigma))); - } - if (rcpp_result_gen.inherits("interrupted-error")) - throw Rcpp::internal::InterruptedException(); - if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) - throw Rcpp::LongjumpException(rcpp_result_gen); - if (rcpp_result_gen.inherits("try-error")) - throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); - return Rcpp::as(rcpp_result_gen); - } - - inline Rcpp::List forecast_conditional_bvarPANEL(arma::field& posterior_A_c_cpp, arma::field& posterior_Sigma_c_cpp, Rcpp::List& X_c, Rcpp::List& cond_forecasts, const int horizon) { - typedef SEXP(*Ptr_forecast_conditional_bvarPANEL)(SEXP,SEXP,SEXP,SEXP,SEXP); - static Ptr_forecast_conditional_bvarPANEL p_forecast_conditional_bvarPANEL = NULL; - if (p_forecast_conditional_bvarPANEL == NULL) { - validateSignature("Rcpp::List(*forecast_conditional_bvarPANEL)(arma::field&,arma::field&,Rcpp::List&,Rcpp::List&,const int)"); - p_forecast_conditional_bvarPANEL = (Ptr_forecast_conditional_bvarPANEL)R_GetCCallable("bvarPANELs", "_bvarPANELs_forecast_conditional_bvarPANEL"); - } - RObject rcpp_result_gen; - { - RNGScope RCPP_rngScope_gen; - rcpp_result_gen = p_forecast_conditional_bvarPANEL(Shield(Rcpp::wrap(posterior_A_c_cpp)), Shield(Rcpp::wrap(posterior_Sigma_c_cpp)), Shield(Rcpp::wrap(X_c)), Shield(Rcpp::wrap(cond_forecasts)), Shield(Rcpp::wrap(horizon))); + rcpp_result_gen = p_forecast_bvarPANEL(Shield(Rcpp::wrap(posterior_A_c_cpp)), Shield(Rcpp::wrap(posterior_Sigma_c_cpp)), Shield(Rcpp::wrap(X_c)), Shield(Rcpp::wrap(cond_forecasts)), Shield(Rcpp::wrap(exog_forecasts)), Shield(Rcpp::wrap(horizon))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); diff --git a/man/bvarPANELs-package.Rd b/man/bvarPANELs-package.Rd index 3c575db..6c60b34 100644 --- a/man/bvarPANELs-package.Rd +++ b/man/bvarPANELs-package.Rd @@ -15,11 +15,15 @@ This package is currently in active development. } \examples{ data(ilo_cubic_panel) # load the data +data(ilo_exogenous_variables) # load the exogenous variables +data(ilo_exogenous_forecasts) # load the exogenous forecast set.seed(123) -specification = specify_bvarPANEL$new(ilo_cubic_panel) # specify the model -burn_in = estimate(specification, 20) # run the burn-in -posterior = estimate(burn_in, 20) # estimate the model -predictive = forecast(posterior, 2) # forecast 2 years ahead +# specify the model +specification = specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) +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, exogenous_forecast = ilo_exogenous_forecasts) # workflow with the pipe |> ############################################################ diff --git a/man/forecast.PosteriorBVARPANEL.Rd b/man/forecast.PosteriorBVARPANEL.Rd index 644b960..e891497 100644 --- a/man/forecast.PosteriorBVARPANEL.Rd +++ b/man/forecast.PosteriorBVARPANEL.Rd @@ -43,11 +43,15 @@ from 1 to \code{horizon} specified as an argument of the function. } \examples{ data(ilo_cubic_panel) # load the data +data(ilo_exogenous_variables) # load the exogenous variables +data(ilo_exogenous_forecasts) # load the exogenous forecast set.seed(123) -specification = specify_bvarPANEL$new(ilo_cubic_panel) # specify the model +# specify the model +specification = specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) burn_in = estimate(specification, 10) # run the burn-in posterior = estimate(burn_in, 10) # estimate the model -predictive = forecast(posterior, 2) # forecast 2 years ahead +# forecast 6 years ahead +predictive = forecast(posterior, 6, exogenous_forecast = ilo_exogenous_forecasts) # workflow with the pipe |> ############################################################ @@ -62,7 +66,11 @@ ilo_cubic_panel |> # provided future values for the Gross Domestic Product # growth rate ############################################################ -#' data(ilo_conditional_forecasts) # load the conditional forecasts of dgdp +data(ilo_conditional_forecasts) # load the conditional forecasts of dgdp +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) # workflow with the pipe |> diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index a8865ca..36f9d88 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -33,97 +33,25 @@ BEGIN_RCPP END_RCPP } // forecast_bvarPANEL -Rcpp::List forecast_bvarPANEL(arma::field& posterior_A_c_cpp, arma::field& posterior_Sigma_c_cpp, Rcpp::List& X_c, const int horizon); -static SEXP _bvarPANELs_forecast_bvarPANEL_try(SEXP posterior_A_c_cppSEXP, SEXP posterior_Sigma_c_cppSEXP, SEXP X_cSEXP, SEXP horizonSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::traits::input_parameter< arma::field& >::type posterior_A_c_cpp(posterior_A_c_cppSEXP); - Rcpp::traits::input_parameter< arma::field& >::type posterior_Sigma_c_cpp(posterior_Sigma_c_cppSEXP); - Rcpp::traits::input_parameter< Rcpp::List& >::type X_c(X_cSEXP); - Rcpp::traits::input_parameter< const int >::type horizon(horizonSEXP); - rcpp_result_gen = Rcpp::wrap(forecast_bvarPANEL(posterior_A_c_cpp, posterior_Sigma_c_cpp, X_c, horizon)); - return rcpp_result_gen; -END_RCPP_RETURN_ERROR -} -RcppExport SEXP _bvarPANELs_forecast_bvarPANEL(SEXP posterior_A_c_cppSEXP, SEXP posterior_Sigma_c_cppSEXP, SEXP X_cSEXP, SEXP horizonSEXP) { - SEXP rcpp_result_gen; - { - Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = PROTECT(_bvarPANELs_forecast_bvarPANEL_try(posterior_A_c_cppSEXP, posterior_Sigma_c_cppSEXP, X_cSEXP, horizonSEXP)); - } - Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); - if (rcpp_isInterrupt_gen) { - UNPROTECT(1); - Rf_onintr(); - } - bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); - if (rcpp_isLongjump_gen) { - Rcpp::internal::resumeJump(rcpp_result_gen); - } - Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); - if (rcpp_isError_gen) { - SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); - UNPROTECT(1); - Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); - } - UNPROTECT(1); - return rcpp_result_gen; -} -// mvnrnd_cond -arma::vec mvnrnd_cond(arma::vec x, arma::vec mu, arma::mat Sigma); -static SEXP _bvarPANELs_mvnrnd_cond_try(SEXP xSEXP, SEXP muSEXP, SEXP SigmaSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::traits::input_parameter< arma::vec >::type x(xSEXP); - Rcpp::traits::input_parameter< arma::vec >::type mu(muSEXP); - Rcpp::traits::input_parameter< arma::mat >::type Sigma(SigmaSEXP); - rcpp_result_gen = Rcpp::wrap(mvnrnd_cond(x, mu, Sigma)); - return rcpp_result_gen; -END_RCPP_RETURN_ERROR -} -RcppExport SEXP _bvarPANELs_mvnrnd_cond(SEXP xSEXP, SEXP muSEXP, SEXP SigmaSEXP) { - SEXP rcpp_result_gen; - { - Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = PROTECT(_bvarPANELs_mvnrnd_cond_try(xSEXP, muSEXP, SigmaSEXP)); - } - Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); - if (rcpp_isInterrupt_gen) { - UNPROTECT(1); - Rf_onintr(); - } - bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); - if (rcpp_isLongjump_gen) { - Rcpp::internal::resumeJump(rcpp_result_gen); - } - Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); - if (rcpp_isError_gen) { - SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); - UNPROTECT(1); - Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); - } - UNPROTECT(1); - return rcpp_result_gen; -} -// forecast_conditional_bvarPANEL -Rcpp::List forecast_conditional_bvarPANEL(arma::field& posterior_A_c_cpp, arma::field& posterior_Sigma_c_cpp, Rcpp::List& X_c, Rcpp::List& cond_forecasts, const int horizon); -static SEXP _bvarPANELs_forecast_conditional_bvarPANEL_try(SEXP posterior_A_c_cppSEXP, SEXP posterior_Sigma_c_cppSEXP, SEXP X_cSEXP, SEXP cond_forecastsSEXP, SEXP horizonSEXP) { +Rcpp::List forecast_bvarPANEL(arma::field& posterior_A_c_cpp, arma::field& posterior_Sigma_c_cpp, Rcpp::List& X_c, Rcpp::List& cond_forecasts, Rcpp::List& exog_forecasts, const int horizon); +static SEXP _bvarPANELs_forecast_bvarPANEL_try(SEXP posterior_A_c_cppSEXP, SEXP posterior_Sigma_c_cppSEXP, SEXP X_cSEXP, SEXP cond_forecastsSEXP, SEXP exog_forecastsSEXP, SEXP horizonSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< arma::field& >::type posterior_A_c_cpp(posterior_A_c_cppSEXP); Rcpp::traits::input_parameter< arma::field& >::type posterior_Sigma_c_cpp(posterior_Sigma_c_cppSEXP); Rcpp::traits::input_parameter< Rcpp::List& >::type X_c(X_cSEXP); Rcpp::traits::input_parameter< Rcpp::List& >::type cond_forecasts(cond_forecastsSEXP); + Rcpp::traits::input_parameter< Rcpp::List& >::type exog_forecasts(exog_forecastsSEXP); Rcpp::traits::input_parameter< const int >::type horizon(horizonSEXP); - rcpp_result_gen = Rcpp::wrap(forecast_conditional_bvarPANEL(posterior_A_c_cpp, posterior_Sigma_c_cpp, X_c, cond_forecasts, horizon)); + rcpp_result_gen = Rcpp::wrap(forecast_bvarPANEL(posterior_A_c_cpp, posterior_Sigma_c_cpp, X_c, cond_forecasts, exog_forecasts, horizon)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } -RcppExport SEXP _bvarPANELs_forecast_conditional_bvarPANEL(SEXP posterior_A_c_cppSEXP, SEXP posterior_Sigma_c_cppSEXP, SEXP X_cSEXP, SEXP cond_forecastsSEXP, SEXP horizonSEXP) { +RcppExport SEXP _bvarPANELs_forecast_bvarPANEL(SEXP posterior_A_c_cppSEXP, SEXP posterior_Sigma_c_cppSEXP, SEXP X_cSEXP, SEXP cond_forecastsSEXP, SEXP exog_forecastsSEXP, SEXP horizonSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = PROTECT(_bvarPANELs_forecast_conditional_bvarPANEL_try(posterior_A_c_cppSEXP, posterior_Sigma_c_cppSEXP, X_cSEXP, cond_forecastsSEXP, horizonSEXP)); + rcpp_result_gen = PROTECT(_bvarPANELs_forecast_bvarPANEL_try(posterior_A_c_cppSEXP, posterior_Sigma_c_cppSEXP, X_cSEXP, cond_forecastsSEXP, exog_forecastsSEXP, horizonSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { @@ -298,9 +226,7 @@ END_RCPP static int _bvarPANELs_RcppExport_validate(const char* sig) { static std::set signatures; if (signatures.empty()) { - signatures.insert("Rcpp::List(*forecast_bvarPANEL)(arma::field&,arma::field&,Rcpp::List&,const int)"); - signatures.insert("arma::vec(*mvnrnd_cond)(arma::vec,arma::vec,arma::mat)"); - signatures.insert("Rcpp::List(*forecast_conditional_bvarPANEL)(arma::field&,arma::field&,Rcpp::List&,Rcpp::List&,const int)"); + signatures.insert("Rcpp::List(*forecast_bvarPANEL)(arma::field&,arma::field&,Rcpp::List&,Rcpp::List&,Rcpp::List&,const int)"); } return signatures.find(sig) != signatures.end(); } @@ -308,17 +234,13 @@ static int _bvarPANELs_RcppExport_validate(const char* sig) { // registerCCallable (register entry points for exported C++ functions) RcppExport SEXP _bvarPANELs_RcppExport_registerCCallable() { R_RegisterCCallable("bvarPANELs", "_bvarPANELs_forecast_bvarPANEL", (DL_FUNC)_bvarPANELs_forecast_bvarPANEL_try); - R_RegisterCCallable("bvarPANELs", "_bvarPANELs_mvnrnd_cond", (DL_FUNC)_bvarPANELs_mvnrnd_cond_try); - R_RegisterCCallable("bvarPANELs", "_bvarPANELs_forecast_conditional_bvarPANEL", (DL_FUNC)_bvarPANELs_forecast_conditional_bvarPANEL_try); R_RegisterCCallable("bvarPANELs", "_bvarPANELs_RcppExport_validate", (DL_FUNC)_bvarPANELs_RcppExport_validate); return R_NilValue; } static const R_CallMethodDef CallEntries[] = { {"_bvarPANELs_bvarPANEL", (DL_FUNC) &_bvarPANELs_bvarPANEL, 8}, - {"_bvarPANELs_forecast_bvarPANEL", (DL_FUNC) &_bvarPANELs_forecast_bvarPANEL, 4}, - {"_bvarPANELs_mvnrnd_cond", (DL_FUNC) &_bvarPANELs_mvnrnd_cond, 3}, - {"_bvarPANELs_forecast_conditional_bvarPANEL", (DL_FUNC) &_bvarPANELs_forecast_conditional_bvarPANEL, 5}, + {"_bvarPANELs_forecast_bvarPANEL", (DL_FUNC) &_bvarPANELs_forecast_bvarPANEL, 6}, {"_bvarPANELs_rmniw1", (DL_FUNC) &_bvarPANELs_rmniw1, 4}, {"_bvarPANELs_sample_m", (DL_FUNC) &_bvarPANELs_sample_m, 5}, {"_bvarPANELs_sample_w", (DL_FUNC) &_bvarPANELs_sample_w, 2}, diff --git a/src/forecast_panel.cpp b/src/forecast_panel.cpp index e1c87e5..defc831 100644 --- a/src/forecast_panel.cpp +++ b/src/forecast_panel.cpp @@ -1,5 +1,6 @@ #include +#include using namespace Rcpp; using namespace arma; @@ -8,97 +9,11 @@ using namespace arma; // [[Rcpp::interfaces(cpp)]] // [[Rcpp::export]] Rcpp::List forecast_bvarPANEL ( - arma::field& posterior_A_c_cpp, // (S)(K, N, C) - arma::field& posterior_Sigma_c_cpp, // (S)(N, N, C) - Rcpp::List& X_c, // (C)(T_c, K) - const int horizon -) { - - const int N = posterior_A_c_cpp(0).n_cols; - const int S = posterior_A_c_cpp.n_elem; - const int K = posterior_A_c_cpp(0).n_rows; - const int C = posterior_A_c_cpp(0).n_slices; - const int p = (K - 1) / N; - - field forecasts(C); // of (horizon, N, S) cubes - rowvec one(1, fill::value(1)); - - for (int c=0; c(X_c[c]); - rowvec x_t = XXcc.tail_rows(1).cols(0, K - 2); - cube forecasts_c(horizon, N, S); - - for (int s=0; s& posterior_A_c_cpp, // (S)(K, N, C) arma::field& posterior_Sigma_c_cpp, // (S)(N, N, C) Rcpp::List& X_c, // (C)(T_c, K) Rcpp::List& cond_forecasts, // (C)(horizon, N) + Rcpp::List& exog_forecasts, // (C)(horizon, d) const int horizon ) { @@ -106,34 +21,62 @@ Rcpp::List forecast_conditional_bvarPANEL ( const int S = posterior_A_c_cpp.n_elem; const int K = posterior_A_c_cpp(0).n_rows; const int C = posterior_A_c_cpp(0).n_slices; - const int p = (K - 1) / N; + + mat EXcc = as(exog_forecasts[0]); + const int d = EXcc.n_cols; field forecasts(C); // of (horizon, N, S) cubes - rowvec one(1, fill::value(1)); for (int c=0; c(X_c[c]); + mat EXcc = as(exog_forecasts[c]); + bool do_exog = EXcc.is_finite(); mat cond_fc = as(cond_forecasts[c]); - rowvec x_t = XXcc.tail_rows(1).cols(0, K - 2); + + rowvec x_t; + if ( do_exog ) { + x_t = XXcc.tail_rows(1).cols(0, K - 1 - d); + } else { + x_t = XXcc.tail_rows(1).cols(0, K - 1); + } + + vec Xt(K); cube forecasts_c(horizon, N, S); for (int s=0; s& posterior_A_c_cpp, // (S)(K, N, C) - arma::field& posterior_Sigma_c_cpp, // (S)(N, N, C) - Rcpp::List& X_c, // (C)(T_c, K) - const int horizon -); - - -arma::vec mvnrnd_cond ( - arma::vec x, // Nx1 with NAs or without - arma::vec mu, // Nx1 mean vector - arma::mat Sigma // NxN covariance matrix -); - - -Rcpp::List forecast_conditional_bvarPANEL ( arma::field& posterior_A_c_cpp, // (S)(K, N, C) arma::field& posterior_Sigma_c_cpp, // (S)(N, N, C) Rcpp::List& X_c, // (C)(T_c, K) Rcpp::List& cond_forecasts, // (C)(horizon, N) + Rcpp::List& exog_forecasts, // (C)(horizon, d) const int horizon ); From 454ad8e9f0d26ddec54322ed33c8036ad5e1a705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sun, 30 Jun 2024 17:55:52 +1000 Subject: [PATCH 09/11] polished examples and changed thinning setup #12 --- R/bvarPANELs-package.R | 32 +++++++++++++++++++++++++------- R/estimate.bvarPANEL.R | 2 +- man/bvarPANELs-package.Rd | 32 +++++++++++++++++++++++++------- man/estimate.BVARPANEL.Rd | 2 +- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/R/bvarPANELs-package.R b/R/bvarPANELs-package.R index 0609b73..b67257d 100644 --- a/R/bvarPANELs-package.R +++ b/R/bvarPANELs-package.R @@ -40,23 +40,41 @@ #' @keywords package models ts #' #' @examples #' @examples +#' # Basic estimation and forecasting example +#' ############################################################ #' data(ilo_cubic_panel) # load the data -#' data(ilo_exogenous_variables) # load the exogenous variables -#' data(ilo_exogenous_forecasts) # load the exogenous forecast #' set.seed(123) -#' # specify the model -#' specification = specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) +#' 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, exogenous_forecast = ilo_exogenous_forecasts) +#' predictive = forecast(posterior, 2) # forecast the future #' #' # workflow with the pipe |> -#' ############################################################ #' set.seed(123) #' ilo_cubic_panel |> #' specify_bvarPANEL$new() |> #' estimate(S = 20) |> #' estimate(S = 20) |> #' forecast(horizon = 2) -> predictive +#' +#' # Full estimation and forecasting example with +#' # exogenous variables and conditional forecasts +#' ############################################################ +#' data(ilo_cubic_panel) # load the data +#' data(ilo_exogenous_variables) # load the exogenous variables +#' data(ilo_exogenous_forecasts) # load the exogenous forecasts +#' data(ilo_conditional_forecasts) # load the conditional forecasts +#' set.seed(123) +#' specification = specify_bvarPANEL$new( +#' ilo_cubic_panel, +#' exogenous = ilo_exogenous_variables +#' ) +#' burn_in = estimate(specification, 10) # run the burn-in +#' posterior = estimate(burn_in, 10) # estimate the model +#' predictive = forecast( +#' posterior, +#' horizon = 6, +#' exogenous_forecast = ilo_exogenous_forecasts, +#' conditional_forecast = ilo_conditional_forecasts +#' ) "_PACKAGE" diff --git a/R/estimate.bvarPANEL.R b/R/estimate.bvarPANEL.R index 5e5251e..5ae49a0 100644 --- a/R/estimate.bvarPANEL.R +++ b/R/estimate.bvarPANEL.R @@ -49,7 +49,7 @@ estimate.BVARPANEL <- function( specification, S, - thin = 10L, + thin = 1L, show_progress = TRUE ) { diff --git a/man/bvarPANELs-package.Rd b/man/bvarPANELs-package.Rd index 6c60b34..91e9ab2 100644 --- a/man/bvarPANELs-package.Rd +++ b/man/bvarPANELs-package.Rd @@ -14,25 +14,43 @@ hierarchical prior structure. Copyright: 2024 International Labour Organization. This package is currently in active development. } \examples{ +# Basic estimation and forecasting example +############################################################ data(ilo_cubic_panel) # load the data -data(ilo_exogenous_variables) # load the exogenous variables -data(ilo_exogenous_forecasts) # load the exogenous forecast set.seed(123) -# specify the model -specification = specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) +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, exogenous_forecast = ilo_exogenous_forecasts) +predictive = forecast(posterior, 2) # forecast the future # workflow with the pipe |> -############################################################ set.seed(123) ilo_cubic_panel |> specify_bvarPANEL$new() |> estimate(S = 20) |> estimate(S = 20) |> forecast(horizon = 2) -> predictive + +# Full estimation and forecasting example with +# exogenous variables and conditional forecasts +############################################################ +data(ilo_cubic_panel) # load the data +data(ilo_exogenous_variables) # load the exogenous variables +data(ilo_exogenous_forecasts) # load the exogenous forecasts +data(ilo_conditional_forecasts) # load the conditional forecasts +set.seed(123) +specification = specify_bvarPANEL$new( + ilo_cubic_panel, + exogenous = ilo_exogenous_variables + ) +burn_in = estimate(specification, 10) # run the burn-in +posterior = estimate(burn_in, 10) # estimate the model +predictive = forecast( + posterior, + horizon = 6, + exogenous_forecast = ilo_exogenous_forecasts, + conditional_forecast = ilo_conditional_forecasts + ) } \author{ Tomasz Woźniak \email{wozniak.tom@pm.me} diff --git a/man/estimate.BVARPANEL.Rd b/man/estimate.BVARPANEL.Rd index 0288b8c..fbe82df 100644 --- a/man/estimate.BVARPANEL.Rd +++ b/man/estimate.BVARPANEL.Rd @@ -5,7 +5,7 @@ \title{Bayesian estimation of a Bayesian Hierarchical Panel Vector Autoregression using Gibbs sampler} \usage{ -\method{estimate}{BVARPANEL}(specification, S, thin = 10L, show_progress = TRUE) +\method{estimate}{BVARPANEL}(specification, S, thin = 1L, show_progress = TRUE) } \arguments{ \item{specification}{an object of class BVARPANEL generated using the From 82bebb307dfb60893136953c3d763d0aab1157a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sun, 30 Jun 2024 17:59:51 +1000 Subject: [PATCH 10/11] Update NEWS.md #12 --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 78ecf8c..b83ec97 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,3 +4,7 @@ 2. The package includes the Gibbs sampler for a Bayesian Hierarchical Panel Vector Autoregression model. [#2](https://github.com/bsvars/bvarPANELs/issues/2) 3. The package includes labour market dynamic panel data. [#3](https://github.com/bsvars/bvarPANELs/issues/3) 4. The package includes the forecast method. [#5](https://github.com/bsvars/bvarPANELs/issues/5) +5. The package includes possibility of conditional forecasting given projected paths of some of the variables. +[#8](https://github.com/bsvars/bvarPANELs/issues/8) +6. The package includes estimation and forecasting with exogenous variables. [#12](https://github.com/bsvars/bvarPANELs/issues/12) + From 5a1670737a03ea96a82b1288cce290ba488e0265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sun, 30 Jun 2024 18:38:56 +1000 Subject: [PATCH 11/11] Update test_forecast.R + included extensive tests of exogenous forecasts #12 --- inst/tinytest/test_forecast.R | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/inst/tinytest/test_forecast.R b/inst/tinytest/test_forecast.R index 0791110..2a18a65 100644 --- a/inst/tinytest/test_forecast.R +++ b/inst/tinytest/test_forecast.R @@ -64,6 +64,11 @@ expect_identical( info = "conditional forecast: forecast identical for normal and pipe workflow." ) +expect_equivalent( + ilo_conditional_forecasts[[1]][1,4], ff2$forecasts[1,4,1,1], + info = "conditional forecast: forecasts and provided conditional forecasts identical." +) + expect_true( is.numeric(ff$forecasts) & is.array(ff$forecasts), info = "conditional forecast: returns numeric array." @@ -81,3 +86,52 @@ expect_error( ) +# exogenous variables +data("ilo_exogenous_variables") +data("ilo_exogenous_forecasts") + +set.seed(1) +suppressMessages( + specification_no1 <- specify_bvarPANEL$new(ilo_cubic_panel, exogenous = ilo_exogenous_variables) +) +run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) +ff <- forecast(run_no1, 6, exogenous_forecast = ilo_exogenous_forecasts) + +set.seed(1) +suppressMessages( + ff2 <- ilo_cubic_panel |> + specify_bvarPANEL$new(exogenous = ilo_exogenous_variables) |> + estimate(S = 3, thin = 1, show_progress = FALSE) |> + forecast(horizon = 6, exogenous_forecast = ilo_exogenous_forecasts) +) + + +expect_identical( + ff$forecasts[1,1,1,1], ff2$forecasts[1,1,1,1], + info = "exogenous forecast: forecast identical for normal and pipe workflow." +) + +expect_true( + is.numeric(ff$forecasts) & is.array(ff$forecasts), + info = "exogenous forecast: returns numeric array." +) + + +expect_error( + forecast(run_no1, horizon = 4, exogenous_forecast = ilo_exogenous_forecasts), + pattern = "horizon", + info = "exogenous forecast: provided forecasts different from horizon." +) + +expect_error( + forecast(run_no1, horizon = 4), + pattern = "missing", + info = "exogenous forecast: missing exogenous forecasts for model with exogenous variables." +) + +ilo_exogenous_forecasts[[1]][1,1] = NA +expect_error( + forecast(run_no1, horizon = 6, exogenous_forecast = ilo_exogenous_forecasts), + pattern = "values", + info = "exogenous forecast: provided exogenous forecasts contain missing values." +)