Time Series Analysis and Forecasting
By: Charanraj Shetty
Tags: Time Series Forecasting, Data Science, Time Series Analysis, Stationarity, Components Of Time Series

Time Series Analysis and Forecasting

Introduction to its Components and Stationarity

Time Series Analysis is a method used in prediction or forecasting the future w.r.t to time-based on historical data. It’s used across the various platforms like Stock Market price analysis, Sale of products, Room booking prediction, demand for food items, the spread of the pandemic, etc. Time series can have an impact on any component which have direct or indirect factors in the future. Time series can be defined as a deviation of observation over a given sequence of time intervals. Observations could be the price of the share, count of sales, no. of cases reported in a day. But out of all these observations, there is one common thing that is noticeable. We can conclude that everything as a function of time. Hence Time Series Analysis is a univariate variable analysis.

Photo by Markus Spiske on Unsplash

Components of Time :

1. Trend:

The trend is a component of time that displays either the upward flow or downward flow if the observation is plotted against the time graph. Trend gives us that either the pattern of the observation is decreasing or increasing concerning the time.

For e.g., let’s assume that we established a new Hotel and Lodge facility on the outskirts of the city where there is no commercial presence around the newly constructed hotel. But due to city development, the local government declared a new airport opening for the city, which fortunately is closer to your newly constructed lodge. Once the airport is constructed and fully up and running, it is observed that the no of bookings in your lodge is rising exponentially with each passing day. So here, the time is an example of displaying the Trend component present in it.

Photo by Burak K from Pexels

2. Seasonal:

The seasonal component of the time series is the pattern recorded for an observation, which is repetitively noted over a longer period of intervals. The seasonal component suggests that during a particular period or phase of a year, there might be a predictable spike recorded for an observation.

E.g., Going back to the Time series analysis of the Hotel booking example, lets us assume that we took the data of hotel booking for the past five years. It is observed that we can record a sudden spike around a particular period of the year. Further deep diving into the analysis, we can conclude that the sudden rise in bookings is due to the festival mode as people come over to celebrate in the city.

Photo by Pixabay from Pexels

3. Errors:

The error component of the time series is the unusual pattern of behavior recorded for the observation. The error component suggests that there was a weird spike observed, which has never happened in the historical data for the observation concerning time.

E.g., Going back to the Time series analysis of the Hotel booking example, let us assume that looking at your progress in business, the investors across the city decided to set up a new hotel next to you considering the profit margin you are enjoying in the last few years. In the coming years, we observe that there is a sudden downward spike in the hotel booking, which is an unusual spike observed in the historical data of your hotel bookings. The reason why this happened is due to some external factors which your observation mapped against time. The setup of the new hotel has impacted your business, which you never saw coming. So this is the component of time which is unpredictable as its an external factor which results in the generation of the same.

Photo by Markus Winkler on Unsplash

Stationarity:

To predict the observation at (t+1) time period, we have to make sure the time series consisting of the historical data at t, t-1, t-2, ….., t-k must be Stationary. The term stationary means that the variance and mean both must remain constant with time at different time intervals. If the variance and mean are not stationary with time then it is difficult to forecast the observation at (t+1) time interval. Also, the stationary points are the non-seasonal time-series observations.

Points to validate Stationary points :

1. Mean is constant

2. Variance is constant

3. Non-seasonal time-series observations.

Variance is constant, but the mean is irregular

Let us understand this with an example to differentiate between stationary and non-stationary time series analysis. Take an example of the figure below. Let us take any two-time intervals P1 and P2. The mean or the average of the slope of the wave in the P2 interval is more than the mean in the P1 interval. Although the variance is constant, the mean around the intervals is not constant, resulting in a non-stationary time series analysis.

Image by Tumisu from Pixabay

The mean is constant, but the variance is irregular

Consider another example below where the mean is constant in intervals P1 and P2. But the variance is varying with time. So this is an example of a non-stationary time series of observations.

Image by OpenClipart-Vectors from Pixabay

Constant mean and variance but seasonal

Consider another example below where the mean and variance are both constant in intervals P1 and P2. But the seasonality is observed in the time series for the given observation. So this is an example of a non-stationary time series of observations.

Image by PublicDomainPictures from Pixabay

How to convert a non-stationary series into stationary series

To convert to stationary time-series data, we apply a differencing concept. We subtract the observation at (t-1) from t and store the result in the new series data. After plotting the data, if all the conditions of the stationarity are satisfied, then we can start with modeling to predict the values at t+1 by applying time series models. However, if they don’t achieve the stationarity even after first differencing, then we can continue differencing until we reach the required stationarity condition.

X = [5,4,6,7,9,12,12]

Image by Author

After applying first differencing :

X(1) = [1,-2,-1,-2,-3,0]

Image by Author

If the graph still doesn’t achieve the stationarity we can apply difference again to see if the output graph reaches stationarity.

This was all about the various components of the Time series, how to identify those components, and also what is stationarity and how to achieve stationarity.

Thanks for reading the article.

In the next article, I will be introducing the models in Time Series.