【发布时间】:2017-07-05 11:15:59
【问题描述】:
我正在尝试执行来自:http://unconj.ca/blog/forecasting-yyz-passengers-in-the-tidyverse.html的代码
在中间的某个地方.....
首先,我们创建模型及其参数的数据集。以下将生成所有可能的 ETS 模型的数据框
ets.params <- crossing(error = c("A", "M"), trend = c("N", "A", "M"),seasonal = c("N", "A", "M"), damped = c(TRUE, FALSE)) %>%
# Drop combinations with a damped non-trend.
mutate(drop = ifelse(trend == "N" & damped, TRUE, FALSE)) %>%
# Create labels for the models out of these parameters.
mutate(kind = "ETS", desc = paste0("(", error, ",", trend,ifelse(damped, "d", ""),",", seasonal, ")"),model = paste0(error, trend, seasonal))
# Drop nonsensical models (these are flagged by `ets` anyway).
ets.params1<-subset(ets.params,!(ets.params$model %in% c("MMA","AMN","AMA","AMM","ANM","AAM")))
ets.params1
# A tibble: 24 x 8
error trend seasonal damped drop kind desc model
<chr> <chr> <chr> <lgl> <lgl> <chr> <chr> <chr>
1 A A A FALSE FALSE ETS (A,A,A) AAA
2 A A A TRUE FALSE ETS (A,Ad,A) AAA
3 A A N FALSE FALSE ETS (A,A,N) AAN
4 A A N TRUE FALSE ETS (A,Ad,N) AAN
5 A N A FALSE FALSE ETS (A,N,A) ANA
6 A N A TRUE TRUE ETS (A,Nd,A) ANA
7 A N N FALSE FALSE ETS (A,N,N) ANN
8 A N N TRUE TRUE ETS (A,Nd,N) ANN
9 M A A FALSE FALSE ETS (M,A,A) MAA
10 M A A TRUE FALSE ETS (M,Ad,A) MAA
# ... with 14 more rows
有了这组模型参数,我们可以创建列表列,其中包含训练数据和计算模型的函数(在本例中为 ets)。
我可以执行上面的代码,但是下面的代码会报错...
ets.models <- ets.params %>%
# Add in the training set and the modelling function.
mutate(fn = replicate(forecast::ets, n = n()),
train = replicate(list(train), n = n())) %>%
# Create a "param" column to pass to `fn`.
mutate(params = purrr::transpose(list(
"y" = train, "model" = model, "damped" = damped
))) %>%
select(kind, desc, train, fn, params)
ets.models
我收到错误: 错误:不应直接调用此函数。错误似乎来自 mutate()..
需要帮助!!!!
【问题讨论】:
标签: r time-series tidyverse purrr