Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Time Series Analysis

Time Series AnalysisΒΆ

Reference: πŸ“–Explanation

A time series is simply a series of data points ordered in time. In a time series, time is often the independent variable and the goal is usually to make a forecast for the future.

StationarityΒΆ

Before we start modeling, we should mention such an important property of time series, stationarity.

So why is stationarity so important? Because it is easy to make predictions on a stationary series since we can assume that the future statistical properties will not be different from those currently observed. Most of the time-series models, in one way or the other, try to predict those properties (mean or variance, for example). Furture predictions would be wrong if the original series were not stationary.

When running a linear regression the assumption is that all of the observations are all independent of each other. In a time series, however, we know that observations are time dependent. It turns out that a lot of nice results that hold for independent random variables (law of large numbers and central limit theorem to name a couple) hold for stationary random variables. So by making the data stationary, we can actually apply regression techniques to this time dependent variable.

Dickey-Fuller test can be used as a check for stationarity. If β€˜Test Statistic’ is greater than the β€˜Critical Value’ then the time series is stationary.

There are a few ways to deal with non-stationarity:

Plot the ACF and PACF charts and find the optimal parameters.

ARIMA familyΒΆ

We will explain this model by building up letter by letter. SARIMA(p,d,q)(P,D,Q,s)SARIMA(p, d, q)(P, D, Q, s), Seasonal Autoregression Moving Average model:

Let’s combine our first 4 letters:

AR(p)+MA(q)=ARMA(p,q)AR(p) + MA(q) = ARMA(p, q)

What we have here is the Autoregressive"moving-average model! If the series is stationary, it can be approximated with these 4 letters. Let’s continue.

Adding this letter to the four gives us the ARIMAARIMA model which can handle non-stationary data with the help of nonseasonal differences. Great, one more letter to go!

With this, we have three parameters: (P,D,Q)(P, D, Q)

ProphetΒΆ

πŸ“– Check out this discussion

ARIMA and similar models assume some sort of causal relationship between past values and past errors and future values of the time series. Facebook Prophet doesn’t look for any such causal relationships between past and future. Instead, it simply tries to find the best curve to fit to the data, using a linear or logistic curve, and Fourier coefficients for the seasonal components. There is also a regression component, but that is for external regressors, not for the time series itself (The Prophet model is a special case of GAM - Generalized Additive Model).

MetricsΒΆ

R2=1βˆ’SSresSStotR^2 = 1 - \frac{SS_{res}}{SS_{tot}}

MAE=βˆ‘i=1n∣yiβˆ’y^i∣nMAE = \frac{\sum\limits_{i=1}^{n} |y_i - \hat{y}_i|}{n}

MedAE=median(∣y1βˆ’y^1∣,...,∣ynβˆ’y^n∣)MedAE = median(|y_1 - \hat{y}_1|, ... , |y_n - \hat{y}_n|)

MSE=1nβˆ‘i=1n(yiβˆ’y^i)2MSE = \frac{1}{n}\sum\limits_{i=1}^{n} (y_i - \hat{y}_i)^2

MSLE=1nβˆ‘i=1n(log(1+yi)βˆ’log(1+y^i))2MSLE = \frac{1}{n}\sum\limits_{i=1}^{n} (log(1+y_i) - log(1+\hat{y}_i))^2

MAPE=100nβˆ‘i=1n∣yiβˆ’y^i∣yiMAPE = \frac{100}{n}\sum\limits_{i=1}^{n} \frac{|y_i - \hat{y}_i|}{y_i}

QuestionsΒΆ