View source: R/estimation_tools.R
DfmRawImp | R Documentation |
DfmRawImp
estimates non-structural IRFs for S-DFM according to section 2.3.1 in
Estimation of Impulse-Response Functions with Dynamic Factor Models:
A New Parametrization available at https://arxiv.org/pdf/2202.00310.pdf.
The code used here follows closely to that of given in the supplementary
material to the Forni and Gambetti (2010), available at
http://pareto.uab.es/lgambetti/ReplicaForniGambettiJME.zip.
DfmRawImp(X, q, r, k, h)
X |
|
q |
The dynamic factor dimension |
r |
Number of static factors, must be larger than or equal to |
k |
The VAR order for static factors |
h |
Estimate IRF |
(n x q x h+1)
-dimensional array of impulse responses
Forni, M., & Gambetti, L. (2010). The dynamic effects of monetary policy: A structural factor model approach. Journal of Monetary Economics, 57(2), 203-216.
# Consider the following monetary policy example for illustration
# taken from Forni and Gambetti (2010)
X <- FG_data$df
# positions of IP, CPI, FFR, and US/Swiss exchange rate in the data
int_ix <- c(5, 96, 75, 106)
# Estimate the static factor dimension r
(PC_r <- baingcriterion(X, rmax = 25)$PC)
(IC_r <- baingcriterion(X, rmax = 25)$IC)
# As seen from this example, the criteria are not in consensus about the
# static factor dimension and suggest also the maximum value as an
# estimate for r dimension. Choose a grid of values of r to compare results:
r <- c(4,10,16)
# We fix dynamic factor dimension q to 4 and the VAR order k to 2
est_irfs <- lapply(r, function(x) DfmRawImp(X = X, q = 4, r = x, k = 2, h = 50))
# Recursive identification of the model
for(j in 1:length(est_irfs)){
# extract the lag zero polynomial corresponding to the variables of interest
b0 <- unclass(est_irfs[[j]])[int_ix, , 1]
# cholesky decomposition of the residual covariance matrix
C <- b0 %>% tcrossprod() %>% chol() %>% t()
# recursive identification of the IRFs
chol_irf <- irf_x(est_irfs[[j]], post_mat = solve(b0)%*%C)
# normalize to 50bp shock to FFR on impact
chol_irf <- chol_irf/chol_irf[int_ix[3],3,1]*0.5
# cumulate IRFS for IP and inflation
chol_irf[int_ix[c(1,2)], ,] <- chol_irf[int_ix[c(1,2)], ,] %>%
apply(MARGIN = c(1,2), FUN = cumsum) %>%
aperm(perm = c(2,3,1))
# produce IRF figures
est_irfs[[j]] <- plot_irfs(t(chol_irf[int_ix, 3,]),
c("Ind_prod", "Inflation", "FF_rate", "ExRate"),
plot_title = paste("DFM with ", r[j], " static factors", sep=""))
}
# plot the IRFs into a single figure
## Not run:
gridExtra::marrangeGrob(c(est_irfs[[1]], est_irfs[[2]], est_irfs[[3]]),
ncol = 3, nrow = 4, top = NULL)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.