% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/CKNNRLD.R
\name{CKNNRLD}
\alias{CKNNRLD}
\title{Cluster-based KNN Regression for Longitudinal Data (CKNNRLD)}
\usage{
CKNNRLD(xnew, y, x, k = 5, c = 4, cluster_method = "kml")
}
\arguments{
\item{xnew}{A matrix of predictor values for test data (new observations).}

\item{y}{A matrix or data frame of longitudinal responses (subjects x timepoints).}

\item{x}{A matrix or data frame of predictors for training data.}

\item{k}{Number of nearest neighbors to use. Can be a scalar (same k for all clusters)
or a vector (different k per cluster).}

\item{c}{Number of clusters for longitudinal clustering.}

\item{cluster_method}{Clustering method to use. Currently supports "kml" (default).}
}
\value{
A data frame with predicted values and cluster assignment for each observation in \code{xnew}.
Columns: cluster, Y1, Y2, ..., Yd (where d = number of timepoints).
}
\description{
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.
}
\examples{
\donttest{
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)
}

}
