library(dplyr)
library(fpp2) # for prison dataset
library(hts) # forecasting function
# prepare group time series
prison.gts <- gts(prison/1e3, characters = c(3,1,9),
gnames = c("State", "Gender", "Legal",
"State*Gender", "State*Legal",
"Gender*Legal"))
result_obj <- tidyr::crossing(methods = c('bu', 'comb'),
fmethods = c('arima'),
algorithms = c("lu", "cg", "chol", "recursive", "slm")) %>%
mutate(forecast_result = purrr::map2(methods, fmethods, algorithms,
~forecast.gts(prison.gts,
method = ..1,
fmethod = ..2,
algorithms = ..3)))我使用tidyr::inter越来创建参数的可能组合,然后这些参数将成为forecast.gts()的输入。
由于我有两个以上的参数,所以参数使用..x表示法进行映射,即..1、..2、..3 https://purrr.tidyverse.org/reference/map2.html
但是,似乎每个组合的结果都是空的。
如果我单独调用这个函数,它会给出结果。
forecast.gts(prison.gts, method="bu", fmethod="arima", algorithms = 'lu')发布于 2020-04-15 08:38:23
map2只接受两个参数。对于超过2个参数,请使用pmap:
library(dplyr)
library(fpp2)
library(hts)
result_obj <- tidyr::crossing(
methods = c('bu', 'comb'),
fmethods = c('arima'),
algorithms = c("lu", "cg", "chol", "recursive", "slm")) %>%
mutate(forecast_result = purrr::pmap(list(methods, fmethods, algorithms),
~forecast.gts(prison.gts,
method = ..1,
fmethod = ..2,
algorithms = ..3)))但是,这将返回以下错误消息:
错误:递归算法不支持gts对象。
因此,您可能需要从algorithms向量中删除它,然后它就可以正常工作了。
https://stackoverflow.com/questions/61224456
复制相似问题