Learn R Programming

BayesChange provides C++ functions to perform Bayesian change points analysis.

Installation

To install BayesChange the package devtools is needed.

install.packages("devtools")

Now BayesChange can be installed through the GitHub repository of the package:

devtools::install_github("lucadanese/BayesChange")

Package contents

The package contains two main functions:

  • detect_cp change points detection on time series and epidemic diffusions.
  • clust_cp clustering of time series or epidemic diffusions with common change points.

Additional methods and functions are included:

  • print() and summary() return information about the algorithm.
  • posterior_estimate() estimates the change points or the final partition of the data.
  • plot() provides a graphical representation of the results.
  • plot_psm() provides the posterior similarity matrix for the output of clust_cp.
  • sim_epi_data() generates an arbitrary number of simulated survival functions.

Detect change points

library(BayesChange)

## Univariate time series

data("stock_uni")

params_uni <- list(a = 1,
                   b = 1,
                   c = 1,
                   phi = 0.1)

out <- clust_cp(data = stock_uni[1:5,], n_iterations = 7500, n_burnin = 2500,
                L = 1, q = 0.5, B = 10000, params = params_uni, kernel = "ts")

print(out)
summary(out)
posterior_estimate(out)
plot(out)


## Multivariate time series

data("stock_multi")

params_multi <- list(m_0 = rep(0,2),
                     k_0 = 1,
                     nu_0 = 10,
                     S_0 = diag(1,2,2),
                     phi = 0.1)

out <- clust_cp(data = stock_multi[,,1:5], n_iterations = 7500, n_burnin = 2500,
                L = 1, B = 10000, params = params_multi, kernel = "ts")

print(out)
summary(out)
posterior_estimate(out)
plot(out)

## Epidemic diffusions

data("epi_synthetic_multi")

params_epi <- list(M = 250, xi = 1/8,
                   alpha_SM = 1,
                   a0 = 4,
                   b0 = 10,
                   I0_var = 0.1,
                   avg_blk = 2)

out <- clust_cp(epi_synthetic_multi, n_iterations = 5000, n_burnin = 2000,
                L = 1, B = 1000, params = params_epi, kernel = "epi")

print(out)
summary(out)
posterior_estimate(out)
plot(out)

Cluster time dependent data with common change points


## Univariate time series

data("stock_uni")

params_uni <- list(a = 1,
                   b = 1,
                   c = 1,
                   phi = 0.1)

out <- clust_cp(data = stock_uni[1:5,], n_iterations = 7500, n_burnin = 2500,
                L = 1, q = 0.5, B = 10000, params = params_uni, kernel = "ts")

print(out)
summary(out)
posterior_estimate(out)
plot(out)

## Multivariate time series

data("stock_multi")

params_multi <- list(m_0 = rep(0,2),
                     k_0 = 1,
                     nu_0 = 10,
                     S_0 = diag(1,2,2),
                     phi = 0.1)

out <- clust_cp(data = stock_multi[,,1:5], n_iterations = 7500, n_burnin = 2500,
                L = 1, B = 10000, params = params_multi, kernel = "ts")

print(out)
summary(out)
posterior_estimate(out)
plot(out)


## Epidemic diffusions

data("epi_synthetic_multi")

params_epi <- list(M = 250, xi = 1/8,
                   alpha_SM = 1,
                   a0 = 4,
                   b0 = 10,
                   I0_var = 0.1,
                   avg_blk = 2)

out <- clust_cp(epi_synthetic_multi, n_iterations = 5000, n_burnin = 2000,
                L = 1, B = 1000, params = params_epi, kernel = "epi")

print(out)
summary(out)
posterior_estimate(out)
plot(out)

Copy Link

Version

Install

install.packages('BayesChange')

Monthly Downloads

11,212

Version

2.3.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Luca Danese

Last Published

March 6th, 2026

Functions in BayesChange (2.3.0)

print.ClustCpObj

ClustCpObj print method
sim_epi_data

Simulate epidemiological data
plot.DetectCpObj

Plot estimated change points
summary.DetectCpObj

DetectCpObj summary method
print.DetectCpObj

DetectCpObj print method
summary.ClustCpObj

ClustCpObj summary method
stock_uni

Daily Stock Price Dataset (Univariate Mean Series)
stock_multi

Daily Stock Price Dataset (Multivariate Open/Close Series)
BayesChange-package

BayesChange: Bayesian Methods for Change Point Analysis
detect_cp_epi

Detect Change Points on a epidemic diffusion
DetectCpObj

DetectCpObj class constructor
ClustCpObj

ClustCpObj class constructor
clust_cp

Clustering time dependent observations with common change points.
detect_cp

Detect change points on time series.
posterior_estimate.ClustCpObj

Estimate the change points of the data
posterior_estimate.DetectCpObj

Estimate the change points of the data
plot_psm.ClustCpObj

Plot the Posterior Similarity Matrix (PSM) for a ClustCpObj
clust_cp_epi

Clustering Epidemiological epidemic_diffusions with common changes in time
clust_cp_uni

Clustering univariate times series with common changes in time
detect_cp_multi

Detect Change Points on multivariate time series
clust_cp_multi

Clustering multivariate times series with common changes in time
epi_synthetic_multi

Multivariate Synthetic Epidemiological Time-Series Data
epi_synthetic

Synthetic Epidemiological Time-Series Data
detect_cp_uni

Detect Change Points on an univariate time series.
posterior_estimate

set generic
plot.ClustCpObj

Plot estimated partition
eu_inflation

EU Inflation Dataset (Standardized Matrix Form)