Learn R Programming

sanba (version 0.0.3)

number_clusters: Estimate the Number of Observational and Distributional Clusters

Description

Computes the estimated number of observational clusters (OC) and distributional clusters (DC) from a fitted SAN model object.

For variational inference (SANvi objects), the function returns point estimates based on posterior mode assignments. For MCMC-based inference (SANmcmc objects), it returns the mean, median, and variance of the number of clusters across posterior samples.

Usage

number_clusters(object, ...)

Value

A data frame reporting the estimated number of observational (OC) and distributional (DC) clusters.

  • For SANvi: a single-row data frame with the point estimates.

  • For SANmcmc: a three-row data frame with the mean, median, and variance across MCMC samples.

Arguments

object

An object of class SANvi or SANmcmc, typically, the output of a call to fit_fiSAN, fit_fSAN, or fit_CAM.

...

ignored.

Examples

Run this code
# Generate example data
set.seed(123)
y <- c(rnorm(60), rnorm(40, 5))
g <- rep(1:2, each = 50)

plot(density(y[g == 1]), xlim = c(-5, 10), main = "Group-specific density")
lines(density(y[g == 2]), col = 2)

# Fit fiSAN via MCMC
est_mcmc <- fit_fiSAN(y, g, est_method = "MCMC")
number_clusters(est_mcmc)

# Fit fiSAN via Variational Inference
est_vi <- fit_fiSAN(y, g, est_method = "VI")
number_clusters(est_vi)

Run the code above in your browser using DataLab