Learn R Programming

BayesChange (version 2.3.0)

detect_cp: Detect change points on time series.

Description

The detect_cp function detect change points on univariate and multivariate time series.

Usage

detect_cp(
  data,
  n_iterations,
  n_burnin = 0,
  q = 0.5,
  params = list(),
  kernel,
  print_progress = TRUE,
  user_seed = 1234
)

Value

A DetectCpObj object containing:

  • $data Vector or matrix with the input data.

  • $n_iterations Total number of MCMC iterations.

  • $n_burnin Number of burn-in iterations removed from posterior summaries.

  • $orders Matrix of change–point allocations. Each row corresponds to an iteration; columns correspond to time indices.

  • $time Computational time (in seconds).

  • $entropy_MCMC A coda::mcmc object containing the MCMC samples of the entropy measure.

  • $lkl_MCMC A coda::mcmc object containing the MCMC samples of the log-likelihood.

  • $phi_MCMC A coda::mcmc object storing MCMC draws of \(\gamma\).

  • $sigma_MCMC A coda::mcmc object storing MCMC draws of \(\sigma\).

  • $delta_MCMC A coda::mcmc object storing MCMC draws of \(\delta\).

  • $I0_MCMC A coda::mcmc object storing MCMC draws of \(I_0\).

  • $kernel_ts Logical; TRUE if the data are time series.

  • $kernel_epi Logical; TRUE if the data follow an epidemic diffusion process.

  • $univariate_ts Logical; TRUE if the time series is univariate, FALSE for multivariate.

Arguments

data

if kernel = "ts" a vector or a matrix. If kernel = "epi" a matrix.

n_iterations

number of MCMC iterations.

n_burnin

number of iterations that must be excluded when computing the posterior estimate.

q

probability of performing a split at each iteration.

params

a list of parameters:

If data is an univariate time series the following must be specified:

  • a, b, c parameters of the Normal-Gamma prior for \(\mu\) and \(\lambda\).

  • prior_var_phi variance for the proposal in the \(N(0,\sigma^2_\phi)\) posterior estimate of \(\delta\).

  • prior_delta_c parameter of the shifted Gamma prior of \(\delta\).

  • prior_delta_d parameter of the shifted Gamma prior of \(\delta\).

If the time series is multivariate the following must be specified:

  • m_0, k_0, nu_0, S_0 parameters for the Normal-Inverse-Wishart prior for \((\mu,\lambda)\).

  • prior_var_phi variance for the proposal in the \(N(0,\sigma^2_\phi)\) posterior estimate of \(\delta\).

  • prior_delta_c parameter of the shifted Gamma prior of \(\delta\).

  • prior_delta_d parameter of the shifted Gamma prior of \(\delta\).

If data are epidemic diffusions:

  • M number of Monte Carlo iterations when computing the likelihood of the epidemic diffusion.

  • xi recovery rate fixed constant for each population at each time.

  • a0,b0 parameters for the computation of the integrated likelihood of the epidemic diffusions.

  • I0_var variance for the Metropolis-Hastings estimation of the proportion of infected at time 0.

kernel

can be "ts" if data are time series or "epi" if data are epidemic diffusions.

print_progress

If TRUE (default) print the progress bar.

user_seed

seed for random distribution generation.

References

Martínez, A. F., & Mena, R. H. (2014). On a Nonparametric Change Point Detection Model in Markovian Regimes. Bayesian Analysis, 9(4), 823–858. tools:::Rd_expr_doi("10.1214/14-BA878")

Corradin, R., Danese, L., & Ongaro, A. (2022). Bayesian nonparametric change point detection for multivariate time series with missing observations. International Journal of Approximate Reasoning, 143, 26--43. tools:::Rd_expr_doi("10.1016/j.ijar.2021.12.019")

Examples

Run this code

## Univariate time series

data("eu_inflation")

params_uni <- list(a = 1, b = 1, c = 1, prior_var_phi = 0.1,
                   prior_delta_c = 1, prior_delta_d = 1)

out <- detect_cp(data = eu_inflation[1,], n_iterations = 2000,
                 n_burnin = 250, q = 0.5, params = params_uni,
                 kernel = "ts")

print(out)

## Multivariate time series

data("eu_inflation")

params_multi <- list(m_0 = rep(0,3),
                     k_0 = 1,
                     nu_0 = 10,
                     S_0 = diag(0.1,3,3),
                     prior_var_phi = 0.1,
                     prior_delta_c = 1,
                     prior_delta_d = 1)

out <- detect_cp(data = eu_inflation[1:3,], n_iterations = 2000,
                 n_burnin = 250, q = 0.5, params = params_multi, kernel = "ts")

print(out)

# \donttest{
## Epidemic diffusions

data("epi_synthetic")

params_epi <- list(M = 100, xi = 1/8, a0 = 4, b0 = 10, I0_var = 0.1)

out <- detect_cp(data = epi_synthetic, n_iterations = 2000, n_burnin = 250,
                 q = 0.25, params = params_epi, kernel = "epi")

print(out)
# }

Run the code above in your browser using DataLab