create_timefolds {splitTools} | R Documentation |
Creates Folds for Time Series Data
Description
This function provides a list with in- and out-of-sample indices per fold used for time series k-fold cross-validation, see Details.
Usage
create_timefolds(y, k = 5L, use_names = TRUE, type = c("extending", "moving"))
Arguments
y |
Any vector of the same length as the data intended to split. |
k |
Number of folds. |
use_names |
Should folds be named? Default is |
type |
Should in-sample data be "extending" over the folds (default) or consist of one single fold ("moving")? |
Details
The data is first partitioned into sequential blocks
to
. Each fold consists of two index vectors: one with in-sample row numbers,
the other with out-of-sample row numbers. The first fold uses
as in-sample
and
as out-of-sample data. The second one uses either
(if
type = "moving"
) or (if
type = "extending"
)
as in-sample, and as out-of-sample data etc. Finally, the kth fold uses
("extending") or
("moving") as in-sample data,
and
as out-of-sample data. This makes sure that out-of-sample data
always follows in-sample data.
Value
A nested list with in-sample and out-of-sample indices per fold.
See Also
Examples
y <- runif(100)
create_timefolds(y)
create_timefolds(y, use_names = FALSE)
create_timefolds(y, use_names = FALSE, type = "moving")