【发布时间】:2016-02-05 11:52:13
【问题描述】:
我有一些时间序列销售数据,我想预测给定范围内的销售。我使用 Holt-Winters、ets、神经网络和其他一些方法,然后混合它们的结果。但是,取决于 Holt Winters 并不总是有效。我编写了两个函数,一个名为forecastWithHoltWinters,另一个是forecastWithoutHoltWinters,可能目标是如果forecastWithHoltWinters 产生错误,那么我需要运行forecastWithoutHoltWinters。它们都有相同的输入,即salesdata(时间序列数据)和horizon(标量),对于给定的horizon 周期,输出是salesforecast。
检查How to write trycatch in R 中最受好评的答案,我编码如下:
forecastWithHoltWinters <- function(salesdata, horizon)
{
salesforecast <- tryCatch(
{
#Lots of lines that forecastWithHoltWinters does
}, error <- function (salesdata, horizon)
{
salesforecast = forecastWithoutHoltWinters(salesdata, horizon)
return (salesforecast)
}
return (salesforecast)
}
我可以看到这里的情况很不对,但我似乎无法将我的问题适应tryCatch()。我也去过http://mazamascience.com/WorkingWithData/?p=912。稍后我会调整警告,但首先我需要处理错误。
我该怎么做?
编辑:我研究了一段时间,没有任何采购错误。然而,error <- function (salesdata, horizon) 不会将输入传输到forecastWithoutHoltWinters 函数,因此该函数不起作用。
【问题讨论】:
标签: r try-catch time-series