Description Usage Arguments Value Note Examples
Runs the MCMC for the (univariate) FDLM under some default conditions:
A random walk model for the dynamic factors;
A full K x K
non-dynamic evolution error variance matrix;
A non-dynamic scalar multiple of the identity for the observation error variance.
1 2 3 |
Y |
the |
tau |
vector of observation points ( |
K |
the number of factors; if NULL, use SVD-based proportion of variability explained |
nsave |
number of MCMC iterations to record |
nburn |
number of MCMC iterations to discard (burin-in) |
nskip |
number of MCMC iterations to skip between saving iterations, i.e., save every (nskip + 1)th draw |
mcmc_params |
named list of parameters for which we store the MCMC output; must be one or more of
|
h_step |
integer for h-step forecasting; if NULL, do not compute any forecasts |
useFastImpute |
logical; when TRUE, use imputation/projection scheme for the dynamic factors; otherwise use full state space model for factors (slower) |
use_obs_SV |
logical; when TRUE, include a stochastic volatility model for the observation error variance |
includeBasisInnovation |
logical; when TRUE, include an iid basis coefficient term for residual correlation (i.e., the idiosyncratic error term for a factor model on the full basis matrix) |
computeDIC |
logical; if TRUE, compute the deviance information criterion |
A named list of the nsave
MCMC samples for the parameters named in mcmc_params
If Tm
is large, then storing all posterior samples for Yhat
, which is nsave x T x m
, may be inefficient
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # Read in the yield curve data (US or UK):
data("US_Yields") # data("UK_Yields")
# Restrict to dates since 2012:
Y = Y[which(dates > as.Date("2012-01-01")),];
dates = dates[which(dates > as.Date("2012-01-01"))] # subset the dates for easy reference
# Center and scale for numerical purposes:
Y = scale(Y)
# Run the MCMC:
mcmc_output = fdlm0(Y, tau, K = 3,
nsave = 1000, nburn = 100, nskip = 2,
mcmc_params = list("beta", "fk", "Yhat", "sigma_e"))
# Plot the factors:
plot_factors(mcmc_output$beta, dates)
# Plot the factor loading curves:
plot_flc(mcmc_output$fk, tau)
# Some diagnostics: effective sample size(s) (may be slow!)
getEffSize(mcmc_output$beta)
getEffSize(mcmc_output$fk)
# getEffSize(mcmc_output$Yhat)
# Check the residuals:
Yhat = colMeans(mcmc_output$Yhat)
resids = Y - Yhat
dev.new(); persp(tau, dates, t(resids))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.