Skip to contents

Performs k-means clustering on subject-level features to obtain initial cluster assignments for mixture model fitting.

Usage

assign_by_kmeans(features, K)

Arguments

features

An (N x d) matrix of subject-level features, where N is the number of subjects and d is the feature dimension.

K

Number of clusters to create.

Value

An integer vector of length N containing cluster labels (1..K). Each element indicates which cluster the corresponding subject is assigned to.

Details

This function uses the standard k-means algorithm with 10 random starts (nstart=10) to find a stable clustering solution. The resulting cluster assignments can be used as initial values for EM algorithms in mixture models.

Examples

if (FALSE) { # \dontrun{
# Create example features
features <- matrix(rnorm(100), nrow = 10, ncol = 10)

# Assign to 3 clusters
z_init <- assign_by_kmeans(features, K = 3)
table(z_init)  # Check cluster sizes
} # }