R/Misc.R

Defines functions create.data

Documented in create.data

#' Create Time Delay Embedding
#'
#' Time series forecasting models usually assume the existence of a degree of correlation between successive values of the series. A form of modelling such correlation is to use previous values of the series as predictors of future value(s), in a procedure known as time delay embedding. This process allows the us of standard regression tools on time series forecasting tasks.
#'
#' @param ts the data structure with the time series data
#' @param embed the size of the embed, defaults to 10
#'
#' @return a data frame with the time delay embedding of the time series
#' @export
#'
create.data <- function(ts, embed = 10){

  t <- zoo::index(ts)[-(1:(embed-1))]
  e <- embed(ts,embed)[, embed:1]
  colnames(e) <- paste('V', 1:embed, sep='')
  d <- xts(e, t)
  as.data.frame(d)

}
nunompmoniz/rewind documentation built on July 8, 2021, 12:25 a.m.