Time Series Analysis & Forecasting in Simple Words
By: Skye Tran
Tags: Forecasting, Data, Time Series Analysis, Analytics

The picture above showed another type of data that could easily be mistaken for time series data. Here, we have the daily expenses of Aria and Lily between 17 May and 23 May. The left side represents the narrow (a.k.a. unstacked) form while the right side illustrates the wide (a.k.a. stacked) form.

Both stacked and unstacked forms represent panel data, which consists of observations about multiple cases at multiple points in time. The key point to remember here is that in panel data, we have more than one case. So do remember to check which case you want to examine further with time series analysis. You might either need to filter data to remove irrelevant cases or summarise the data for a more aggregated view.

Ten-second takeaway: Is your data already in time-series format or do you need to transform it to a more usable form?

What is stationarity and why does it matter?

Remember we said earlier that one of the goals of time series analysis is to predict or estimate the future value of a time series variable (let say a variable Y)?

But what can be a good estimator of the future value of Y? Well, we have so many options. One of the easiest and simplest options is to use the mean (a.k.a. average).

However, for this approach to be valid, we must assume that over time the future value of a time series variable converges on a single value, which is the mean of Y. This brings us to the idea of stationarity, which encompasses the following 2 points.

The mean and variance of Y have to stay the same over time. Any fluctuation in Y value occurs randomly. The rise and fall of Y don’t relate to time.

Only when the time series of Y is stationary, we can then estimate the future value of Y based on the mean of Y that we calculated from known observations as of today.

What if the time series is not stationary? We can either apply transformation (e.g. difference or logarithmic transform) to convert it into a stationary time series or opt for other approaches that are more suitable for a nonstationary dataset.

Ten-second takeaway: Before deciding on how to best estimate the future value of time series, have you checked whether the time series data is stationary or not?

What makes a time series nonstationary?

Now comes the tricky part! There is only one way for time series to be stationary. But there are so many ways for time series to be non-stationary.

Here, we’ll explore the 3 most common reasons including trending, periodicity and structural breaks. But do keep in mind these aren’t the only factors resulting in non-stationarity.

Trending

Cumulative number of confirmed COVID-19 cases in Japan (Image by Author, Data Source: GCP Public Dataset)

Trending means the time series exhibits an upward or downward movement over a long period. Following this trend, the mean of the time series also keeps increasing or decreasing in the long term. Thus the time series is no longer stationary and the mean is not a good estimator for future value.

As shown above, the easiest way to spot trending is to use a time-series plot (a.k.a. line plot, time-series graph). One axis represents time while the other axis shows the numeric values.

However, sometimes, within the short term (e.g. between 31 Dec 2019 to 9 Mar 2020), the general trend might not be evident. Therefore, it can be easily mistaken for a stationary time series. To recognise the general trend of time series, it is recommended to observe time series plot over a longer period such as multiple years.

Periodicity

Iowa’s Alcoholic Beverages Division Daily Sales of Tito’s Handmade Vodka in April 2021 (Image by Author, Data Source: GCP Public Dataset)

Periodicity means the ups and downs follow a cycle and are repetitive over time. In the picture above, it’s not difficult to guess because the wholesale stores under Iowa’s Alcoholic Beverages Division close every Saturday and Sunday. Therefore daily sales are zero during weekends.

If those rises and falls align with the calendar (e.g. month, quarter, season, public holidays etc.), then periodicity has another name, which is seasonality. For instance, retail sales revenue often rises during the Christmas period while temperature usually dips below zero during winter in Canada.

With periodicity, the mean of the time series changes in tandem with time or season. Thus, an easy way to detect seasonality is to observe the line plot to spot peaks and troughs that are regularly spaced and follow approximately the same direction as well as magnitude every year. Another way is to create multiple box plots to visually compare mean value across different months or quarters.

Structural Breaks (a.k.a. Equilibrium Shifts)

Short-term visitor arrivals to Australia decreased by 97.5% in 2020 due to the pandemic and the resulting border closure (Image by Author, Data Source: Australian Bureau of Statistics)

While trending and periodicity exhibit somewhat systematic and predictable changes, structural breaks reflect abrupt changes at a point in time. For example, when Australia closed its border last year due to COVID-19, the short-term visitor arrivals to Australia plummetted by 97.5%.

No doubt the mean of the time series also shifted to a new level. This also suggests that the mean value based on past observations is no longer a good estimator for the future. Whenever this happens, it’s time to revise the model to account for the underlying shift and the related factors.

Ten-second takeaway: Does plotting your time series data reveal any trends, periodicity or structural breaks? If not, have you conducted the Augmented Dickey-Fuller test or KPSS test to check for stationarity?

What are the common approaches for univariate time series analysis?

There are many ways to predict future values of time series analysis. Supervised machine learning methods are often used when the time series has more than one variable collected over time. This is also known as multivariate time series. But let’s save this for another day.

For univariate time series analysis, only one single observation is collected over time. For example, scientists have been measuring CO 2 in the atmosphere at Mauna Loa Observatory in Hawaii since 1974 for research purpose.

When the time series data only consists of one single column of numbers against time, the simplicity of classical time series methods could truly be a blessing. Therefore, many classical time series forecasting methods could be great alternatives to machine learning methods for univariate time series analysis.

Here, I will briefly introduce the logic behind 3 classical time series forecasting methods. Just in case you want to know more about other classical methods, here is a short and sweet article to explore.

Moving Average (MA) Model