gibbs_alg: Gibbs sampler algorithm for simulated scenarios or real...

View source: R/gibbs_alg.R

gibbs_algR Documentation

Gibbs sampler algorithm for simulated scenarios or real datasets

Description

Gibbs sampler algorithm for simulated scenarios or real datasets

Usage

gibbs_alg(
  N,
  w,
  M,
  K,
  Tl,
  cluster,
  alpha,
  sigma2,
  bs = 1000,
  as = 2,
  al = 2,
  bl = 1000,
  a = 2,
  b = 1000,
  alpha0 = 1/100,
  kstar,
  lambda,
  Y,
  d,
  maxIter = 10000
)

Arguments

N

A scalar representing the number of observations

w

A scalar representing the minimum number of points in each interval between two change points

M

A scalar representing the number of points available for each observation

K

A vector containing the number of change points for each cluster (or its initial values)

Tl

A list containing a vector for each cluster determining the change-point positions in each cluster (or its initial values)

cluster

A vector containing the cluster assignments for the observations (or its initial values)

alpha

A list containing a vector for each cluster determining the constant level values for each interval between change points in each cluster (or its initial values)

sigma2

A vector with the variances of observations (or its initial values)

bs

The hyperparameter value for the scale parameter in the inverse-gamma prior for the variance component

as

The hyperparameter value for the shape parameter in the inverse-gamma prior for the variance component

al

The hyperparameter value for the shape parameter in the gamma prior for lambda

bl

The hyperparameter value for the scale parameter in the gamma prior for lambda

a

The hyperparameter value for the shape parameter in the gamma prior for alpha0

b

The hyperparameter value for the scale parameter in the gamma prior for alpha0

alpha0

A scalar defining the parameter for the Dirichlet process prior that controls the number of clusters (or its initial values)

kstar

A scalar with the number maximum of change points in all clusters

lambda

A scalar defining the parameter for the Truncate Poisson distribution that controls the number of change points (or its initial values)

Y

A matrix M x N with the data sequences

d

A scalar representing the number of clusters.

maxIter

A scalar for the number of iteration to run in the Gibbs sampler

Value

A list with each component representing the estimates for each iteration of the Gibbs sampler for each parameter

See Also

[run_gibbs()]

Examples


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 <- gibbs_alg(alpha0 = 1/100, N = 5, w = 10, M = 50, K = par.values$K,
Tl = par.values$Tl, cluster = cluster, alpha = par.values$alpha, sigma2 = sigma2,
bs = 1000, as = 2, al = 2, bl = 1000, a = 2, b = 1000, kstar = 2, lambda = 2,
Y = data, d = 2, maxIter = 10)


BayesCPclust documentation built on April 4, 2025, 5:19 a.m.