R forecast.holtwinters in forecast package not found
Asked Answered
T

5

7

I am trying to use the forecast.holtwinters function and when I try to run it:

dftimeseriesforecast <- forecast.HoltWinters(data, h=65)

I get this error:

Error: could not find function "forecast.HoltWinters"

I have also tried this:

 dftimeseriesforecast= forecast::forecast.HoltWinters(data, h=65)

But I get this error message:

Error: 'forecast.HoltWinters' is not an exported object from 'namespace:forecast'

I look at this list of functions in the forecast package using this code:

ls("package:forecast")

and this returns:

[1] "%>%" "accuracy" "Acf" "arfima" "Arima" "arima.errors" "arimaorder" "auto.arima"
[9] "autolayer" "baggedETS" "bats" "bizdays" "bld.mbb.bootstrap" "BoxCox" "BoxCox.lambda" "Ccf"
[17] "checkresiduals" "croston" "CV" "CVar" "dm.test" "dshw" "easter" "ets"
[25] "findfrequency" "forecast" "forecast.ets" "fourier" "fourierf" "gas" "geom_forecast" "GeomForecast"
[33] "getResponse" "ggAcf" "ggCcf" "gghistogram" "gglagchull" "gglagplot" "ggmonthplot" "ggPacf"
[41] "ggseasonplot" "ggsubseriesplot" "ggtaperedacf" "ggtaperedpacf" "ggtsdisplay" "gold" "holt" "hw"
[49] "InvBoxCox" "is.acf" "is.Arima" "is.baggedETS" "is.bats" "is.constant" "is.ets" "is.forecast"
[57] "is.mforecast" "is.nnetar" "is.nnetarmodels" "is.splineforecast" "is.stlm" "ma" "meanf" "monthdays"
[65] "msts" "na.interp" "naive" "ndiffs" "nnetar" "nsdiffs" "Pacf" "remainder"
[73] "rwf" "seasadj" "seasonal" "seasonaldummy" "seasonaldummyf" "seasonplot" "ses" "sindexf"
[81] "snaive" "splinef" "StatForecast" "stlf" "stlm" "taperedacf" "taperedpacf" "taylor"
[89] "tbats" "tbats.components" "thetaf" "trendcycle" "tsclean" "tsCV" "tsdisplay" "tslm"
[97] "tsoutliers" "wineind" "woolyrnq"

Does anyone know what is going on? I've used this before and had no problems. I'm using forecast version 8.1.

Troostite answered 28/7, 2017 at 13:28 Comment(0)
T
11

None of these things are in the forecast package. They are in 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 is an unexported function from stats which should only be called on objects from HoltWinters().

forecast.HoltWinters is an unexported function from forecast which means you need three colons to access it. But you should never have to do this because it should be automatically found when you run forecast on a the output from 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]

Same as:

> 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]
Ti answered 28/7, 2017 at 13:38 Comment(3)
I just checked and that is true for predict.Holtwinters, but it isn't true for forecast.Holtwinters. The forecast pdf lists forecast.Holtwinters and stats:::forecast.HoltWinters doesn't work. I get the same error. cran.r-project.org/web/packages/forecast/forecast.pdf. But, predict.holtwinters does just as well as forecast.Holtwinters so I can use this instead. Thank you @TiTroostite
Think I was a bit rushed with that answer. You need three colons to get unexported functions but you should never have to.. See edits.Ti
Also, I installed older version R 3.2 instead of the current version and forecast.holtwinters and predict.holtwinters was present and working properly, so I think there's a problem with version of R and forecast 8.1. But, holtwinters works fine with the stats package as well.Troostite
K
9

Use like this:

forecast:::forecast.HoltWinters().

It will work.

Kravits answered 2/6, 2018 at 12:31 Comment(0)
R
1

This works for me when using R v3.4.4 and forecast v8.2:

hw <- stats::HoltWinters(data) forecast_data <- forecast(hw, h=65)

Rutile answered 10/4, 2018 at 17:53 Comment(0)
C
1

you can try belows code,it will work. you need not HoltWinters.forecast.

    dftimeseries.hw <- HoltWinters(data)
    dftimeseries.forecast <-forecast(dftimeseries.hw,h=65)
Callas answered 14/9, 2018 at 5:5 Comment(0)
O
0

Use:

forecast_data <-forecast(mydata #data name,h=56)

after updating your r version and it will work

Obstinate answered 17/8, 2018 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.