Time Series Forecasting with R (Part 2)
ETS, ARIMA and Prophet Method
Time Series Forecasting with R (Part 2)
ETS, ARIMA and Prophet Method

If you are interested in articles related to my experience, please feel free to contact me: linkedin.com/in/nattapong-thanngam
This article is part of a series about Customer Analytics_._ (Part 1: Basic Time Series Forecasting with R),(Part 2: ETS, ARIMA, and Prophet Method by R_)_,(Part 3: ARIMA and Prophet Method by Python_)_
Overview:
- Data source name: Monthly CO2 Concentration (ppm) in Hawaii
- Program: R, use library(fpp3) and library(fable.prophet)
Introduction:
- ETS (Error, Trend, Seasonal) method is an approach method for forecasting time series univariate. This ETS model focuses on trend and seasonal components. Some methods we have already seen using other names.

Source: Forecasting: Principles and Practice (2nd ed)
- ARIMA (Autoregressive integrated moving average) method
- AR: Autoregression. A model that uses the dependent relationship between an observation and some number of lagged observations.
- I: Integrated. The use of differencing of raw observations (e.g. subtracting an observation from observation at the previous time step) in order to make the time series stationary.
- MA: Moving Average. A model that uses the dependency between an observation and a residual error from a moving average model applied to lagged observations. - Prophet is a procedure for forecasting time series data based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality, plus holiday effects. The procedure makes use of a decomposable time series model with three main model components: trend, seasonality, and holidays. Link for more detail.
Step 1: Data Preparation and Data understanding
Note: same as part 1
- Filter data: Screen only data in Y2010 onward
- Separate train & validate data set:
- Train = Jan.10 — Dec.19,
- Validate = Jan.20 — Feb.22
Step 2: Fit model
- Method: ETS, ARIMA, and Prophet
- 1–7 Models are ETS methods that R will automatically select the best ETS method based on the lowest AIC

Fit model (Image by Author)
Step 3: Model validation
- Forecast data = 26 period. (Jan.20 — Feb.22)

Predicted value of 9 models (Image by Author)

Predicted value (only 3 models) vs Actual data (Image by Author)
- If focus only 3 models, ETS model is the best performance for this data.

Model validation (Image by Author)
Step 4: Residual plot
- Use: gg_tsresiduals → Good model has to follow the below criteria
- Independent (or uncorrelated) → bottom left graph shows independent (ACF plot not over the blue line) (ok)
- Mean of residual = 0 → bottom right graph show ~0 (ok)
- Constant variance → Top graph shows constant (ok)
- Normal distribution → bottom right graph shows normal distribution (ok)

Residual plot by ETS model (Image by Author)
Step 5: Forecast data
- For ETS function, R will automatically minimize AIC. ETS(A,A,A) means
- Error = Additive error
- Trend component= Additive → Train data has trend
- Seasonal component = Additive → Train data has season
- Other parameters are shown below

Error, Trend, Season, and parameters of ETS model (Image by Author)

FCST data by ETS model (Image by Author)
- For more information, if I select ARIMA, R will automatically minimize AICc. ARIMA(1,0,1)(2,1,0)[12] means
- (1,0,1) → non-seasonal → (p,d,q)
- (2,1,0)[12] → seasonal → (P,D,Q)[s]
- Data is not stationary → “d” or “D” should not be Zero
- Have season as yearly → “m” should be 12

Source: https://otexts.com/fpp2/seasonal-arima.html

All parameters of ARIMA model (Image by Author)

FCST data by ARIMA model (Image by Author)

Residual plot by ARIMA model (Image by Author)
- For Prophet, result is shown below

FCST data by library(fable.prophet) (Image by Author)

Residual plot by Prophet model (Image by Author)
Note:
- To increase accuracy, cross-validation, decomposition, or combinate method are recommended methods.
- Model by Python
Please feel free to contact me, I am willing to share and exchange on topics related to Data Science and Supply Chain.
Facebook: facebook.com/nattapong.thanngam
Linkedin: linkedin.com/in/nattapong-thanngam