| ts_windows | R Documentation |
Converts time series into a data frame suitable for training forecasting
models: each row holds the target y (the value horizon steps ahead) and
the lags preceding values lag1 (most recent) ... lagp. With a list of
series (e.g. from augment_data()), the windows of all series are stacked
and a series column identifies their origin; windows never cross series
boundaries.
ts_windows(x, lags, horizon = 1L, target = 1L)
x |
A |
lags |
Number of lags. |
horizon |
Forecast horizon (1 = one step ahead). |
target |
For multivariate series: name or index of the target column. |
For multivariate series, lags of every component are created
(<name>_lag1, ...) and the target is the column named by target.
A data frame with columns y, the lag columns and (for lists)
series.
w <- ts_windows(ldeaths, lags = 3)
head(w)
fit <- lm(y ~ ., data = w)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.