| CKNNRLD | R Documentation |
This function implements a clustering-based KNN regression method designed for longitudinal datasets. It first clusters the training data using longitudinal clustering (via latrend) and then performs KNN regression within each selected cluster.
CKNNRLD(xnew, y, x, k = 5, c = 4, cluster_method = "kml")
xnew |
A matrix of predictor values for test data (new observations). |
y |
A matrix or data frame of longitudinal responses (subjects x timepoints). |
x |
A matrix or data frame of predictors for training data. |
k |
Number of nearest neighbors to use. Can be a scalar (same k for all clusters) or a vector (different k per cluster). |
c |
Number of clusters for longitudinal clustering. |
cluster_method |
Clustering method to use. Currently supports "kml" (default). |
A data frame with predicted values and cluster assignment for each observation in xnew.
Columns: cluster, Y1, Y2, ..., Yd (where d = number of timepoints).
set.seed(123)
n <- 30
T <- 3
d <- 2
x <- matrix(runif(n * d), nrow = n)
y <- matrix(rnorm(n * T), nrow = n)
train_idx <- sample(1:n, 20)
test_idx <- setdiff(1:n, train_idx)
result <- CKNNRLD(
x = x[train_idx, ],
y = y[train_idx, ],
xnew = x[test_idx, ],
k = 3,
c = 2
)
head(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.