Learn R Programming

dsp (version 1.2.0)

predict.dsp: Predict changepoints from the output of ABCO

Description

Predict changepoints from the output of ABCO

Usage

# S3 method for dsp
predict(object, cp_thres = 0.5, cp_prop = FALSE, ...)

Value

If cp_prop = FALSE, a numeric vector of indices that correspond to indices of the observed data. If cp_prop = TRUE, a list containing:

- 'cp_t':  a numeric vector of indices that correspond to indices of the observed data.
- 'cp_prop': a numeric vector of length (T - D) with the pointwise proportion of samples where the increment exceeds the threshold.

If no proportions exceed cp_thres, then the vector will be a length 0 integer vector.

Arguments

object

object of class dsp from dsp_fit()

cp_thres

(default 0.5) cutoff proportion for percentage of posterior samples exceeding the threshold needed to label a changepoint

cp_prop

(default FALSE) logical flag determining if the posterior proportions of threshold exceedance is to be returned.

...

currently unused

Details

The changepoint model uses a thresholding mechanism with a latent indicator variable. This function calculates the proportion of samples where the increment exceeds the threshold.

Examples

Run this code
set.seed(200)
signal = c(rep(0, 50), rep(10, 50))
noise = rep(1, 100)
noise_var = rep(1, 100)
for (k in 2:100){
  noise_var[k] = exp(0.9*log(noise_var[k-1]) + rnorm(1, 0, 0.5))
  noise[k] = rnorm(1, 0, sqrt(noise_var[k])) }

y = signal + noise
model_spec = dsp_spec(family = "gaussian", model = "changepoint",
                      D = 1, useAnom = TRUE)
mcmc_output = dsp_fit(y, model_spec = model_spec, nsave = 500, nburn = 500)
predict(mcmc_output)

Run the code above in your browser using DataLab