Hello,
I am trying to use the nested modeltime package to forecast multiple series in a dataframe. Before running the forecasts I am trying to convert the data into a time series using the following code:
to_ts <- function(data, freq = 4L) {
dates <- data$quarter
value <- data
tk_ts(value, start = c(year(dates)[1], quarter(dates)[1]), frequency = freq) %>%
tk_tbl(timetk_idx = TRUE) %>%
rename(date = index)
}
nested_pfu_prob <- pfu_prob %>%
select(-c(group_id,group_id2,sector,sector_cpart)) %>%
group_by(instr_class,instr_code, cat,sector_label,sector_cpart_label,type) %>%
nest(data.tbl=-group_cols())
nested_pfu_prob_ts <- nested_pfu_prob %>%
mutate(data.ts = map(.x = data.tbl,
.f = to_ts))
unest_pfu_ts <- nested_pfu_prob_ts %>%
unnest(data.ts)
The code works without any problems however, when moving on to the modeltime functions I get the following error:
# Modeltime
pfu_prob_nest <- pfu_prob_nested %>%
extend_timeseries(
.id_var = id,
.date_var = quarter,
.length_future = 12
)
..1` must be a vector, not a function.
Does anyone know how I can solve this error?
Thank you