Onepagecode’s Newsletter

Share this post
Time Series Modelling
onepagecode.substack.com

Time Series Modelling

Everything you need to know about Time Series Modelling

Onepagecode
May 19
Share this post
Time Series Modelling
onepagecode.substack.com

Time-series is simply an ordered collection of data points. Time is usually the independent variable in a time series, and a forecast of the future is typically the goal. When it comes to time series, there are other factors to consider. Describe a time series as follows:

  1. Does it remain stationary?

  2. Seasonality: Does there seem to be any seasonality?

  3. Does the variable have an autocorrelation?

Autocorrelation

As a function of time lag, autocorrelation is the similarity between observations.

An autocorrelation plot is shown above. When you examine the first and 24th values closely, you will find that they have a high level of autocorrelation. Also, the 12th and 36th observations show a high level of correlation. Therefore, a very similar value will be found every 24 seconds.

Seasonality

Periodic fluctuations are known as seasonality. In the evenings, electricity consumption is low and the daytime consumption is high, or online sales peak during Christmas, and then slow down again.

As you can see from the chart above, there is a clear daily seasonal pattern. Each day, the peak occurs in the evening, and the lowest point occurs at the beginning of the day and at the end.

An autocorrelation plot can also be used for determining seasonality if it has a sinusoidal shape, such as the autocorrelation plot shown in the prior example. By looking at the period, you can determine the season’s length.

Stationarity

Time series are characterized by their stationarity. If the statistical properties of a time series do not change over time, it is said to be stationary. The mean and variance are constant, and covariance is independent of time.

The process above is stationary when we look at the same plot again. There is no change in the mean or variance over time.

Our ideal time series for modelling should be stationary. Some of them are stationary, but we can make them stationary by making different transformations.

How to test if a process is a stationarity

Dickey-Fuller’s plot title might have caught your eye. A time series is tested for stationary behaviour by running this statistical test.

It tests whether a unit root is present under the null hypothesis. The process is not stationary if p > 0.

A value of 0 would reject the null hypothesis, and a stationary process would be considered.

The process below, for example, is not stationary. Notice how the mean changes over time.

Modelling time series

Predictions can be made by modelling a time series in many ways. Below are a few examples.

● Average movement

● Exponential smoothing

● ARIMA

Moving average

A common method of modelling time series is the moving-average approach. Moving-average models specify that the next observation will be the average of all the previous observations.

An interesting trend in the data can be identified using the moving average. Applying a moving average model to smooth the time series, and highlighting different trends, requires defining a window.

Our moving average model was applied to a 24h window in the plot above. Using the green line as a smoother, we can see two peaks within 24 hours.

A longer window will ensure a smoother trend. See the example below for a smaller window moving average.

Exponential smoothing

A similar algorithm is used in exponential smoothing, although this time a decreasing weight is assigned to each observation. The more distant we move from the present, the less importance is given to observations.

Exponential smoothing can be expressed mathematically as follows:

The smoothing factor, alpha, here has a range between 0 and 1. It influences how quickly weights decrease.

Dark blue and orange lines show exponential smoothing of the time series respectively, using smoothing factors of 0.3 and 0.05, respectively.

Smoothing increases smoothness as the smoothing factor decreases. We approach the moving average model as the smoothing factor approaches zero.

Double exponential smoothing

Whenever there is a tendency in the time series, double exponential smoothing is applied. This is usually achieved using the exponential smoothing method, which is recursively applied twice.

Mathematics:

It takes values between 0 and 1, and beta is the trend smoothing factor.

The following chart shows how the shape of the time series differs with different alpha and beta values.

Triple exponential smoothing

By introducing a seasonal smoothing factor, we extend double exponential smoothing. Certainly, this is helpful if your time series show seasonality.

Triple exponential smoothing can be expressed mathematically as follows:

Seasonal smoothing factor gamma and length of the season L are equal.

Seasonal autoregressive integrated moving average model (SARIMA)

SARIMA is actually a complex model derived by combining simple models to model time series that exhibit non-stationary properties.

Our first step is to create an autoregression model AR(p). It is basically an internal regression. We assume here that the current value reflects its previous values over a period of time. p is a parameter that indicates the maximum lag. In order to find the

lag at which the majority of lags are not significant, we examine the partial autocorrelation plot.

As shown below, p is 4.

In the next step, we add the moving average model MA(q). In the autocorrelation plot, q is the biggest lag after which the other lags are not significant.

In the following example, q is 4.

Then we add the integration order I(d). In order for a series to be stationary, d must equal 1.

In addition, we add the seasonality component, S(P, D, Q, s), where:

● A season’s length is simply the length of the year.

● For the seasonal component, we use P and Q in the same way as for p and q.

● D is the order of seasonal integration, which measures the number of differences necessary to remove seasonality from a series.

SARIMA(p, d, q)(P, D, Q, s) is the result of combining all these.

As a result, we should use transformations to remove seasonality and nonstationary behaviour from our time series before using SARIMA.

The post was originally posted on my medium blog, I have decided to end my medium blog. So I posted it back here!

Share this post
Time Series Modelling
onepagecode.substack.com
Comments

Create your profile

0 subscriptions will be displayed on your profile (edit)

Skip for now

Only paid subscribers can comment on this post

Already a paid subscriber? Sign in

Check your email

For your security, we need to re-authenticate you.

Click the link we sent to , or click here to sign in.

TopNewCommunity

No posts

Ready for more?

© 2022 Onepagecode
Privacy ∙ Terms ∙ Collection notice
Publish on Substack Get the app
Substack is the home for great writing