Title: | Bayesian Analysis of a FAVAR Model |
---|---|
Description: | Estimate a FAVAR model by a Bayesian method, based on Bernanke et al. (2005) <DOI:10.1162/0033553053327452>. |
Authors: | Pu Chen [aut, cre] |
Maintainer: | Pu Chen <[email protected]> |
License: | GPL-3 |
Version: | 0.1.3 |
Built: | 2025-03-28 03:34:53 UTC |
Source: | https://github.com/common2016/favar |
Convert auto regression (AR) coefficients to moving average (MA) coefficients
ar2ma(ar, p, n = 11, CharValue = TRUE)
ar2ma(ar, p, n = 11, CharValue = TRUE)
ar |
AR coefficients matrix which is k x kp dimension, k is numbers of variables, and no constant. |
p |
lags orders of AR. |
n |
lags orders of MA generated. |
CharValue |
logical value, whether compute character value. |
the formula is,
where A is MA coefficients, F is AR coefficients.
a matrix which is MA coefficients.
require(vars) data(Canada) ar <- Bcoef(VAR(Canada, p = 2, type = "none")) ar ar2ma(ar, p = 2)
require(vars) data(Canada) ar <- Bcoef(VAR(Canada, p = 2, type = "none")) ar ar2ma(ar, p = 2)
From
may include some information related with
. The function
extract factors from
X
which is not related with R
by iteration
based on Boivin et al. (2009).
BGM(X, R, K = 2, tolerance = 0.001, nmax = 100)
BGM(X, R, K = 2, tolerance = 0.001, nmax = 100)
X |
a large matrix from which principle components are extracted. |
R |
a numeric vector which we are interesting in, for example interest rates. |
K |
the number of extracted principle components. |
tolerance |
the difference between factors when iterating. |
nmax |
the max iterations, see details. |
The algorithm is as follows:
Extract the first K principal components noted from
X
.
Regress X
on and
, and get regression
coefficients
of
.
compute .
Extract the first K principal components noted from
X_t^{(0)}
.
repeat step 2 - step 4 until precision you want.
the first K principle components, i.e. , not containing the information
R
.
Boivin, J., M.P. Giannoni and I. Mihov, Sticky Prices and Monetary Policy: Evidence from Disaggregated US Data. American Economic Review, 2009. 99(1): p. 350-384.
data('regdata') BGM(X = regdata[,1:115],R = regdata[,ncol(regdata)], K = 2)
data('regdata') BGM(X = regdata[,1:115],R = regdata[,ncol(regdata)], K = 2)
Estimate a VAR base on Bayesian method
BVAR( data, plag = 2, iter = 10000, burnin = 5000, prior = list(b0 = 0, vb0 = 0, nu0 = 0, s0 = 0, mn = list(kappa0 = NULL, kappa1 = NULL)), ncores = 1 )
BVAR( data, plag = 2, iter = 10000, burnin = 5000, prior = list(b0 = 0, vb0 = 0, nu0 = 0, s0 = 0, mn = list(kappa0 = NULL, kappa1 = NULL)), ncores = 1 )
data |
a |
plag |
a lag order in VAR |
iter |
iterations of the MCMC |
burnin |
the first random draws discarded in MCMC |
prior |
a list whose elements is named. |
ncores |
the number of CPU cores in parallel computations. |
a list:
A
, the samples drawn for the coefficients of VAR
sigma
, the samples drawn for the variance-covariance of the coefficients of VAR
sumrlt
, a list include varcoef, varse, q25, q975
which are
means, standard errors, 0.25 quantiles and 0.975 quantiles of A
.
Extract Coefficients of a FAVAR Model
## S3 method for class 'favar' coef(object, ...)
## S3 method for class 'favar' coef(object, ...)
object |
a class 'favar'. |
... |
additional arguments affecting the coefficients produced. |
A list
Factor loading matrix in a factor equation.
regression coefficients in VAR equations.
Estimate a FAVAR model by Bernanke et al. (2005).
FAVAR( Y, X, fctmethod = "BBE", slowcode, K = 2, plag = 2, factorprior = list(b0 = 0, vb0 = NULL, c0 = 0.01, d0 = 0.01), varprior = list(b0 = 0, vb0 = 0, nu0 = 0, s0 = 0, mn = list(kappa0 = NULL, kappa1 = NULL)), nburn = 5000, nrep = 15000, standardize = TRUE, ncores = 1 )
FAVAR( Y, X, fctmethod = "BBE", slowcode, K = 2, plag = 2, factorprior = list(b0 = 0, vb0 = NULL, c0 = 0.01, d0 = 0.01), varprior = list(b0 = 0, vb0 = 0, nu0 = 0, s0 = 0, mn = list(kappa0 = NULL, kappa1 = NULL)), nburn = 5000, nrep = 15000, standardize = TRUE, ncores = 1 )
Y |
a matrix. Observable economic variables assumed to drive the dynamics of the economy. |
X |
a matrix. A large macro data set. The meanings of |
fctmethod |
|
slowcode |
a logical vector that identifies which columns of X are slow
moving. Only when |
K |
the number of factors extracted from |
plag |
the lag order in the VAR equation. |
factorprior |
A list whose elements is named sets the prior for the factor equation.
|
varprior |
A list whose elements is named sets the prior of VAR equations.
|
nburn |
the number of the first random draws discarded in MCMC. |
nrep |
the number of the saved draws in MCMC. |
standardize |
Whether standardize? We suggest it does, because in the function VAR equation and factor equation both don't include intercept. |
ncores |
the number of CPU cores in parallel computations. |
Here we simply state the prior distribution setting of VAR. VAR could be written by (Koop and Korobilis, 2010),
You can write down it according to data matrix,
where . We assume that prior distribution of
and
is,
Or you can set the Minnesota prior for variance of , for example,
for the
th equation in
,
is lag order, for won lags of endogenous variables
,for lags of other endogenous variables in the mth equation,
where
is the standard error for residuals of the mth equation.
Based on the priors, you could get corresponding post distribution for the parameters by Markov Chain Monte Carlo (MCMC) algorithm. More details, see Koop and Korobilis (2010).
An object of class "favar" containing the following components:
A list. The estimation results of VAR including estimated coefficients
A
, their variance-covariance matrix sigma
, and other statistical summary for A
.
A array with 3 dimension. and Lamb[i,,]
is factor loading matrix
for factor equations in the th sample of MCMC.
Extracted factors from X
.
Model information containing nburn,nrep,X,Y
and p
, the number of endogenous variables
in the VAR.
Bernanke, B.S., J. Boivin and P. Eliasz, Measuring the Effects of Monetary Policy: A Factor-Augmented Vector Autoregressive (FAVAR) Approach. Quarterly Journal of Economics, 2005. 120(1): p. 387-422.
Boivin, J., M.P. Giannoni and I. Mihov, Sticky Prices and Monetary Policy: Evidence from Disaggregated US Data. American Economic Review, 2009. 99(1): p. 350-384.
Koop, G. and D. Korobilis, Bayesian Multivariate Time Series Methods for Empirical Macroeconomics. 2010: Now Publishers.
summary.favar
, coef.favar
and irf
. All of them are
S3 methods of the "favar" object, and
summary.favar
that prints the estimation results of a FAVAR model, and
coef.favar
that extracts the coefficients in a FAVAR model, and
irf
that computes the impulse response in a FAVAR model.
# data('regdata') # fit <- FAVAR(Y = regdata[,c("Inflation","Unemployment","Fed_funds")], # X = regdata[,1:115], slowcode = slowcode,fctmethod = 'BBE', # factorprior = list(b0 = 0, vb0 = NULL, c0 = 0.01, d0 = 0.01), # varprior = list(b0 = 0,vb0 = 10, nu0 = 0, s0 = 0), # nrep = 15000, nburn = 5000, K = 2, plag = 2) ##---- print FAVAR estimation results------ # summary(fit,xvar = c(3,5)) ##---- or extract coefficients------ # coef(fit) ##---- plot impulse response figure------ # library(patchwork) # dt_irf <- irf(fit,resvar = c(2,9,10))
# data('regdata') # fit <- FAVAR(Y = regdata[,c("Inflation","Unemployment","Fed_funds")], # X = regdata[,1:115], slowcode = slowcode,fctmethod = 'BBE', # factorprior = list(b0 = 0, vb0 = NULL, c0 = 0.01, d0 = 0.01), # varprior = list(b0 = 0,vb0 = 10, nu0 = 0, s0 = 0), # nrep = 15000, nburn = 5000, K = 2, plag = 2) ##---- print FAVAR estimation results------ # summary(fit,xvar = c(3,5)) ##---- or extract coefficients------ # coef(fit) ##---- plot impulse response figure------ # library(patchwork) # dt_irf <- irf(fit,resvar = c(2,9,10))
Compute GIRF of linear VAR by Koop et al. (1996)
GI(ma, sig_u, imp_var = 1, unit = "sd")
GI(ma, sig_u, imp_var = 1, unit = "sd")
ma |
a list, it's MA coefficients from |
sig_u |
a covariance matrix from VAR models. Note the order of variables in |
imp_var |
a numerical scalar which specifies the impulse variable. |
unit |
|
a data frame, its row is variables and its column is horizons.
Koop, G., M.H. Pesaran and S. Potter, Impulse Response Analysis in Nonlinear Multivariate Models. Journal of Econometrics, 1996. 74: p. 119-147.
Based on a shock to one standard deviation, compute the IRF.
irf( fit, irftype = "orth", tcode = "level", resvar = 1, impvar = NULL, nhor = 10, ci = 0.8, showplot = TRUE )
irf( fit, irftype = "orth", tcode = "level", resvar = 1, impvar = NULL, nhor = 10, ci = 0.8, showplot = TRUE )
fit |
a "favar" object. |
irftype |
|
tcode |
a scalar |
resvar |
It's column indexes in |
impvar |
Specify a impulse variable. A numeric scalar which is position of variables in VAR equation.
If it's |
nhor |
IRF horizon, default is |
ci |
confidence interval, default is 0.8. |
showplot |
whether show figure. |
A list containing 2 elements. The first element is a object from ggplot2::ggplot
, the
second element is raw data for IRF.
# see FAVAR function
# see FAVAR function
Compute Impulse Response for Every Sample of MCMC
irf_single(i, varrlt, Lamb, Ynum, type = "orth", impvar = 1, nhor)
irf_single(i, varrlt, Lamb, Ynum, type = "orth", impvar = 1, nhor)
i |
the |
varrlt |
estimation results for VAR equations, and it's got by |
Lamb |
a array with 3 dimension. and |
Ynum |
the |
type |
|
impvar |
a numeric scalar which is position of variables in VAR equation.
If it's |
nhor |
IRF horizon, default is |
IRF matrix, the dimension is ncol(Xmatrix) + ncol(Y)
xnhor
.
A matrix containing a large macro data set regdata
.
regdata
regdata
A matrix regdata
with 190 rows and 118 variables,
X
is the first column through the 115th column in regdata
, a large macro data set
Y
is the 116th column through the 118th column in regdata
, driving the dynamics of the economy
https://sites.google.com/site/garykoop/home/computer-code-2
A logic vector, record the variables that are the 1st column through the 115th column
in regdata
is slow-moving or not.
slowcode
slowcode
An object of class logical
of length 115.
https://sites.google.com/site/garykoop/home/computer-code-2
S3 method for class "favar".
## S3 method for class 'favar' summary(object, xvar = NULL, ...)
## S3 method for class 'favar' summary(object, xvar = NULL, ...)
object |
a "favar" object from function |
xvar |
a numeric vector, which variables in |
... |
additional arguments affecting the summary produced. |
No return value, called for side effects
# see FAVAR function
# see FAVAR function
Record the transformation form for the 1st column through the 115th column
in regdata
, and 'level' is Level, 'ln' is logarithm, 'Dln' is first difference of logarithm.
tcode
tcode
An object of class character
of length 118.
https://sites.google.com/site/garykoop/home/computer-code-2