knn.forecast | R Documentation |
Provide an n x n similarity matrix as input, all points both observed and those to be
forecasted should be included. The f.index.in
argument indicates which observations
to identify neighbors for, and removes them from consideration as eligible neighbors.
Once the matrix is subset down to only the columns in f.index.in
and the rows excluding f.index.in
, the
NNreg()
function is applied over the columns, returning for each column the mean of those points in y.in
identified as neighbors
based on the row index of the k.in
most similar observations in the column. It is important that the index of the similarity matrix
and y.in
accurately reflect the time order of the observations.
knn.forecast(Sim.Mat.in, f.index.in, k.in, y.in)
Sim.Mat.in |
numeric and symmetric matrix of similarities (recommend use of |
f.index.in |
numeric vector indicating the indices of |
k.in |
integer value indicating the the number of nearest neighbors to be considered in forecasting, must be |
y.in |
numeric vector of the response series to be forecast. |
numeric vector of the same length as f.index.in
, of forecasted observations.
NNreg()
for the function used to perform knn regression on a single
point.
SwMatrixCalc()
for the function to calculate a matrix with the recommended similarity measure.
Sim.Mat <- matrix(c(1, .5, .2, .5, 1, .7, .2, .7, 1), nrow = 3, ncol = 3, byrow = TRUE ) y <- c(2, 1, 5) f.index <- c(3) k <- 2 knn.forecast(Sim.Mat.in = Sim.Mat, f.index.in = f.index, y.in = y, k.in = k)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.