clustKL: Choose cluster number by KL method

Description Usage Arguments Value See Also Examples

View source: R/clustKL.R

Description

To find minimal cluster number which reduces Kullback-Leibler divergence no larger than a customized threshold. KL monotonically decreases with number of clusters.

Usage

1
clustKL(id_var, ls_par, dat, ls_idxA, nIter, thKL, regQ, seed)

Arguments

id_var

Character of id variable

ls_par

Posterior mean of LMM parameters generated from postMean output

dat

Longitudinal data input

ls_idxA

List of random effect indices to project on

nIter

Number of iterations used in clustering optimization

thKL

Proportion of max KL, used as upper threshold of Kullback-Leibler divergence corresponding to chosen number of clusters

regQ

Positive regularization value to add to the diagonal of matrix to be inverted

seed

Random seed to initialize cluster centers

Value

list(nClusters,KLs,cluster0)

nClusters

Vector of optimised cluster numbers corresponding to sets of random effects in ls_idxA

KLs

List of Kullback-Leibler divergence across grid of cluster numbers corresponding to ls_idxA

cluster0

List of matrix, column k indicates cluster membership for k clusters corresponding to ls_idxA

See Also

Other BayesPC main functions: modelStan(), pcFit(), postMean()

Other Cluster number choices: clustBoot()

Examples

1
2
3
4
5
6
7
8
9
data(df_of_draws)
ls_par <- postMean(df_of_draws, paste0("Z", 1:10), "ID", DATASET)
ls_idxA <- list(
  seq(10),
  1:4,
  5:7,
  8:10
)
out_KL <- clustKL("ID", ls_par, DATASET, ls_idxA, 10, .1, 1e-6, 1)

maoyinan/BayesPC documentation built on Dec. 21, 2021, 1:48 p.m.