Last modified: December 14, 2024

This article is written in: 🇺🇸

Time Series Analysis

Time series data consists of sequential observations collected over a period of time. This kind of data is prevalent in a range of fields such as finance, economics, climatology, and more. Time series analysis involves the exploration of this data to identify inherent structures such as patterns or trends, forecasting future points in the series, and providing insights for strategic decision-making.

Definition: An ordered sequence of values representing a variable, recorded at equally spaced time intervals.

The need for Time Series Models

You are probably aware of regression models, where models predict one quantity based on the relationship with another quantity. They typically involve using independent variables to predict dependent variables. For example, when predicting electricity consumption for a particular month, we would take into consideration temperature, number of residents, and so on. These factors might seem sufficient for all cases of prediction, making the creation of an entirely new domain of models just for time series seem unnecessary, doesn’t it? However, the issue arises when past values influence the current value. This is where time series models come into play. For instance, predicting this month's electricity consumption based on last month's consumption can be achieved using an AR(1) model.

Non-Time Series Approach:

Time Series Approach:

Below is a plot that visualizes the historical data and predictions of electricity consumption over time.

electricity consumption over time

The plot includes three components:

  1. Historical Data shown as a solid line, this represents the actual electricity consumption data collected over a two-year period from January 2021 to December 2022.
  2. Regression Prediction represented by a dashed blue line, this forecast is based on a linear regression model. It captures a simple trend over the historical data and projects it forward for the first three months of 2023.
  3. Time Series Prediction shown as another dashed line, this prediction uses an Exponential Smoothing model with a seasonal component. It considers both trend and seasonality in the data to provide a more dynamic projection for the same three-month period.

Components of a Time Series

A time series is a series of data points indexed in chronological order, typically at regular time intervals. It can be decomposed into four primary components:

Time Series Analysis Techniques

Timeseries analysis methods can be broadly classified into two main categories: time-domain methods and frequency-domain methods.

Time-Domain Methods

These methods analyze the temporal sequences of data points directly. The focus here is on identifying patterns such as trends, seasonality, noise, and fluctuations within the time series data.

Important Techniques Include:

Some of the methods used for time-domain analysis include:

After decomposing the time series into its components, statistical techniques can be employed to model and forecast future points in the series. Some widely used techniques include:

Frequency-Domain Methods

These methods focus on transforming the time series data into the frequency domain to detect and study cyclic behaviors and periodicities. This is typically done through mathematical transforms that help decompose the time series into constituent frequencies.

Important Techniques Include:

These techniques enable you to study the frequency composition of the data, highlighting dominant cycles that might not be apparent in the time domain.

Parametric vs. Non-Parametric Methods

Types of Timeseries

The classification also distinguishes between:

Below is a plot demonstrating the four concepts of time series modeling:

types_of_models

  1. Linear Univariate Model shows predictions using a single variable with a linear ARIMA model.
  2. Linear Multivariate Model shows predictions with multiple variables using a VAR model.
  3. Nonlinear Univariate Model shows predictions using a single variable with a nonlinear MLP model.
  4. Nonlinear Multivariate Model shows predictions with multiple variables using a nonlinear MLP model.

Applications of Time Series Analysis

Time series analysis finds widespread applications across various industries, including:

Example

Let's consider a simplified example of time series data and apply some basic analysis techniques to it. Imagine we have the following monthly sales data for a retail store:

Month Sales
1 100
2 120
3 110
4 130
5 140
6 150
7 160
8 180
9 170
10 190
11 200
12 210

Plotting the Time Series Data

First, we can visualize the data using an ASCII plot:

Sales
210 |                                   x
200 |                                x
190 |                             x
180 |                         x
170 |                      x 
160 |                   x 
150 |                x
140 |             x
130 |          x
120 |       x
110 |    x
100 | x
    -------------------------------------
      1  2  3  4  5  6  7  8  9  10 11 12
                   Month

From the plot, we can see an increasing trend in the sales data.

Applying Moving Average

Next, let's apply a moving average with a window size of 3 to smooth out short-term fluctuations:

Month Sales Moving Average (Window=3)
1 100
2 120
3 110 120
4 130 110
5 140 127
6 150 140
7 160 150
8 180 163
9 170 180
10 190 170
11 200 187
12 210 200

The moving average shows an increasing trend in sales, similar to the original time series plot.

Here's the plot with the analysis using Simple Exponential Smoothing (SES) on the given sales data:

sales_prediction

Table of Contents

    Time Series Analysis
    1. The need for Time Series Models
    2. Components of a Time Series
    3. Time Series Analysis Techniques
      1. Time-Domain Methods
      2. Frequency-Domain Methods
      3. Parametric vs. Non-Parametric Methods
      4. Types of Timeseries
    4. Applications of Time Series Analysis
    5. Example
    6. Plotting the Time Series Data
      1. Applying Moving Average