BestC: Find Optimal Number of Clusters for Longitudinal Data

View source: R/BestC.R

BestCR Documentation

Find Optimal Number of Clusters for Longitudinal Data

Description

This function determines the best number of clusters (C) for longitudinal data clustering based on internal validation indices using the latrend package.

Usage

BestC(Y, range_clusters = 2:6, method = "kml")

Arguments

Y

A matrix or data frame of longitudinal outcomes (subjects x timepoints).

range_clusters

A numeric vector of cluster numbers to evaluate (e.g., 2:6).

method

Clustering method to use. Currently supports "kml" (default).

Value

A list with:

best_c

Optimal number of clusters

criteria

Data frame of criteria values for each cluster number

criteria_best

Criteria values for the best cluster number

Examples


set.seed(123)
n <- 30
T <- 3
y <- matrix(rnorm(n * T), nrow = n)
best_c_info <- BestC(Y = y, range_clusters = 2:4)
print(best_c_info$best_c)



CKNNRLD documentation built on May 29, 2026, 1:06 a.m.

Related to BestC in CKNNRLD...