Forecasting time series
After using HoltWinters
to build a time series smoothing model, we can now forecast future values based on the smoothing model. In this recipe, we introduce how to use the forecast
function to make a prediction on time series data.
Getting ready
In this recipe, you have to have completed the previous recipe by generating a smoothing model with HoltWinters
and have it stored in a variable, m.pre
.
How to do it…
Please perform the following steps to forecast Taiwan Semiconductor's future income:
- Load the
forecast
package:> library(forecast)
- We can use the
forecast
function to predict the income of the next four quarters:> income.pre <- forecast.HoltWinters(m.pre, h=4) > summary(income.pre) Forecast method: HoltWinters Model Information: Holt-Winters exponential smoothing with trend and additive seasonal component. Call: HoltWinters(x = m) Smoothing parameters: alpha: 0.8223689 beta : 0.06468208 gamma: 1 Coefficients: [,1] a 1964...