Learn R Programming

dsp

Dynamic Shrinkage Processes

This package provides a full, efficient MCMC sampling algorithm for dynamic shrinkage processes (DSPs). DSPs extend popular global-local shrinkage priors, such as the horseshoe prior for sparse signals, to the time series setting by allowing the shrinkage behavior to depend on the history of the shrinkage process. The resulting processes are locally adaptive, which is important for time series data and regression functions with irregular features.

The package provides the component samplers for the Gibbs sampler for DSPs, as well as a full MCMC implementation for Bayesian trend filtering (BTF) with dynamic horseshoe processes as the prior (penalty). BTF estimates are used for curve-fitting of univariate data, typically with irregular features. The BTF model is implemented using a dynamic linear model (DLM) framework, which provides efficient computations and a platform for useful extensions. BTF penalizes differences (first or second, in this case) of the conditional expectation (i.e., the signal) to produce approximately locally constant or locally linear estimates. We use DSPs as the prior on the 1st/2nd differences, which produces curve estimates and credible bands that are highly adaptive to both rapidly- and slowly-changing features. We also provide BTF model implementations for the (static) horseshoe (HS) prior and a normal- inverse-Gamma (NIG) prior. In all cases, computations are linear in the number of time points, so the MCMC samplers are highly efficient.

Besides curve-fitting via BTF, we include full, efficient MCMC sampling algorithms for dynamic shrinkage processes applied to (1) dynamic regression with time-varying coefficients and (2) B-spline models for curve-fitting. In the dynamic regression model, we regress a dynamic (scalar) response on a vector of dynamic predictors for which the corresponding regression coefficients are time-varying. The 1st/2nd differences of the regression coefficients are penalized using DSPs (with options for HS and NIG priors), allowing for highly adaptive regression functions. In the B-spline setting, we penalize 1st/2nd differences of the B-spline basis coefficients, similar to P-splines, using DSPs (with options for HS and NIG priors). The resulting curve-fitting model is highly adaptive, like the BTF model above, but easily incorporates unequally-spaced observation points.

Installation

install.packages("dsp")

Alternatively, install the development version

install.packages("devtools")
devtools::install_github("schafert/dsp")
library("dsp")

Copy Link

Version

Install

install.packages('dsp')

Version

1.2.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Toryn Schafer

Last Published

August 19th, 2025

Functions in dsp (1.2.0)

fit_ASV

MCMC Sampler for Adaptive Stchoastic Volatility (ASV) model
dsp_fit

MCMC Sampler for Models with Dynamic Shrinkage Processes
dsp-package

dsp: Dynamic Shrinkage Process and Change Point Detection
fit_paramsASV_n

Helper function for Sampling parameters for ASV model with a nugget Effect
fit_paramsASV

Helper function for Sampling parameters for ASV model
credBands

Compute Simultaneous Credible Bands
computeDIC_ASV

Function for calculating DIC and Pb (Bayesian measures of model complexity and fit by Spiegelhalter et al. 2002)
generate_ly2hat

Posterior predictive sampler on the transformed y (log(y^2))
ergMean

Compute the ergodic (running) mean.
dsp_spec

Model Specification
getNonZeros

Compute Non-Zeros (Signals)
getARpXmat

Compute the design matrix X for AR(p) model
initChol_spam

Compute initial Cholesky decomposition for Bayesian Trend Filtering
initEvol0

Initialize the parameters for the initial state variance
initEvolParams

Initialize the evolution error variance parameters
logit

Compute the log-odds
initSV

Initialize the stochastic volatility parameters
init_paramsASV_n

Helper function for initializing parameters for ASV model with a nugget effect
init_paramsASV

Helper function for initializing parameters for ASV model
initCholReg_spam

Compute initial Cholesky decomposition for TVP Regression
sampleAR1

Sample the AR(1) coefficient(s)
plot.dsp

Plot the Bayesian trend filtering fitted values
sampleBTF

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

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

Initialize the evolution error variance parameters
sampleBTF_reg

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

Sampler for the stochastic volatility parameters
sampleLogVols

Sample the latent log-volatilities
ncind

Sample components from a discrete mixture of normals
sampleFastGaussian

Sample a Gaussian vector using the fast sampler of BHATTACHARYA et al.
sampleEvolParams

Sampler evolution error variance parameters
predict.dsp

Predict changepoints from the output of ABCO
simRegression

Simulate noisy observations from a dynamic regression model
sampleLogVolMu

Sample the AR(1) unconditional means
simBaS

Compute Simultaneous Band Scores (SimBaS)
sampleLogVolMu0

Sample the mean of AR(1) unconditional means
sample_mat_c

Wrapper function for C++ call for sample mat, check pre-conditions to prevent crash
sampleDSP

Sample the dynamic shrinkage process parameters
t_create_loc

Initializer for location indices for filling in band-sparse matrix
getEffSize

Summarize of effective sample size
summary.dsp

Summarize DSP MCMC chains
t_sampleAR1

Sample the TAR(1) coefficients
sampleBTF_sparse

Sampler for first or second order random walk (RW) Gaussian dynamic linear model (DLM) with additional shrinkage to zero
sampleBTF_reg_backfit

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

Compute the inverse log-odds
spec_dsp

Compute the spectrum of an AR(p) model
simUnivariate

Generate univariate signals of different type
sampleEvol0

Sample the parameters for the initial state variance
t_initSV

Initialize the stochastic volatility parameters
simRegression0

Simulate noisy observations from a dynamic regression model
t_sampleR_mh

Sample the threshold parameter
t_sampleLogVols

Sample the latent log-volatilities
t_sampleEvolZeta_ps

Sampler for the anomaly component parameters
t_sampleLogVolMu

Sample the TAR(1) unconditional means
t_initEvolParams_no

Initialize the evolution error variance parameters
t_sampleBTF

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

Sample the thresholded dynamic shrinkage process parameters
uni.slice

Univariate Slice Sampler from Neal (2008)
t_sampleSVparams

Sampler for the stochastic volatility parameters
sample_j_wrap

Sampling from 10-component Gaussian Mixture component described in Omori et al. 2007
sampleSVparams0

Sampler for the stochastic volatility parameters using same functions as DHS prior
t_initEvolZeta_ps

Initialize the anomaly component parameters
build_Q

Compute the quadratic term in Bayesian trend filtering
btf_reg

MCMC Sampler for Bayesian Trend Filtering: Regression
abco

Adaptive Bayesian Changepoint with Outliers
btf_sparse

Run the MCMC for sparse Bayesian trend filtering
btf

MCMC Sampler for Bayesian Trend Filtering
build_XtX

Compute X'X
btf0

MCMC Sampler for Bayesian Trend Filtering: D = 0
btf_bspline0

MCMC Sampler for B-spline Bayesian Trend Filtering: D = 0
btf_nb

MCMC Sampler for Bayesian Trend Filtering with Negative Binomial Observation Model
btf_bspline

MCMC Sampler for B-spline Bayesian Trend Filtering