Bayesian Macroeconometrics in R (BMR) is an R interface to BM++, a templated C++ library for estimating Bayesian Vector Autoregression (BVAR) and Dynamic Stochastic General Equilibrium (DSGE) models.
Features:
- BVAR models with flexible prior specification, including: the Minnesota prior; normal-inverse-Wishart prior; and Matias Villani's steady-state prior.
- BVARs with time-varying parameters.
- Solve DSGE models using the method of undetermined coefficients (Uhlig's method) and Sims' QZ method.
- Estimate DSGE and DSGE-VAR models.
The simplest installation method is via the devtools package.
install.packages("devtools")
library(devtools)
install_github("kthohr/BMR")Note that BMR requires compilation, so approproate development tools are necessary to install the package.
See http://www.kthohr.com/bmr for documentation and replication files.
Estimate a BVAR model with Minnesota prior:
library("BMR")
data(BMRMCData)
# create bvarm objectbvar_obj<- new(bvarm) # add data; add a constant; and set lags (p) = 2bvar_obj$build(bvarMCdata,TRUE,2)
# prior of 0.5 on own-first-lags, and take default values for the hyperparametersbvar_obj$prior(c(0.5,0.5))
# draw from the posterior distributionbvar_obj$gibbs(10000)
# posterior mean and variancebvar_obj$alpha_pt_meanbvar_obj$alpha_pt_var# plot IRFs
IRF(bvar_obj,20,save=FALSE)Solve a three-equation New-Keynesian model:
## Solve the NK model with gensys#
rm(list=ls())
library(BMR)
#alpha<-0.33vartheta<-6beta<-0.99theta<-0.6667eta<-1phi<-1phi_pi<-1.5phi_y<-0.5/4rho_a<-0.90rho_v<-0.5BigTheta<- (1-alpha)/(1-alpha+alpha*vartheta)
kappa<- (((1-theta)*(1-beta*theta))/(theta))*BigTheta*((1/eta)+((phi+alpha)/(1-alpha)))
psi<- (eta*(1+phi))/(1-alpha+eta*(phi+alpha))
sigma_T<-1sigma_M<-0.25G0_47<- (1/eta)*psi*(rho_a-1)
#Order: yg, y, pi, rn, i, n, a, v, yg_t+1, pi_t+1Gamma0<- rbind(c( -1, 0, 0, eta, -eta/4, 0, 0, 0, 1, eta/4),
c( kappa, 0, -1/4, 0, 0, 0, 0, 0, 0, beta/4),
c( phi_y, 0,phi_pi/4, 0, -1/4, 0, 0, 1, 0, 0),
c( 0, 0, 0, -1, 0, 0, G0_47, 0, 0, 0),
c( 0, -1, 0, 0, 0, 1-alpha, 1, 0, 0, 0),
c( -1, 1, 0, 0, 0, 0, -psi, 0, 0, 0),
c( 0, 0, 0, 0, 0, 0, 1, 0, 0, 0),
c( 0, 0, 0, 0, 0, 0, 0, 1, 0, 0),
c( 1, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c( 0, 0, 1, 0, 0, 0, 0, 0, 0, 0))
Gamma1<- rbind(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c( 0, 0, 0, 0, 0, 0, rho_a, 0, 0, 0),
c( 0, 0, 0, 0, 0, 0, 0, rho_v, 0, 0),
c( 0, 0, 0, 0, 0, 0, 0, 0, 1, 0),
c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 1))
#C<-matrix(0,10,1)
Psi<-matrix(0,10,2)
Psi[7,1] <-1Psi[8,2] <-1Pi<-matrix(0,10,2)
Pi[9,1] <-1Pi[10,2] <-1#Sigma<- rbind(c(sigma_T^2, 0), c( 0, sigma_M^2))
## build the model and solve itdsge_obj<- new(gensys)
dsge_obj$build(Gamma0,Gamma1,C,Psi,Pi)
dsge_obj$solve()
# Y_t = G * Y_{t-1} + Impact * e_tdsge_obj$G_soldsge_obj$impact_sol# set shocks (Sigma); then plot IRFs and simulate some datadsge_obj$shocks_cov=Sigmavar_names<- c("Output Gap","Output","Inflation","Natural Int",
"Nominal Int","Labour Supply","Technology","MonetaryPolicy")
dsge_irf<- IRF(dsge_obj,12,var_names=var_names)
dsge_sim<-dsge_obj$simulate(800,200)Keith O'Hara
GPL (>= 2)