Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kthohr committed Sep 12, 2017
1 parent 254076b commit dac4040
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 295 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: r
cache: packages
sudo: required
warnings_are_errors: false

Expand Down
18 changes: 10 additions & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
useDynLib(BMR)

importFrom(Rcpp, evalCpp)
import(ggplot2)
importFrom(Rcpp, evalCpp)
importFrom(grid, grid.newpage, viewport, pushViewport, grid.layout)
importFrom("grDevices", "cairo_ps", "dev.list", "dev.off")
importFrom("stats", "acf", "dbeta", "dgamma", "dnorm", "dunif",
"embed", "optim", "pacf", "qnorm", "rnorm", "runif", "sd",
"var")
importFrom("stats", "acf", "embed", "optim", "pacf", "qnorm", "rnorm", "runif", "sd", "var")

exportClasses("Rcpp_bvarm")
exportClasses("Rcpp_bvars")
exportClasses("Rcpp_bvars")
exportClasses("Rcpp_cvar")
exportClasses("Rcpp_bvartvp")
exportClasses("Rcpp_gensys")
exportClasses("Rcpp_uhlig")
exportClasses("Rcpp_dsge_gensys")
exportClasses("Rcpp_dsgevar_gensys")

export(IRF,forecast,modecheck,prior,stationarity,gtsplot,gacf,gpacf)

Expand All @@ -22,13 +24,13 @@ S3method(plot, Rcpp_bvarm)
S3method(plot, Rcpp_bvars)
S3method(plot, Rcpp_bvarw)
S3method(plot, Rcpp_bvartvp)
S3method(plot, EDSGE)
S3method(plot, DSGEVAR)
S3method(plot, Rcpp_dsge_gensys)
S3method(plot, Rcpp_dsgevar_gensys)

S3method(forecast, Rcpp_bvarm)
S3method(forecast, Rcpp_bvars)
S3method(forecast, Rcpp_bvarw)
S3method(forecast, Rcpp_cvar)

S3method(modecheck, EDSGE)
S3method(modecheck, DSGEVAR)
S3method(modecheck, Rcpp_dsge_gensys)
S3method(modecheck, Rcpp_dsgevar_gensys)
2 changes: 1 addition & 1 deletion R/Plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,6 @@ plot.Rcpp_dsgevar_gensys <- function(x,parnames=NULL,BinDenom=40,MCMCplot=FALSE,

.plotdsgevar <- function(obj,parnames=NULL,BinDenom=40,trace_plot=FALSE,save=FALSE,height=13,width=13)
{
dsge_obj <- obj$get_dsge()
dsge_obj <- obj$dsge
.plotedsge(dsge_obj,parnames,BinDenom,trace_plot,save,height,width)
}
2 changes: 1 addition & 1 deletion src/bmlib/include/dsge/dsgevar_class.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ dsgevar<T>::IRF(const int n_irf_periods)
arma::mat dsge_obs_impact = dsge_obj_copy.kalman_mat_H.t() * G_state*arma::chol(shocks_cov,"lower");

arma::mat Q_dcm, R_dcm;
arma::qr(Q_dcm,R_dcm,dsge_obs_impact);
arma::qr(Q_dcm,R_dcm,dsge_obs_impact.t());

Q_dcm *= -1.0;
R_dcm *= -1.0;
Expand Down
8 changes: 6 additions & 2 deletions src/modules/dsge_R.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class dsge_gensys_R : public bm::dsge<bm::gensys>

void model_fn_R(const arma::vec& pars_inp, bm::gensys& lrem_obj_inp, arma::mat& shocks_cov_out, arma::mat& C_out, arma::mat& H_out, arma::mat& R_out);

//

SEXP get_model_fn();
void set_model_fn(SEXP model_fn_inp);
void eval_model(Rcpp::NumericVector pars_inp);

Expand Down Expand Up @@ -93,14 +96,15 @@ class dsgevar_gensys_R : public bm::dsgevar<bm::gensys>
arma::vec mcmc_initial_lb;
arma::vec mcmc_initial_ub;

void model_fn_R(const arma::vec& pars_inp, bm::gensys& lrem_obj_inp, arma::mat& shocks_cov_out, arma::mat& C_out, arma::mat& H_out, arma::mat& R_out);

// member functions

void build_R(const arma::mat& data_raw, bool cons_term_inp, int p_inp, double lambda_inp);

arma::mat get_dsge_draws();

void model_fn_R(const arma::vec& pars_inp, bm::gensys& lrem_obj_inp, arma::mat& shocks_cov_out, arma::mat& C_out, arma::mat& H_out, arma::mat& R_out);

SEXP get_model_fn();
void set_model_fn(SEXP model_fn_inp);
void eval_model(Rcpp::NumericVector pars_inp);

Expand Down
40 changes: 30 additions & 10 deletions src/modules/dsge_gensys_R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ RCPP_MODULE(dsge_gensys_module)
.field( "mcmc_initial_lb", &dsge_gensys_R::mcmc_initial_lb )
.field( "mcmc_initial_ub", &dsge_gensys_R::mcmc_initial_ub )

.property( "lrem", &dsge_gensys_R::get_lrem_R, &dsge_gensys_R::set_lrem_R )
// .property( "model", &dsge_gensys_R::get_model_fn, &dsge_gensys_R::set_model_fn )

.method( "get_model_fn", &dsge_gensys_R::get_model_fn )
.method( "set_model_fn", &dsge_gensys_R::set_model_fn )
.method( "eval_model", &dsge_gensys_R::eval_model )

.method( "get_lrem", &dsge_gensys_R::get_lrem_R )
.method( "set_lrem", &dsge_gensys_R::set_lrem_R )

.method( "set_bounds", &dsge_gensys_R::set_bounds_R )
.method( "set_prior", &dsge_gensys_R::set_prior_R )

Expand All @@ -72,6 +73,12 @@ RCPP_MODULE(dsge_gensys_module)
//
// wrapper functions to catch errors and handle memory pointers

SEXP
dsge_gensys_R::get_model_fn()
{
return model_fn_SEXP;
}

void
dsge_gensys_R::set_model_fn(SEXP model_fn_inp)
{
Expand All @@ -92,6 +99,8 @@ dsge_gensys_R::set_model_fn(SEXP model_fn_inp)
}
}

