Y.ts <- ts(Y, frequency=12, start=c(2010,1)) | | #1: store the data in a time series object |
Y.forecasts <- HoltWinters(Y.ts, beta=FALSE, gamma=FALSE) | | #2: fit a simple exponential smoothing predictive model using the "HoltWinters()" function |
library("forecast") | | #3: load the "forecast" R package |
Y.forecasts2 <- forecast.HoltWinters(Y.forecasts, h=6) | | #4: forecast up to 6 months |
Y.forecasts2 | | #5: display forecasts |
par(mfrow = c(2,1)) | | #6: 2x1 charts |
plot(Y.forecasts2) | | #7: plot the forecasts with 80%,95% prediction interval |
acf(Y.forecasts2$residuals, lag.max=20) | | #8: correlogram of the in-sample forecast errors for lags 1-20 |