knn.forecast {knnwtsim}R Documentation

KNN Forecast

Description

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.

Usage

knn.forecast(Sim.Mat.in, f.index.in, k.in, y.in)

Arguments

Sim.Mat.in

numeric and symmetric matrix of similarities (recommend use of S_w, see SwMatrixCalc()).

f.index.in

numeric vector indicating the indices of Sim.Mat.in and y.in which correspond to the time order of the points to be forecast.

k.in

integer value indicating the the number of nearest neighbors to be considered in forecasting, must be >= 1.

y.in

numeric vector of the response series to be forecast.

Value

numeric vector of the same length as f.index.in, of forecasted observations.

See Also

Examples

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)

[Package knnwtsim version 1.0.0 Index]