sampleMultNormMixture: Telescoping sampling of a Bayesian finite multivariate...

View source: R/sampleMultNormMixture.R

sampleMultNormMixtureR Documentation

Telescoping sampling of a Bayesian finite multivariate Gaussian mixture where a prior on the number of components is specified.

Description

  • The MCMC scheme is implemented as suggested in Frühwirth-Schnatter et al (2021).

  • The priors on the model parameters are specified as in Frühwirth-Schnatter et al (2021), see the vignette for details and notation.

  • The parameterizations of the Wishart and inverse Wishart distribution are used as in Frühwirth-Schnatter et al (2021), see also the vignette.

Usage

sampleMultNormMixture(
  y,
  S,
  mu,
  Sigma,
  eta,
  c0,
  g0,
  G0,
  C0,
  b0,
  B0,
  M,
  burnin,
  thin,
  Kmax,
  G = c("MixDynamic", "MixStatic"),
  priorOnK,
  priorOnWeights,
  verbose = FALSE
)

Arguments

y

A numeric matrix; containing the data.

S

A numeric matrix; containing the initial cluster assignments.

mu

A numeric matrix; containing the initial cluster-specific mean values.

Sigma

A numeric matrix; containing the initial cluster-specific variance covariance values.

eta

A numeric vector; containing the initial cluster sizes.

c0

A numeric vector; hyperparameter of the prior on \Sigma_k.

g0

A numeric vector; hyperparameter of the prior on C_0.

G0

A numeric vector; hyperparameter of the prior on C_0.

C0

A numeric vector; initial value of the hyperparameter C_0.

b0

A numeric vector; hyperparameter of the prior on \mu_k.

B0

A numeric vector; hyperparameter of the prior on \mu_k.

M

A numeric scalar; specifying the number of recorded iterations.

burnin

A numeric scalar; specifying the number of burn-in iterations.

thin

A numeric scalar; specifying the thinning used for the iterations.

Kmax

A numeric scalar; the maximum number of components.

G

A character string; either "MixDynamic" or "MixStatic".

priorOnK

A named list; providing the prior on the number of components K, see priorOnK_spec().

priorOnWeights

A named list; providing the prior on the mixture weights.

verbose

A logical; indicating if some intermediate clustering results should be printed.

Value

A named list containing:

  • "Mu": sampled component means.

  • "Eta": sampled weights.

  • "S": sampled assignments.

  • "Nk": number of observations assigned to the different components, for each iteration.

  • "K": sampled number of components.

  • "Kplus": number of filled, i.e., non-empty components, for each iteration.

  • "e0": sampled Dirichlet parameter of the prior on the weights (if e_0 is random).

  • "alpha": sampled Dirichlet parameter of the prior on the weights (if \alpha is random).

  • "acc": logical vector indicating acceptance in the Metropolis-Hastings step when sampling either e_0 or \alpha.

Examples

y <- iris[, 1:4]
z <- iris$Species
r <- ncol(y)

M <- 50
thin <- 1
burnin <- 0
Kmax <- 40  
Kinit <- 10

G <- "MixStatic"      
priorOnE0 <- priorOnE0_spec("G_1_20", 1)
priorOnK <- priorOnK_spec("BNB_143")

R <- apply(y, 2, function(x) diff(range(x)))
b0 <- apply(y, 2, median)
B_0 <- rep(1, r)  
B0 <- diag((R^2) * B_0)
c0 <- 2.5 + (r-1)/2
g0 <- 0.5 + (r-1)/2
G0 <- 100 * g0/c0 * diag((1/R^2), nrow = r)
C0 <- g0 * chol2inv(chol(G0))

cl_y <- kmeans(y, centers = Kinit, nstart = 100)
S_0 <- cl_y$cluster
mu_0 <- t(cl_y$centers)

eta_0 <- rep(1/Kinit, Kinit)
Sigma_0 <- array(0, dim = c(r, r, Kinit))
Sigma_0[, , 1:Kinit] <- 0.5 * C0

result <- sampleMultNormMixture(
  y, S_0, mu_0, Sigma_0, eta_0,
  c0, g0, G0, C0, b0, B0,  
  M, burnin, thin, Kmax, G, priorOnK, priorOnE0)

K <- result$K
Kplus <- result$Kplus   

plot(K, type = "l", ylim = c(0, max(K)),
     xlab = "iteration", main = "",
     ylab = expression("K" ~ "/" ~ K["+"]), col = 1)
lines(Kplus, col = 2)
legend("topright", legend = c("K", expression(K["+"])),
       col = 1:2, lty = 1, box.lwd = 0)


telescope documentation built on April 4, 2025, 2:40 a.m.