sampleBTF: Sampler for first or second order random walk (RW) Gaussian...

View source: R/component_samplers.R

sampleBTFR Documentation

Sampler for first or second order random walk (RW) Gaussian dynamic linear model (DLM)

Description

Compute one draw of the T x 1 state variable mu in a DLM using back-band substitution methods. This model is equivalent to the Bayesian trend filtering (BTF) model, assuming appropriate (shrinkage/sparsity) priors for the evolution errors.

Usage

sampleBTF(y, obs_sigma_t2, evol_sigma_t2, D = 1, chol0 = NULL)

Arguments

y

the T x 1 vector of time series observations

obs_sigma_t2

the T x 1 vector of observation error variances

evol_sigma_t2

the T x 1 vector of evolution error variances

D

the degree of differencing (one or two)

chol0

(optional) the m x m matrix of initial Cholesky factorization; if NULL, use the Matrix package for sampling, otherwise use the spam package

Value

T x 1 vector of simulated states

Note

Missing entries (NAs) are not permitted in y. Imputation schemes are available.

Examples

# Simulate some data:
T = 1000
y = seq(0, 10, length.out = T) + rnorm(T)
plot(y) # plot the data

obs_sigma_t2 = rep(1, T)  # These could be static or dynamic
evol_sigma_t2 = rep(0.001, T)

# Simulate one draw of the states:
mu = sampleBTF(y = y, obs_sigma_t2, evol_sigma_t2, D = 1)
lines(mu, lwd=8, col='blue') # add the states to the plot


drkowal/dsp documentation built on July 19, 2023, 11:42 a.m.