Package 'FAVAR'

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] , Chen Chen [aut], Gary Koop [cph], Dimitris Korobilis [cph]
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

Help Index


ar2ma

Description

Convert auto regression (AR) coefficients to moving average (MA) coefficients

Usage

ar2ma(ar, p, n = 11, CharValue = TRUE)

Arguments

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.

Details

the formula is,

As=F1As1+F2As2+...+FpAspA_s = F_1 * A_{s-1} + F_2 * A_{s-2} + ... + F_p * A_{s-p}

where A is MA coefficients, F is AR coefficients.

Value

a matrix which is MA coefficients.

Examples

require(vars)
data(Canada)
ar <- Bcoef(VAR(Canada, p = 2, type = "none"))
ar
ar2ma(ar, p = 2)

Separate RR From XX

Description

XX may include some information related with RR. The function extract factors from X which is not related with R by iteration based on Boivin et al. (2009).

Usage

BGM(X, R, K = 2, tolerance = 0.001, nmax = 100)

Arguments

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.

Details

The algorithm is as follows:

  1. Extract the first K principal components noted Ft(0)F_t^{(0)} from X.

  2. Regress X on Ft(0)F_t^{(0)} and RtR_t, and get regression coefficients βR(0)\beta_R^{(0)} of RtR_t.

  3. compute X0(0)=XtRtβRX_0^{(0)} = X_t- R_t \beta_R.

  4. Extract the first K principal components noted Ft(1)F_t^{(1)} from X_t^{(0)}.

  5. repeat step 2 - step 4 until precision you want.

Value

the first K principle components, i.e. Ft(n)F_t^{(n)}, not containing the information R.

References

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.

Examples

data('regdata')
BGM(X = regdata[,1:115],R = regdata[,ncol(regdata)], K = 2)

Bayesian Estimation of VAR

Description

Estimate a VAR base on Bayesian method

Usage

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
)

Arguments

data

a ts object which include all endogenous variables in VAR

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. b0 is the prior of mean of β\beta, and vb0 is the prior of the variance of β\beta. nu0 is the degree of freedom of Wishart distribution for Σ1\Sigma^{-1}, i.e., a shape parameter, and s0^{-1} is scale parameters for the Wishart distribution. mn sets the Minnesota prior. If prior$mn$kappa0 is not NULL, b0,vb0 is neglected.

ncores

the number of CPU cores in parallel computations.

Value

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

Description

Extract Coefficients of a FAVAR Model

Usage

## S3 method for class 'favar'
coef(object, ...)

Arguments

object

a class 'favar'.

...

additional arguments affecting the coefficients produced.

Value

A list

fct_loading

Factor loading matrix in a factor equation.

varcoef

regression coefficients in VAR equations.


FAVAR

Description

Estimate a FAVAR model by Bernanke et al. (2005).

Usage

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
)

Arguments

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 X and Y is same as ones of Bernanke et al. (2005).

fctmethod

'BBE' or 'BGM'. 'BBE'(default) means the factors extracted method by Bernanke et al. (2005), and 'BGM' means the factors extracted method by Boivin et al. (2009).

slowcode

a logical vector that identifies which columns of X are slow moving. Only when fctmethod is set as 'BBE', slowcode is valid.

K

the number of factors extracted from X.

plag

the lag order in the VAR equation.

factorprior

A list whose elements is named sets the prior for the factor equation. b0 is the prior of mean of regression coefficients β\beta,and vb0 is the prior of the variance of β\beta, and c0/2 and d0/2 are prior parameters of the variance of the error σ2\sigma^{-2}, and they are the shape and scale parameters of Gamma distribution, respectively.

varprior

A list whose elements is named sets the prior of VAR equations. b0 is the prior of mean of VAR coefficients β\beta, and vb0 is the prior of the variance of β\beta, it's a scalar that means priors of variance is same, or a vector whose length equals the length of β\beta. nu0 is the degree of freedom of Wishart distribution for Σ1\Sigma^{-1}, i.e., a shape parameter, and s0 is a inverse scale parameter for the Wishart distribution, and it's a matrix with ncol(s0)=nrow(s0)=the number of endogenous variables in VAR. If it's a scalar, it means the entry of the matrix is same. mn sets the Minnesota prior. If varprior$mn$kappa0 is not NULL, b0,vb0 is neglected. mn's element kappa0 controls the tightness of the prior variance for self-variables lag coefficients, the prior variance is κ0/lag2\kappa_0/lag^2, another element kappa1 controls the cross-variables lag coefficients spread, the prior variance is κ0κ1lag2σm2σn2,mn\frac{\kappa_0\kappa_1}{lag^2}\frac{\sigma_m^2}{\sigma_n^2}, m\ne n. See details.

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.

Details

Here we simply state the prior distribution setting of VAR. VAR could be written by (Koop and Korobilis, 2010),

yt=Ztβ+εt,εtN(0,Σ)y_t= Z_t\beta + \varepsilon_t, \varepsilon_t\sim N(0,\Sigma)

You can write down it according to data matrix,

Y=Zβ+ε,εN(0,IΣ)Y= Z\beta + \varepsilon, \varepsilon\sim N(0,I\otimes \Sigma)

where Y=(y1,y2,,yT),Z=(Z,Z2,,ZT),ε=(ε1,ε2,,εT)Y = (y_1,y_2,\cdots, y_T)',Z=(Z_,Z_2,\cdots,Z_T)',\varepsilon=(\varepsilon_1,\varepsilon_2,\cdots,\varepsilon_T). We assume that prior distribution of β\beta and Σ1\Sigma^{-1} is,

