I want to make some time-series evaluation in R. The process is usually to define a time lag and the evaluation frequency/periods, and for each evaluation period, train a model with the defined time lag and compute metrics for that period.
For example, we have:
- Evaluation period size and interval
n
- Evaluation start at
b
- Time lag
l
We train a model with points 1:b-l
, evaluate it on b:b+n
. After that we train a model with points 1:b+n-l
and evaluate it on b+n:b+2n
and etc, for k
periods. It could vary a bit but that's the general spirit. So this is basically a sliding window for the evaluation data, but an increasing window for training data.
This is illustrated in the answer to this question (the expanding window solution).
How could I do this, preferably without loops and using the tidyverse and/or packages specific for time-series analysis?