-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from bsvars/2-gibbs-sampler-for-the-basic-model
2 gibbs sampler for the basic model
- Loading branch information
Showing
22 changed files
with
2,403 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method(estimate,BVARPANEL) | ||
S3method(estimate,PosteriorBVARPANEL) | ||
export(specify_bvarPANEL) | ||
export(specify_panel_data_matrices) | ||
export(specify_posterior_bvarPANEL) | ||
export(specify_prior_bvarPANEL) | ||
export(specify_starting_values_bvarPANEL) | ||
import(RcppProgress) | ||
importFrom(R6,R6Class) | ||
importFrom(Rcpp,sourceCpp) | ||
importFrom(RcppTN,dtn) | ||
importFrom(RcppTN,rtn) | ||
importFrom(bsvars,estimate) | ||
useDynLib(bvarPANELs, .registration = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# bvarPANELs 0.0.1.9000 | ||
|
||
1. This package is alive! [#1](https://github.com/bsvars/bvarPANELs/issues/1) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
# Generated by using Rcpp::compileAttributes() -> do not edit by hand | ||
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
bvarPANEL <- function(S, Y, X, prior, starting_values, thin = 100L, show_progress = TRUE) { | ||
.Call(`_bvarPANELs_bvarPANEL`, S, Y, X, prior, starting_values, thin, show_progress) | ||
} | ||
|
||
rmniw1 <- function(A, V, S, nu) { | ||
.Call(`_bvarPANELs_rmniw1`, A, V, S, nu) | ||
} | ||
|
||
sample_m <- function(aux_A, aux_V, aux_s, aux_w, prior) { | ||
.Call(`_bvarPANELs_sample_m`, aux_A, aux_V, aux_s, aux_w, prior) | ||
} | ||
|
||
sample_w <- function(aux_V, prior) { | ||
.Call(`_bvarPANELs_sample_w`, aux_V, prior) | ||
} | ||
|
||
sample_s <- function(aux_A, aux_V, aux_Sigma, aux_m, prior) { | ||
.Call(`_bvarPANELs_sample_s`, aux_A, aux_V, aux_Sigma, aux_m, prior) | ||
} | ||
|
||
log_kernel_nu <- function(aux_nu, aux_Sigma_c, aux_Sigma, prior_lambda, C, N, K) { | ||
.Call(`_bvarPANELs_log_kernel_nu`, aux_nu, aux_Sigma_c, aux_Sigma, prior_lambda, C, N, K) | ||
} | ||
|
||
sample_nu <- function(aux_nu, aux_Sigma_c, aux_Sigma, prior) { | ||
.Call(`_bvarPANELs_sample_nu`, aux_nu, aux_Sigma_c, aux_Sigma, prior) | ||
} | ||
|
||
sample_Sigma <- function(aux_Sigma_c_inv, aux_s, aux_nu, prior) { | ||
.Call(`_bvarPANELs_sample_Sigma`, aux_Sigma_c_inv, aux_s, aux_nu, prior) | ||
} | ||
|
||
sample_AV <- function(aux_A_c, aux_Sigma_c_inv, aux_s, aux_m, aux_w, prior) { | ||
.Call(`_bvarPANELs_sample_AV`, aux_A_c, aux_Sigma_c_inv, aux_s, aux_m, aux_w, prior) | ||
} | ||
|
||
sample_A_c_Sigma_c <- function(Y_c, X_c, aux_A, aux_V, aux_Sigma, aux_nu) { | ||
.Call(`_bvarPANELs_sample_A_c_Sigma_c`, Y_c, X_c, aux_A, aux_V, aux_Sigma, aux_nu) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
#' @title Bayesian estimation of a Bayesian Hierarchical Panel Vector | ||
#' Autoregression using Gibbs sampler | ||
#' | ||
#' @description Estimates the Bayesian Hierarchical Panel VAR using the Gibbs | ||
#' sampler proposed by Woźniak (2024). | ||
#' | ||
#' @details | ||
#' The homoskedastic SVAR model is given by the reduced form equation: | ||
#' \deqn{Y_c = A_cX_c + E_c} | ||
#' where \eqn{Y_c} is an \code{T_c x N} matrix of dependent variables for | ||
#' country \code{c}, \eqn{X_c} is a \code{T_c x K} matrix of explanatory | ||
#' variables, \eqn{E_c} is an \code{T_c x N} matrix of error terms, and | ||
#' \eqn{A_c} is an \code{NxK} matrix of country-specific autoregressive slope | ||
#' coefficients and parameters on deterministic terms in \eqn{X_c}. | ||
#' | ||
#' @param specification an object of class BVARPANEL generated using the | ||
#' \code{specify_bvarPANEL$new()} function. | ||
#' @param S a positive integer, the number of posterior draws to be generated | ||
#' @param thin a positive integer, specifying the frequency of MCMC output thinning | ||
#' @param show_progress a logical value, if \code{TRUE} the estimation progress | ||
#' bar is visible | ||
#' | ||
#' @return An object of class PosteriorBVARPANEL containing the Bayesian | ||
#' estimation output and containing two elements: | ||
#' | ||
#' \code{posterior} a list with a collection of \code{S} draws from the | ||
#' posterior distribution generated via Gibbs sampler. | ||
#' \code{last_draw} an object of class BVARPANEL with the last draw of the | ||
#' current MCMC run as the starting value to be passed to the continuation of | ||
#' the MCMC estimation using the \code{estimate()} method. | ||
#' | ||
#' @seealso \code{\link{specify_bvarPANEL}}, \code{\link{specify_posterior_bvarPANEL}} | ||
#' | ||
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me} | ||
#' | ||
#' @method estimate BVARPANEL | ||
#' | ||
#' @examples | ||
#' data(ilo_cubic_panel) # load the data | ||
#' set.seed(123) | ||
#' 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 | ||
#' | ||
#' @export | ||
estimate.BVARPANEL <- function( | ||
specification, | ||
S, | ||
thin = 10L, | ||
show_progress = TRUE | ||
) { | ||
|
||
# get the inputs to estimation | ||
prior = specification$prior$get_prior() | ||
starting_values = specification$starting_values$get_starting_values() | ||
data_matrices = specification$data_matrices$get_data_matrices() | ||
|
||
# estimation | ||
qqq = .Call(`_bvarPANELs_bvarPANEL`, S, data_matrices$Y, data_matrices$X, prior, starting_values, thin, show_progress) | ||
|
||
specification$starting_values$set_starting_values(qqq$last_draw) | ||
output = specify_posterior_bvarPANEL$new(specification, qqq$posterior) | ||
|
||
return(output) | ||
} # END estimate.BVARPANEL | ||
|
||
|
||
|
||
#' @inherit estimate.BVARPANEL | ||
#' | ||
#' @method estimate PosteriorBVARPANEL | ||
#' | ||
#' @param specification an object of class PosteriorBVARPANEL generated using | ||
#' the \code{estimate.BVARPANEL()} function. This setup facilitates the | ||
#' continuation of the MCMC sampling starting from the last draw of the previous | ||
#' run. | ||
#' | ||
#' @export | ||
estimate.PosteriorBVARPANEL <- function(specification, S, thin = 10, show_progress = TRUE) { | ||
|
||
# get the inputs to estimation | ||
prior = specification$last_draw$prior$get_prior() | ||
starting_values = specification$last_draw$starting_values$get_starting_values() | ||
data_matrices = specification$last_draw$data_matrices$get_data_matrices() | ||
|
||
# estimation | ||
qqq = .Call(`_bvarPANELs_bvarPANEL`, S, data_matrices$Y, data_matrices$X, prior, starting_values, thin, show_progress) | ||
|
||
specification$last_draw$starting_values$set_starting_values(qqq$last_draw) | ||
output = specify_posterior_bvarPANEL$new(specification$last_draw, qqq$posterior) | ||
|
||
return(output) | ||
} # END estimate.PosteriorBSVAR |
Oops, something went wrong.