Search code examples
rforecastingholtwinters

R forecast.holtwinters in forecast package not found


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.


Solution

  • 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]