Reputation: 10568
Data:
data <- c(13,15,13,15,18,44,22,20,35,25,22,26,24,
26,38,25,32,47,17,23,49,19,22,44,14,18,37)
ts <- ts(data, frequency = 12, start = c(2013,1))
I want to forecast 12 months ahead with HoltWinters
tsHolt <- HoltWinters(ts, seasonal = "additive")
tsHoltPredict <- HoltWinters(tsHolt, seasonal = "additive", h = 12)
plot(tsHoltPredict)
But I am getting:
Error in HoltWinters(tsHolt, seasonal = "additive", h = 12) : unused argument (h = 12)
Upvotes: 2
Views: 2441
Reputation: 237
I was having the same problem.
Here is how to solve it: -
library(forecast)
# Creating a time series object
Data_ts <- ts(Data, frequency = 12)
fit = HoltWinters(Data_ts)
# Forecasting using Holt-Winters
pred = forecast::forecast(fit, h = 12) # forecasting for the next 12 months.
plot(pred)
The critical part in the code is to use: -
forecast::forecast(fit, h = 12)
If you are using various libraries, then the forecast's library functions gets masked. Hence, we have to specify that we must use forecast function from forecast library.
Upvotes: 0
Reputation: 10568
Re-reading the library(forecast)
documentation it seems that:
forecast(tsHolt, 12)
works as well!
Upvotes: 0
Reputation: 1417
Is predict()
what you are looking for?
tsHoltPredict <- predict(tsHolt, n.ahead = 12, prediction.interval = TRUE)
Upvotes: 2