NNreg | R Documentation |
Finds the index of the nearest neighbors for a single point given that point's
vector of similarities to all observations eligible to be considered as neighbors. The k.in2
neighbors are identified by their index in the similarity vector, and this index is used to
identify the neighbor points in y.in2
. The function then returns the mean of the values
in y.in2
identified as neighbors. It is suggested to call this function through knn.forecast()
for all points to be forecasted simultaneously.
NNreg(v, k.in2, y.in2)
v |
numeric vector of similarities used to identify nearest neighbors. |
k.in2 |
integer value indicating the the number of nearest neighbors to be considered. |
y.in2 |
numeric vector of the response series to be forecast. |
numeric value of the mean of the k.in2
nearest neighbors in y.in2
.
knn.forecast()
the recommended user facing function to perform knn
regression for forecasting with NNreg()
.
Sim.Mat <- matrix(c(1, .5, .2, .5, 1, .7, .2, .7, 1), nrow = 3, ncol = 3, byrow = TRUE ) Sim.Mat.col <- Sim.Mat[-(3), 3] y <- c(2, 1, 5) k <- 2 NNreg(v = Sim.Mat.col, k.in2 = 2, y.in2 = y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.