Time Series Basics

Chalindu Kodikara
6 min readMar 20, 2022

--

1. Time Series

In simple words, time series is a series of data points ordered in time. The following diagram shows a time series in a graph representation.

Time series data

Time is often the independent variable and data points are the dependent variable. We can take any variable that changes with time as the y variable. For example, the y variable (In this case marked as Data) can be latency, throughput, number of sales, bitcoin price, stock market values, etc…

Since the data points are taken at successive equally spaced points in time, time series can be considered as a sequence of discrete-time data.

— — — — — — — — — — — — — — — — — — — —

2. Time Series Analysis

Time series analysis contains methods that can extract useful statistics and other behaviours of the data. Time series data can contain trends, patterns, and seasonality patterns. When it comes to analysing, it requires a large number of data points to ensure the reliability and consistency of the statistics that we get from the analysing.

Another advantage is, time-series data can be used to predict future values based on past values.

Time series data:

  • Helps organizations to find trends or patterns over time
  • Helps to find outliers in the data points
  • Helps organizations to predict future values
  • Can be used to forecast weather
  • Can be useful for tracking changes in application performance
  • Can be used for stock market analysis

— — — — — — — — — — — — — — — — — — — —

In order to analyze time series, we need to understand underlying patterns. Patterns are composed of different components. The components of time series data are given below,

➖ Seasonality

➖ Trend

➖ Cycle

➖ Irregular

2.1 Time Series Components

Seasonality

Seasonality is the periodic fluctuations in the time series data.

Ex:- Electric consumption is high during the day and low during the night. This happens every day, so the fluctuation is periodic.

The below diagram shows 3 month seasonality in the annual sales.

Seasonal Pattern for annual sales

Trend

The trend is a long term pattern present in the time series. So there is a tendency of data to increase or decrease during a long period of time. It is not a must to always decrease or increase in the long period. An increase, a decrease or stable sections of time can be seen in the long period of a trend. But the overall trend must be a downtrend, uptrend or stable.

An uptrend in the passengers' data

Cycle

The cyclic component of a time series refers to the periodic fluctuations in the data around the trend. Generally, cycles last longer than a year.

Seasonality is not equal to cyclical effects. Seasonality is observed within one calendar year. Seasonality can be daily, weekly, monthly, or yearly. For a cycle, there is no specific time period. It can be shorter or longer than one calendar year.

Irregular

Irregular fluctuations are sudden changes that happen in the time-series data. These short-term fluctuations can occur due to various reasons. These fluctuations are not predictable and uncontrollable.

— — — — — — — — — — — — — — — — — — — —

There are some aspects that we should consider when it comes to time series analysis.

Covariance, autocovariance

stationary

Correlation, autocorrelation, partial autocorrelation

2.2 Time Series Analysis — Other Important Aspects

Covariance

Covariance is used to determine the relationship between two random variables.

Ex: Bitcoin and Ethereum prices increase or decrease together — Positive Covariance. Bitcoin and Ethereum prices change inversely — Negative Covariance.

Autocovariance — The covariance of X(t) and X(t+T) is a function of their time difference(T is called lag). Since the covariance is taken for the same random variable, it is called autocovariance.

Stationary

A time series can be considered stationary if its properties don’t change over time. Therefore, it has a constant mean and constant variance. There is no seasonality and trend as well.

✔️ No trend or seasonality in the series

There are 2 categories in stationary.

  1. Strictly(Strongly) Stationary

Any order statistics don’t change with time.

2. Weakly Stationary

It is hard to model practical random variables as strictly stationary. Therefore, we define weakly stationary to model practical distributions.

  • Mean is time-invariant
  • Variance is time-invariant
  • Autocovariance is time-invariant — covariance depends only on the lag. Autocovariance means the covariance between the same random variable. Two time points t1 & t2, the covariance between Xt1 and Xt2 is the autocovariance.

Cov(Xt1, Xt2) = Cov(Xt3, Xt4) = Cov(Xt6, Xt7)

Correlation

Correlation quantifies the relationship between two random variables. In simple terms, correlation is a unit measure. Covariance can vary from -infinity to +inifinity. But correlation can only vary from -1 to +1. +1 indicates that those 2 variables have a strong direct relationship.

Autocorrelation — is the measure of the degree of correlation of the same random variable in two successive time intervals.

Ex:- Values that are separated by an interval can have a positive or negative correlation.

Autocorrelation in time-series data

When these correlations are present in a time series, it means past values of the time series influence the present values.

The below diagram is an autocorrelation function of a time series. Using the autocorrelation function, we can identify whether the time series has a trend or a seasonality. If the series is stationary, it can also be identified using an ACF(autocorrelation function) plot.

ACF Plot of time a time-series data

Partial Autocorrelation

Partial autocorrelation is the measure of the autocorrelation between an observation in time (t) with an observation in time (t-k). But all the time lags between (t) to (t-k) is not considered.

PACF Plot of time a time-series data

Autocorrelation vs Partial autocorrelation

Example

Let’s take, S-chicken price monthly

S(t)-chicken price in March

S(t-1)-chicken price in February

S(t-2)-chicken price in January

Let’s consider the price of chicken in January and March. There is a direct effect as well as indirect effect from the January price to the March price. Indirect effects happen through February month price.

Autocorrelation considers the direct effect as well as the indirect effect. But partial autocorrelation considers only the direct effect.

So Partial autocorrelation is very important. It gives the direct effect from the price of chicken some number of months ago to the price of chicken today.

— — — — — — — — — — — — — — — — — — — —

Do feel free to comment and give your feedback.

You can connect with me on LinkedIn: https://www.linkedin.com/in/chalindukodikara

— — — — — — — — — — — — — — — — — — — —

References:

Time series — Wikipedia

Time Series Definition (investopedia.com)

--

--

Chalindu Kodikara

Computer Science and Engineering Graduate, Software Engineer