fdlm0: MCMC Sampling Algorithm for the FDLM

Description Usage Arguments Value Note Examples

View source: R/mcmc_sampler.R

Description

Runs the MCMC for the (univariate) FDLM under some default conditions:

  1. A random walk model for the dynamic factors;

  2. A full K x K non-dynamic evolution error variance matrix;

  3. A non-dynamic scalar multiple of the identity for the observation error variance.

Usage

1
2
3
fdlm0(Y, tau, K = NULL, nsave = 1000, nburn = 1000, nskip = 10,
  mcmc_params = list("beta", "fk"), h_step = NULL, useFastImpute = TRUE,
  use_obs_SV = FALSE, includeBasisInnovation = TRUE, computeDIC = TRUE)

Arguments

Y

the T x m data observation matrix, where T is the number of time points and m is the number of observation points (NAs allowed)

tau

vector of observation points (m-dimensional)

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

  • "beta" (factors)

  • "fk" (loading curves)

  • "sigma_et" (observation error SD; possibly dynamic)

  • "Wt" (evolution error variance)

  • "Yhat" (fitted values)

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 DIC and the effective number of parameters p_d

Value

A named list of the nsave MCMC samples for the parameters named in mcmc_params

Note

If Tm is large, then storing all posterior samples for Yhat, which is nsave x T x m, may be inefficient

Examples

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

drkowal/FDLM documentation built on May 20, 2019, 5:20 p.m.