//

void
dsge_gensys_R::eval_model(Rcpp::NumericVector pars_inp)
{
Expand Down Expand Up @@ -151,14 +160,18 @@ dsge_gensys_R::model_fn_R(const arma::vec& pars_inp, bm::gensys& lrem_obj_inp, a
}
}

gensys_R dsge_gensys_R::get_lrem_R()
// get and set LREM

gensys_R
dsge_gensys_R::get_lrem_R()
{
gensys_R lrem_obj_out = static_cast<gensys_R&>(lrem_obj);

return lrem_obj_out;
}

void dsge_gensys_R::set_lrem_R(gensys_R lrem_obj_inp)
void
dsge_gensys_R::set_lrem_R(gensys_R lrem_obj_inp)
{
try {
lrem_obj = static_cast<bm::gensys&>(lrem_obj_inp);
Expand All @@ -171,7 +184,8 @@ void dsge_gensys_R::set_lrem_R(gensys_R lrem_obj_inp)

// set bounds and prior

void dsge_gensys_R::set_bounds_R(arma::vec lower_bounds_inp, arma::vec upper_bounds_inp)
void
dsge_gensys_R::set_bounds_R(arma::vec lower_bounds_inp, arma::vec upper_bounds_inp)
{
try {
const int n_vals = lower_bounds_inp.n_elem;
Expand All @@ -194,7 +208,8 @@ void dsge_gensys_R::set_bounds_R(arma::vec lower_bounds_inp, arma::vec upper_bou
}
}

void dsge_gensys_R::set_prior_R(const arma::uvec& prior_form_inp, const arma::mat& prior_pars_inp)
void
dsge_gensys_R::set_prior_R(const arma::uvec& prior_form_inp, const arma::mat& prior_pars_inp)
{
try {
this->set_prior(prior_form_inp,prior_pars_inp);
Expand All @@ -207,7 +222,8 @@ void dsge_gensys_R::set_prior_R(const arma::uvec& prior_form_inp, const arma::ma

//

SEXP dsge_gensys_R::estim_mode_R(const arma::vec& initial_vals)
SEXP
dsge_gensys_R::estim_mode_R(const arma::vec& initial_vals)
{
try {
optim::opt_settings settings;
Expand All @@ -231,7 +247,8 @@ SEXP dsge_gensys_R::estim_mode_R(const arma::vec& initial_vals)
return R_NilValue;
}

void dsge_gensys_R::estim_mcmc_R(const arma::vec& initial_vals, int n_pop, int n_gen, int n_burnin)
void
dsge_gensys_R::estim_mcmc_R(const arma::vec& initial_vals, int n_pop, int n_gen, int n_burnin)
{
try {
mcmc::mcmc_settings settings;
Expand All @@ -255,7 +272,10 @@ void dsge_gensys_R::estim_mcmc_R(const arma::vec& initial_vals, int n_pop, int n
}
}

SEXP dsge_gensys_R::IRF_R(int n_irf_periods)
//

SEXP
dsge_gensys_R::IRF_R(int n_irf_periods)
{
try {
arma::cube irf_vals = this->IRF(n_irf_periods);
Expand Down
Loading

0 comments on commit dac4040

Please sign in to comment.