CKNNRLD.tune: Tune CKNNRLD Model with Automatic Cluster Selection

View source: R/Tuning_CKNNRLD.R

CKNNRLD.tuneR Documentation

Tune CKNNRLD Model with Automatic Cluster Selection

Description

Automatically selects the best number of clusters (C) using internal validation criteria, then tunes the CKNNRLD model within each cluster via cross-validation.

Usage

CKNNRLD.tune(
  y,
  x,
  nfolds = 10,
  folds = NULL,
  seed = NULL,
  A = 10,
  C_range = 2:6,
  cluster_method = "kml"
)

Arguments

y

Matrix of longitudinal outcomes (subjects x timepoints).

x

Matrix of predictor variables (subjects x features).

nfolds

Number of folds for cross-validation (default = 10).

folds

Optional list of pre-specified fold indices.

seed

Random seed for reproducibility.

A

Maximum number of neighbors to evaluate (searches from 2 to A, default = 10).

C_range

Range of cluster numbers to evaluate (default = 2:6).

cluster_method

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

Value

A list containing:

best_c

Optimal number of clusters

cluster_results

Tuning results for each cluster (from KNNRLD.tune)

cluster_sizes

Size of each cluster

cluster_assignments

Cluster labels for each subject

criteria

Data frame of quality criteria used for selecting best C

Examples


set.seed(123)
n <- 30
T <- 3
d <- 2
x <- matrix(runif(n * d), nrow = n)
y <- matrix(rnorm(n * T), nrow = n)
tune_result <- CKNNRLD.tune(
  y = y,
  x = x,
  nfolds = 3,
  A = 4,
  C_range = 2:3
)
print(tune_result$best_c)



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