Learn R Programming

BayesCPclust

BayesCPclust aims to estimate the change points in constant-wise data sequences while simultaneously performing clustering. A Gibbs sampler algorithm was developed to estimate the number of clusters, cluster assignments, number of change points, their positions, and constant levels.

For more details see paper in arXiv paper link

Installation

You can install the development version of BayesCPclust from GitHub with:

# install.packages("devtools")
devtools::install_github("acarolcruz/BayesCPclust")

Example

The following example illustrate the process of performing clustering and estimations for constant-wise change-point data using the data example ‘data’. When there is no prior knowledge of the number of change points and their locations, we suggest to initialize the algortihm with zero change points for all clusters and the position for the change points (Tl) should be defined as the number of observations (M).

d = 2 # two clusters
N = 5 # 5 data sequences
M = 50 # 50 observations for each data sequence
maxIter = 10 # number of Gibbs sampler iterations

data(data)

# initial values for each paramter and each cluster
par.values <- list(K = c(0, 0), Tl = list(50, 50), alpha = list(5, 10))

#cluster assignment for each data sequence
cluster <- kmeans(t(data), 2)$cluster

# variance for each data sequence
sigma2 <- apply(data, 2, var)

res <- run_gibbs(M, N, w = 10, d, as = 2, bs = 100, al = 2, bl = 1000, a = 2, 
b = 1000, alpha0 = 1/100, lambda = 2, maxIter = 10, par.values,
data, cluster, sigma2)

res$clusters[maxIter,]
# 3 7 7 7 7

Copy Link

Version

Install

install.packages('BayesCPclust')

Monthly Downloads

312

Version

0.1.0

License

MIT + file LICENSE

Maintainer

Ana Carolina da Cruz

Last Published

January 29th, 2025

Functions in BayesCPclust (0.1.0)

update_lambda

Update equation for lambda
data_a

Error free data for all examples.
full_cond

Full conditional for lambda
gibbs_alg

Gibbs sampler algorithm for simulated scenarios or real datasets
Mode

Compute the mode of a numerical vector
logsumexp

Transfor a vector with over- or underflow
postK

Marginal probability of K
pk

Probability mass function for truncated poisson
possigma2n

Full conditional function for sigma2
postK_mk

Marginal probability of K per bin
qn0_mk

Mixing probability for creating new cluster per bin
data

Error free data for all examples.
qnj

Mixing probability for getting assigned to an existing cluster
postalpha0

Posterior for alpha0
run_gibbs

Runs the Gibbs sampler algorithm using using initial values for the parameters
postmk

Marginal probability of m1,m2,m3,...,mk+1
qn0

Mixing probability for creating new cluster
postalphak

Full conditional for alphak