我正在尝试使用forecast.holtwinters函数,当我尝试运行它时:
dftimeseriesforecast <- forecast.HoltWinters(data, h=65)
我收到此错误:
错误:找不到功能&#34; forecast.HoltWinters&#34;
我也试过这个:
dftimeseriesforecast= forecast::forecast.HoltWinters(data, h=65)
但我收到此错误消息:
错误:&#39; forecast.HoltWinters&#39;不是来自&#39;命名空间的导出对象:预测&#39;
我使用以下代码查看预测包中的这个函数列表:
ls("package:forecast")
然后返回:
[1]&#34;%&gt;%&#34; &#34;准确性&#34; &#34; ACF&#34; &#34; ARFIMA&#34; &#34;马&#34; &#34; arima.errors&#34; &#34; arimaorder&#34; &#34; auto.arima&#34;
[9]&#34;自动涂层&#34; &#34; baggedETS&#34; &#34;蝙蝠&#34; &#34; bizdays&#34; &#34; bld.mbb.bootstrap&#34; &#34; BoxCox&#34; &#34; BoxCox.lambda&#34; &#34; CCF&#34;
[17]&#34; checkresiduals&#34; &#34;克罗斯顿&#34; &#34; CV&#34; &#34; CVAR&#34; &#34; dm.test&#34; &#34; dshw&#34; &#34;复活节&#34; &#34; ETS&#34;
[25]&#34;发现频率&#34; &#34;预测&#34; &#34; forecast.ets&#34; &#34;傅立叶&#34; &#34; fourierf&#34; &#34;气体&#34; &#34; geom_forecast&#34; &#34; GeomForecast&#34;
[33]&#34; getResponse&#34; &#34; ggAcf&#34; &#34; ggCcf&#34; &#34; gghistogram&#34; &#34; gglagchull&#34; &#34; gglagplot&#34; &#34; ggmonthplot&#34; &#34; ggPacf&#34;
[41]&#34; ggseasonplot&#34; &#34; ggsubseriesplot&#34; &#34; ggtaperedacf&#34; &#34; ggtaperedpacf&#34; &#34; ggtsdisplay&#34; &#34;金&#34; &#34;霍尔特&#34; &#34; HW&#34;
[49]&#34; InvBoxCox&#34; &#34; is.acf&#34; &#34; is.Arima&#34; &#34; is.baggedETS&#34; &#34; is.bats&#34; &#34; is.constant&#34; &#34; is.ets&#34; &#34; is.forecast&#34;
[57]&#34; is.mforecast&#34; &#34; is.nnetar&#34; &#34; is.nnetarmodels&#34; &#34; is.splineforecast&#34; &#34; is.stlm&#34; &#34;毫安&#34; &#34; meanf&#34; &#34; monthdays&#34;
[65]&#34; msts&#34; &#34; na.interp&#34; &#34;幼稚&#34; &#34; ndiffs&#34; &#34; nnetar&#34; &#34; nsdiffs&#34; &#34; PACF&#34; &#34;其余&#34;
[73]&#34; rwf&#34; &#34; seasadj&#34; &#34;季节性&#34; &#34; seasonaldummy&#34; &#34; seasonaldummyf&#34; &#34; seasonplot&#34; &#34; SES&#34; &#34; sindexf&#34;
[81]&#34; snaive&#34; &#34; splinef&#34; &#34; StatForecast&#34; &#34; STLF&#34; &#34; stlm&#34; &#34; taperedacf&#34; &#34; taperedpacf&#34; &#34;泰勒&#34;
[89]&#34; tbats&#34; &#34; tbats.components&#34; &#34; thetaf&#34; &#34; trendcycle&#34; &#34; tsclean&#34; &#34; TSCV&#34; &#34; tsdisplay&#34; &#34; TSLM&#34;
[97]&#34; tsoutliers&#34; &#34; wineind&#34; &#34; woolyrnq&#34;
有谁知道发生了什么事?我以前用过这个,没有问题。我使用预测版本8.1。
答案 0 :(得分:8)
这些内容都不在forecast
包中。它们位于stats
:
> m <- stats::HoltWinters(co2)
> class(m)
[1] "HoltWinters"
> p = predict(m)
> pp = stats:::predict.HoltWinters(m)
> p
Jan
1998 365.1079
> pp
Jan
1998 365.1079
predict.HoltWinters
是来自stats
的未导出函数,只应在来自HoltWinters()
的对象上调用。
forecast.HoltWinters
是来自forecast
的未导出函数,这意味着您需要三个冒号才能访问它。但是你应该永远不必这样做,因为当你在forecast
的输出上运行HoltWinters()
时应该会自动找到它:
> m <- stats::HoltWinters(co2)
> forecast(m)
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Jan 1998 365.1079 364.7139 365.5019 364.5053 365.7105
Feb 1998 365.9664 365.5228 366.4100 365.2879 366.6449
[etc]
同样:
> forecast:::forecast.HoltWinters(m)
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Jan 1998 365.1079 364.7139 365.5019 364.5053 365.7105
Feb 1998 365.9664 365.5228 366.4100 365.2879 366.6449
[etc]
答案 1 :(得分:5)
像这样使用:
forecast:::forecast.HoltWinters().
它会起作用。
答案 2 :(得分:1)
使用R v3.4.4和预测v8.2时,这对我有用:
hw <- stats::HoltWinters(data)
forecast_data <- forecast(hw, h=65)
答案 3 :(得分:0)
使用:
forecast_data <-forecast(mydata #data name,h=56)
在更新您的r
版本之后,它将起作用
答案 4 :(得分:0)
您可以尝试下面的代码,它将起作用。您不需要HoltWinters.forecast。
dftimeseries.hw <- HoltWinters(data)
dftimeseries.forecast <-forecast(dftimeseries.hw,h=65)