Learn R Programming

dsp (version 1.2.0)

btf_nb: MCMC Sampler for Bayesian Trend Filtering with Negative Binomial Observation Model

Description

Run the MCMC for Bayesian trend filtering with a penalty on first (D = 1) or second (D = 2) differences of the log conditional expectation of a Negative Binomial distribution. The penalty is determined by the prior on the evolution errors, currently only the following options are available:

  • the dynamic horseshoe prior ('DHS');

  • the static horseshoe prior ('HS');

In each case, the evolution error is a scale mixture of Gaussians. Sampling is accomplished with a (parameter-expanded) Gibbs sampler, mostly relying on a dynamic linear model representation.

Usage

btf_nb(
  y,
  evol_error = "DHS",
  D = 2,
  nsave = 1000,
  nburn = 1000,
  nskip = 4,
  mcmc_params = list("mu", "yhat", "evol_sigma_t2", "r", "dhs_phi", "dhs_mean"),
  r_init = NULL,
  r_sample = TRUE,
  step = 1,
  evol0_sample = FALSE,
  evol0_sd = 10,
  sigma_e = 1/sqrt(Nt),
  chol0 = NULL,
  computeDIC = TRUE,
  offset = 0,
  verbose = TRUE,
  seed = NULL
)

Value

A named list with the following. One named element for each of the parameters specified in mcmc_params containing the nsave posterior draws as a vector for scalar parameters and matrix for multivariate parameters. An element named loglike containing a vector of the nsave evaluations of the log likelihood of the data y with a Negative Binomial distribution defined by the current iteration conditional expectation + offset and overdispersion. If computeDIC is TRUE, a named element for the computed value of DIC and effective parameters p_d for the data y

with a Negative Binomial distribution defined by the posterior mean of the conditional expectation + offset and posterior mean overdispersion.

Arguments

y

the length T vector of time series observations; expected to be in the support of a Negative Binomial distribution

evol_error

the evolution error distribution; must be one of 'DHS' (dynamic horseshoe prior; the default), 'HS' (horseshoe prior), 'BL' (Bayesian lasso), or 'NIG' (normal-inverse-gamma prior)

D

degree of differencing (D = 0, D = 1, or D = 2)

nsave

number of MCMC iterations to record

nburn

number of MCMC iterations to discard (burnin)

nskip

number of MCMC iterations to skip between saving iterations, i.e., save every (nskip + 1)th draw

mcmc_params

character list of parameters for which we store the MCMC output; must be one or more of:

  • 'mu' (conditional mean)

  • 'yhat' (posterior predictive distribution)

  • 'evol_sigma_t2' (evolution error variance)

  • 'r' (overdispersion)

  • 'dhs_phi' (DHS AR(1) coefficient)

  • 'dhs_mean' (DHS AR(1) unconditional mean)

Defaults to everything.

r_init

numeric; initial value (defaults to 5) of MCMC sampling for overdispersion parameter; must be an integer if r_sample is 'int_mh' or NULL (initializes to default of 5)

r_sample

logical; If TRUE (default), the overdispersion is sampled, else it is fixed at r_init;

step

numeric (defaults to 1); step length of proposal distribution for Metropolis-Hasting sampling of overdispersion parameter; ignored if r_sample is FALSE

evol0_sample

logical; if TRUE (default), the prior variance of the initial D values of mu is sampled, else it is fixed at evol0_sd

evol0_sd

numeric; initial value (defaults to 10) or the fixed prior standard deviation for the initial D values of mu

sigma_e

numeric; scale value (defaults to 1/sqrt(T)) for half-Cauchy prior on global variance parameter

chol0

logical; If anything except NULL (the default), the Cholesky term of the log volatility is precomputed

computeDIC

logical; if TRUE, compute the deviance information criterion DIC and the effective number of parameters p_d

offset

length T vector of offset values for the log conditional expectation

verbose

logical; If TRUE (the default), time remaining is printed to console

seed

optional seed for random number generation for reproducible results