fdlm: MCMC Sampling Algorithm for the Functional Dynamic Linear...

Description Usage Arguments Value Note Examples

View source: R/mcmc_sampler.R

Description

Runs the MCMC for the functional dynamic linear model (with no predictor variables). The dynamic factors are modeled using an AR(1) model.

Usage

1
2
3
fdlm(Y, tau, K = NULL, nsave = 1000, nburn = 1000, nskip = 3,
  mcmc_params = list("beta", "fk"), use_obs_SV = FALSE, X_Tp1 = 1,
  includeBasisInnovation = FALSE, Con_mat = NULL)

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

the m x d matrix of coordinates 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

  • "beta" (dynamic factors)

  • "fk" (loading curves)

  • "mu_k" (intercept)

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

  • "Yhat" (fitted values)

  • "Ypred" (posterior predictive values)

  • "Yfore" (one-step forecast; includes the estimate and the distribution)

use_obs_SV

logical; when TRUE, include a stochastic volatility model for the observation error variance

X_Tp1

the p x 1 matrix of predictors at the forecasting time point T + 1

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)

Con_mat

a Jc x m matrix of constraints for the loading curves such that Con_mat*fk = 0 for each loading curve fk; default is NULL for no constraints.

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 or Ypred, which are 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
# Simulate some data (w/o predictors):
sim_data = simulate_dfosr(T = 100, m = 20,
                          p_0 = 0, p_1 = 0)
Y = sim_data$Y; tau = sim_data$tau
T = nrow(Y); m = ncol(Y); # Dimensions

# Run the MCMC w/ K = 6:
out = fdlm(Y = Y, tau = tau, K = 6,
           mcmc_params = list("beta", "fk", "Yhat", "Ypred"))

# Plot the factors:
plot_factors(post_beta = out$beta)

# Plot the loading curves:
plot_flc(post_fk = out$fk, tau = tau)

# Plot a fitted value w/ posterior predictive credible intervals:
i = sample(1:T, 1); # Select a random time i
plot_fitted(y = Y[i,],
            mu = colMeans(out$Yhat)[i,],
            postY = out$Ypred[,i,],
            y_true = sim_data$Y_true[i,],
            t01 = tau)

drkowal/dfosr documentation built on May 7, 2020, 3:09 p.m.