Time Sequence Forecasting Made Easy (Half 4.1): Understanding Stationarity in a Time Sequence

0
1431
Time Sequence Forecasting Made Easy (Half 4.1): Understanding Stationarity in a Time Sequence


to this point, we have now mentioned completely different decomposition strategies and baseline fashions. Now, we transfer on to Time Sequence Forecasting fashions like ARIMA, SARIMA, and so forth.

However these forecasting fashions require the info to be stationary. So first, we’ll focus on what stationarity in a time collection truly is, why it’s required, and the way it’s achieved.


Maybe most of you will have already learn loads about stationarity in a time collection by means of blogs, books, and so forth., as there are a whole lot of assets obtainable to find out about it.

At first, I assumed to elucidate what stationarity in time collection is after I focus on forecasting fashions like ARIMA, and so forth.

However after I first learnt about this subject, my understanding didn’t go a lot past fixed imply or variance, robust or weak stationarity, and exams to verify for stationarity.

One thing all the time felt lacking; I used to be unable to know just a few issues about stationarity.

So, I made a decision to jot down a separate article on this subject to elucidate what I learnt in response to my questions or doubts on stationarity.

I simply tried to jot down about stationarity in time collection in a extra intuitive approach, and I hope you’re going to get a recent perspective on this subject past the strategies and statistical exams.


We name a time collection stationary when it has a relentless imply, fixed variance and a relentless autocovariance or fixed autocorrelation construction.

Let’s focus on every property.

What can we imply by Fixed Imply?

For instance, think about a time collection of gross sales information for five years. If we calculate the typical gross sales of every yr, the values must be roughly the identical and if the averages differ considerably for every year, then there isn’t any fixed imply and time collection is just not stationary.

Picture by Creator

The following property of a stationary time collection is Fixed Variance.

If the unfold of the info is identical all through the collection, then it’s stated to have Fixed Variance.

In different phrases, if the time collection goes up and down by related quantities all through the collection, then it’s stated to have Fixed Variance.

But when the ups and downs begin small after which turn out to be bigger later, then there isn’t any fixed variance.

Picture by Creator

The third property of a stationary time collection is Fixed Autocovariance (or Autocorrelation).

If the connection between values relies upon solely on the hole between them, no matter once they happen, then there’s Fixed Autocovariance.

For instance, you will have written a weblog and tracked its views for 50 days and if every day’s views are intently associated to earlier day’s views (day 6 views just like day 5 and day 37 views just like day 36, as a result of they’re at some point aside).

If this relationship stays the identical all through the whole collection, then autocovariance is fixed.

In a stationary time collection the autocorrelation normally decreases because the lag (or distance) will increase as a result of solely close by values are strongly associated.

If autocorrelation stays excessive at bigger lags, it could point out the presence of development or seasonality, suggesting non-stationarity.

When a time collection has all of those three properties, then we name it a stationary time collection, however we name this a second order stationarity or weak stationarity.

There are primarily two varieties of stationarity:
1) Robust Stationarity
2) Weak Stationarity

Robust Stationarity means the whole time collection stays the identical at any time when we observe it, not simply imply and variance however even skewness, kurtosis and general form of distribution.

In actual world that is uncommon for a time collection, so the basic forecasting fashions assumes weak stationarity, a extra sensible and sensible situation.

Figuring out Stationarity in a Time Sequence

There are completely different strategies for figuring out stationarity in a Time Sequence.

To know these strategies, let’s think about a retail gross sales dataset which we used earlier on this collection for STL Decomposition.

First is Visible Inspection.

Let’s plot this collection

Picture by Creator

From the above plot, we will observe each development and seasonality within the time collection, which signifies that the imply is just not fixed. Due to this fact, we will conclude that this collection is non-stationary.

One other technique to check stationarity is to divide the time collection into two halves and calculate the imply and variance.

If the values are roughly the identical, then the collection is stationary.

For this time collection,

Picture by Creator

The imply is considerably larger, and variance can also be a lot bigger in first half. Because the imply and variance are usually not fixed, this confirms that this time collection is nonstationary.

We are able to additionally determine the stationarity in a time collection through the use of the Autocorrelation (ACF) plot.

ACF plot for this time collection

Picture by Creator

Within the above plot, we will observe that every statement on this time collection is correlated with its earlier values at completely different lags.

As mentioned earlier, autocorrelation regularly decays to zero in a stationary time collection.

However that isn’t the case right here because the autocorrelation is excessive at a number of lags (i.e., the observations are extremely correlated even when they’re farther aside) and it suggests the presence of development and seasonality, which confirms that the collection is non-stationary.

We even have statistical exams to determine stationarity in a time collection.

One is Augmented Dickey Fuller (ADF) Check, and the opposite is Kwiatkowski-Phillips-Schmidt-Shin (“KPSS”) Check.

Let’s see what we get after we apply these exams to the time collection.

Picture by Creator

Each the exams verify that the time collection is non-stationary.

These are the strategies we use to determine stationarity in a time collection,

Remodeling a non-stationary time collection to a Stationary Time Sequence.

We have now a method known as ‘Differencing’ to rework a non-stationary to stationary collection.

On this technique, we subtract every worth from its earlier worth. This fashion we see how a lot they alter from one time to subsequent.

Let’s think about a pattern from retail gross sales dataset after which proceed with differencing.

Picture by Creator

Now we carry out differencing, this we name as first-order differencing.

That is how differencing is utilized throughout the entire time collection to see how the values change over time.

Earlier than first order differencing,

Picture by Creator

After first order differencing

Picture by Creator

Earlier than making use of first-order differencing, we will observe a rising development within the unique time collection together with occasional spikes at common intervals, indicating seasonality.

After differencing, the collection fluctuates round zero, which implies the development has been eliminated.