βN(b0,Vb0),Σ1W(S01,ν0)\beta\sim N(b0,V_{b0}), \Sigma^{-1}\sim W(S_0^{-1},\nu_0)

Or you can set the Minnesota prior for variance of β\beta, for example, for the mmth equation in yt=Ztβ+εty_t= Z_t\beta + \varepsilon_t,

  • κ0l2,l\frac{\kappa_0}{l^2},l is lag order, for won lags of endogenous variables

  • κ0κ1l2σm2σn2,mn\frac{\kappa_0\kappa_1}{l^2}\frac{\sigma_m^2}{\sigma_n^2}, m\ne n,for lags of other endogenous variables in the mth equation, where σm\sigma_m 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).

Value

An object of class "favar" containing the following components:

varrlt

A list. The estimation results of VAR including estimated coefficients A, their variance-covariance matrix sigma, and other statistical summary for A.

Lamb

A array with 3 dimension. and Lamb[i,,] is factor loading matrix for factor equations in the iith sample of MCMC.

factorx

Extracted factors from X

.

model_info

Model information containing nburn,nrep,X,Y and p, the number of endogenous variables in the VAR.

References

  1. 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.

  2. 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.

  3. Koop, G. and D. Korobilis, Bayesian Multivariate Time Series Methods for Empirical Macroeconomics. 2010: Now Publishers.

See Also

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.

Examples

# 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))

Generalized Impulse Response Function (GIRF)

Description

Compute GIRF of linear VAR by Koop et al. (1996)

Usage

GI(ma, sig_u, imp_var = 1, unit = "sd")

Arguments

ma

a list, it's MA coefficients from ar2ma

sig_u

a covariance matrix from VAR models. Note the order of variables in sig_u is same with one of ma[[i]].

imp_var

a numerical scalar which specifies the impulse variable.

unit

'sd' is one standard deviation shock which is default, and 'one' is one unit shock.

Value

a data frame, its row is variables and its column is horizons.

References

Koop, G., M.H. Pesaran and S. Potter, Impulse Response Analysis in Nonlinear Multivariate Models. Journal of Econometrics, 1996. 74: p. 119-147.


Impulse Response Function for FAVAR

Description

Based on a shock to one standard deviation, compute the IRF.

Usage

irf(
  fit,
  irftype = "orth",
  tcode = "level",
  resvar = 1,
  impvar = NULL,
  nhor = 10,
  ci = 0.8,
  showplot = TRUE
)

Arguments

fit

a "favar" object.

irftype

'orth' is orthogonal IRF, and 'gen' is generalized IRF.

tcode

a scalar 'level' or a vector whose length equal ncol(X)+ncol(Y). X,Y is the parameters of the FAVAR function. If the variable is taken the logarithm('ln') or the first difference of logarithm('Dln'), the IRF needs to return to its level value, and you can set the parameters. Default is 'level'.

resvar

It's column indexes in cbind(XY) that specify response variables. It's a scalar or a vector. A change variable cause a change of another variable, and the former is viewed as impulse variable, the latter is viewed as response variable.

impvar

Specify a impulse variable. A numeric scalar which is position of variables in VAR equation. If it's NULL that is default, its position is the last.

nhor

IRF horizon, default is 10.

ci

confidence interval, default is 0.8.

showplot

whether show figure. TRUE is default. If multiple pictures would be printed, the package patchwork is needed to be loaded.

Value

A list containing 2 elements. The first element is a object from ggplot2::ggplot, the second element is raw data for IRF.

Examples

# see FAVAR function

Compute Impulse Response for Every Sample of MCMC

Description

Compute Impulse Response for Every Sample of MCMC

Usage

irf_single(i, varrlt, Lamb, Ynum, type = "orth", impvar = 1, nhor)

Arguments

i

the iith sample in MCMC

varrlt

estimation results for VAR equations, and it's got by BayesVAR.

Lamb

a array with 3 dimension. and Lamb[i,,] is factor loading matrix for factor equations.

Ynum

the ncol(Y).

type

'orth' is orthogonal IRF, and 'gen' is generalized IRF.

impvar

a numeric scalar which is position of variables in VAR equation. If it's NULL that is default, its position is the last.

nhor

IRF horizon, default is NULL

Value

IRF matrix, the dimension is ncol(Xmatrix) + ncol(Y)xnhor.


Sample Data

Description

A matrix containing a large macro data set regdata.

Usage

regdata

Format

A matrix regdata with 190 rows and 118 variables,

X

X is the first column through the 115th column in regdata, a large macro data set

Y

Y is the 116th column through the 118th column in regdata, driving the dynamics of the economy

Source

https://sites.google.com/site/garykoop/home/computer-code-2


Slow-moving or Not

Description

A logic vector, record the variables that are the 1st column through the 115th column in regdata is slow-moving or not.

Usage

slowcode

Format

An object of class logical of length 115.

Source

https://sites.google.com/site/garykoop/home/computer-code-2


Print Results of FAVAR

Description

S3 method for class "favar".

Usage

## S3 method for class 'favar'
summary(object, xvar = NULL, ...)

Arguments

object

a "favar" object from function FAVAR.

xvar

a numeric vector, which variables in X was printed. It's a index. If it's NULL, estimation results for X = F + Y is not printed.

...

additional arguments affecting the summary produced.

Value

No return value, called for side effects

Examples

# see FAVAR function

Transformation Form for X

Description

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.

Usage

tcode

Format

An object of class character of length 118.

Source

https://sites.google.com/site/garykoop/home/computer-code-2