SARIMA models

Modelli ARIMA in Python

James Fulton

Climate informatics researcher

The SARIMA model

Seasonal ARIMA = SARIMA

  • Non-seasonal orders
    • p: autoregressive order
    • d: differencing order
    • q: moving average order

SARIMA(p,d,q)(P,D,Q)$_S$

  • Seasonal Orders
    • P: seasonal autoregressive order
    • D: seasonal differencing order
    • Q: seasonal moving average order
    • S: number of time steps per cycle
Modelli ARIMA in Python

The SARIMA model

ARIMA(2,0,1) model : $$y_t = a_1 y_{t-1} + a_2 y_{t-2} + m_1 \epsilon_{t-1} + \epsilon_t$$

SARIMA(0,0,0)(2,0,1)$_7$ model: $$y_t = a_7 y_{t-7} + a_{14} y_{t-14} + m_7 \epsilon_{t-7} + \epsilon_t$$

Modelli ARIMA in Python

Fitting a SARIMA model

# Imports
statsmodels.tsa.statespace.sarimax import SARIMAX

# Instantiate model model = SARIMAX(df, order=(p,d,q), seasonal_order=(P,D,Q,S))
# Fit model results = model.fit()
Modelli ARIMA in Python

Seasonal differencing

Subtract the time series value of one season ago

$$\Delta y_t = y_t - y_{t-S}$$

# Take the seasonal difference
df_diff = df.diff(S)
Modelli ARIMA in Python

Differencing for SARIMA models

Time series

Modelli ARIMA in Python

Differencing for SARIMA models

First difference of time series

Modelli ARIMA in Python

Differencing for SARIMA models

First difference and first seasonal difference of time series

Modelli ARIMA in Python

Finding p and q

Modelli ARIMA in Python

Finding P and Q

Modelli ARIMA in Python

Plotting seasonal ACF and PACF

# Create figure
fig, (ax1, ax2) = plt.subplots(2,1)

# Plot seasonal ACF
plot_acf(df_diff,  lags=[12,24,36,48,60,72], ax=ax1)

# Plot seasonal PACF
plot_pacf(df_diff, lags=[12,24,36,48,60,72], ax=ax2)

plt.show()
Modelli ARIMA in Python

Let's practice!

Modelli ARIMA in Python

Preparing Video For Download...