Nevertheless, for the reason that seasonal spikes are nonetheless current, the following step is to use seasonal differencing.

In seasonal differencing, we subtract the worth from the identical season in earlier cycle.

On this time collection we have now yearly seasonality (12 months), which implies:

For January 1993, we calculate Jan 1993 – Jan 1992.

This fashion we apply seasonal differencing to entire collection.

After seasonal differencing on first order differenced collection, we get

Picture by Creator

We are able to observe that the seasonal spikes are gone and in addition for yr 1992 we get null values as a result of there are not any earlier values to subtract.

After first order differencing and seasonal differencing, the development and seasonality in a time collection are eliminated.

Now we’ll once more take a look at for stationarity utilizing ADF and KPSS exams.

Picture by Creator

We are able to see that the time collection is stationary.


Be aware: Within the ultimate seasonal differenced collection, we nonetheless observe some spikes round 2020-2022 due to pandemic (one-time occasions).

These are known as Interventions. They might not violate stationarity; they’ll have an effect on mannequin accuracy. Strategies like Intervention evaluation can be utilized right here.

We’ll focus on this after we discover ARIMA modeling.


We eliminated the development and seasonality within the time collection to make it stationary utilizing differencing.

Now as an alternative of differencing, we will additionally use STL Decomposition.

Earlier on this collection, we mentioned that when development and seasonal patterns in time collection get messy, we use STL to extract these patterns in a time collection.

So, we will apply STL decomposition on a time collection and extract the residual part which we get after eradicating development and seasonality.

We can even focus on ‘STL + ARIMA’ after we discover the ARIMA forecasting mannequin.


To date, we have now mentioned strategies for figuring out stationarity and for remodeling non-stationary time collection into stationary.

However why do time collection forecasting fashions assume stationarity?

We use time collection forecasting fashions to foretell the longer term based mostly on previous values.

These fashions require a stationary time collection to foretell the longer term as a result of the patterns stay constant over time.

In non-stationary time collection, there’s a fixed change in imply and variance, making the patterns unstable and the predictions unreliable.

Aren’t development and seasonality additionally patterns in a time collection?

Pattern and Seasonality are additionally the patterns in a time collection, however they violate the assumptions of fashions like ARIMA, which require stationary enter.

Pattern and Seasonality are dealt with individually earlier than modelling, and we’ll focus on this in upcoming blogs.

These time collection forecasting fashions are designed to seize short-term dependencies after eradicating international patterns.

What precisely are these short-term dependencies?

When we have now a time collection, we attempt to decompose it utilizing decomposition strategies to know the development, seasonality and residuals in it.

We already know that the development offers us the general path of the info over time (up or down) and seasonality reveals the patterns that repeat at common intervals.

We additionally get residual, which is remaining after we take away development and seasonality from the time collection. This residual is unexplained by development and seasonality.

Pattern offers general path and seasonality reveals patterns that will get repeated all through the collection.

However there could also be some patterns in residual that are momentary in a time collection like a sudden spike in gross sales because of a promotion occasion or a sudden drop in gross sales because of strike or climate circumstances.

What can fashions like ARIMA do with this information?

Do fashions predict future promotional occasions or strikes based mostly on this information? No.

More often than not collection forecasting fashions are utilized in reside manufacturing techniques throughout many industries (Actual-Time).

In real-time forecasting techniques, as new information is available in, the forecasts are constantly up to date to mirror the most recent traits and patterns.

Let’s take a easy instance of cool drinks stock administration.

The shop proprietor is aware of that the cool drinks gross sales is excessive in summer time and low in winter. However that doesn’t assist him in each day stock planning. Right here the brief time period dependencies are crucial.

For instance,

  • there could also be a spike in gross sales throughout festivals and marriage ceremony season for a while.
  • If there’s a sudden temperature spike (warmth wave)
  • A weekend 1+1 provide could improve gross sales
  • Weekend gross sales could also be excessive in comparison with weekdays.
  • When retailer was out of inventory for 2-3 days and the second inventory is again there could also be a sudden burst of gross sales.

These patterns don’t repeat persistently like seasonality, they usually aren’t a part of a long-term development. However they do happen usually that forecasting fashions can be taught from them.

Time collection forecasting fashions don’t predict these future occasions, however they be taught the patterns or habits of the info when such a spike seems.

The mannequin then predicts in accordance with it like a spike in gross sales after a promotional occasion the gross sales could regularly turn out to be regular quite than a sudden drop. The fashions seize these patterns and supply dependable outcomes.

After prediction, the development and seasonality parts are added again to acquire the ultimate forecast.

Because of this the short-term dependencies are crucial in time collection forecasting.


Dataset: This weblog makes use of publicly obtainable information from FRED (Federal Reserve Financial Knowledge). The collection Advance Retail Gross sales: Division Shops (RSDSELD) is revealed by the U.S. Census Bureau and can be utilized for evaluation and publication with acceptable quotation.

Official quotation:
U.S. Census Bureau, Advance Retail Gross sales: Division Shops [RSDSELD], retrieved from FRED, Federal Reserve Financial institution of St. Louis; https://fred.stlouisfed.org/collection/RSDSELD, July 7, 2025.


Be aware:
All of the visualizations and take a look at outcomes proven on this weblog have been generated utilizing Python code.
You may discover the entire code right here: GitHub.

On this weblog, I used Python to carry out statistical exams and, based mostly on the outcomes, decided whether or not the time collection is stationary or non-stationary.

Subsequent up on this collection is an in depth dialogue of the statistical exams (ADF and KPSS exams) used to determine stationarity.

I hope you discovered this weblog intuitive and useful.

I’d love to listen to your ideas or reply any questions.

Thanks for studying!