Time Series Decomposition

using R stats::decompose() function

Calin Uioreanu
Developing Data Products Course Project

Summary

This is a short presentation for the course project shiny application. We have chosen Time series decomposition, a hot topic in data mining.

Our goals:

  • create a shiny application.
  • publish it on the Web using shinyapps.io.
  • create a presentation using the slidify library
  • publish it on rpubs and cross-link.

Time Series Decomposition using R's stats::decompose() function and default time series datasets, as well as forecasting using arima.

Datasets

We make use of R's base package stats time series datasets.

(data()$results[1,c(3:4)])
##                                          Item 
##                               "AirPassengers" 
##                                         Title 
## "Monthly Airline Passenger Numbers 1949-1960"

We have picked the AirPassengers, nottem and sunspots Time Series.

length(AirPassengers)
## [1] 144

Decomposition using R decompose() function

R's powerful time series decomposition tools allow the separation into seasonal, trend and irregular components. The stats::decompose() function uses moving averages

plot(decompose(nottem))

plot of chunk unnamed-chunk-3

Forecasting using R arima() and predict() functions

Our goal is to predict a 2 years period using R´s predict.Arima() function. We use R's arima (Autoregressive Integrated Moving Average) modeling to create a statistical model for the irregular component of time series. We use a basic order of (1,0,0) for the arima model and define the periodicity (monthly data, 12). We then make use of the predict function, plot the forecast together with the 95% Confidence Interval.

arima(AirPassengers, order=c(1,0,0))
## 
## Call:
## arima(x = AirPassengers, order = c(1, 0, 0))
## 
## Coefficients:
##          ar1  intercept
##       0.9646   278.4649
## s.e.  0.0214    67.1141
## 
## sigma^2 estimated as 1119:  log likelihood = -711.09,  aic = 1428.18

Final slide