| KNNRLD | R Documentation |
This function performs KNN regression for longitudinal data without clustering. It predicts longitudinal outcomes for new observations based on the weighted average of their k nearest neighbors in the predictor space.
KNNRLD(xnew, y, x, k = 5)
xnew |
A matrix of predictor values for prediction (test set). |
y |
A matrix or data frame of longitudinal responses (training set). |
x |
A matrix or data frame of training predictor values. |
k |
Number of nearest neighbors to use. Can be a scalar or a vector. |
A list of matrices with predicted values for each value of k. Each matrix has dimensions nrow(xnew) x ncol(y).
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)
pred <- KNNRLD(
xnew = x[test_idx, ],
y = y[train_idx, ],
x = x[train_idx, ],
k = 3
)
head(pred[[1]])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.