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.

We will discuss ARIMA models, seasonal ARMA models, multiplicative seasonal ARMA models and SARIMA models.

ARIMA models

We continue with the GDP dataset from the last few lectures (US GDP from FRED, https://fred.stlouisfed.org/series/GDP, in billions of dollars, quarterly, seasonally adjusted, not adjusted for inflation). As before, we work with the logarithms of the data, and we split the data into training and test sets with the last 50 quarters as the test set.

  observation_date      GDP
0       1947-01-01  243.164
1       1947-04-01  245.968
2       1947-07-01  249.585
3       1947-10-01  259.745
4       1948-01-01  265.742
<Figure size 1000x400 with 1 Axes>

We will apply the ARIMA(pp, dd, qq) model for this data with d=1d = 1. This means that ARMA(pp, qq) model is used for the differenced data yt−yt−1y_t - y_{t-1}. Why is it sensible to work with differences for the log GDP data?

Why difference log GDP? The models we have already fit suggest it. Every AR model that we fit to log GDP had a root of the AR polynomial at (or extremely close to) 1: AR(1) gave ϕ^1=0.9984\hat{\phi}_1 = 0.9984, AR(4) had a root of modulus 1.0016, and ARMA(1, 2) gave ϕ^1=0.998\hat{\phi}_1 = 0.998 and needed the option enforce_stationarity = False.

To see what this means, take the AR(1) model yt=ϕ0+ϕ1yt−1+ϵty_t = \phi_0 + \phi_1 y_{t-1} + \epsilon_t. When ∣ϕ1∣<1|\phi_1| < 1, the series is pulled back toward a fixed mean level after every shock. When ϕ1=1\phi_1 = 1, there is no such pull, and the model becomes

yt−yt−1=ϕ0+ϵt.y_t - y_{t-1} = \phi_0 + \epsilon_t.

So the fitted AR(1) with ϕ^1≈1\hat{\phi}_1 \approx 1 is really saying that the differences ∇yt=yt−yt−1\nabla y_t = y_t - y_{t-1} of log GDP are simple (a constant plus noise), while log GDP itself just accumulates these differences. The same holds for higher orders: if the AR polynomial has a root at 1, then it factors as ϕ(z)=(1−z)ψ(z)\phi(z) = (1 - z)\psi(z), and the model ϕ(B)yt=ϵt\phi(B) y_t = \epsilon_t can be rewritten as ψ(B)∇yt=ϵt\psi(B) \nabla y_t = \epsilon_t, which is an AR model of one lower order for the differences. In other words, our fits are telling us to model ∇yt\nabla y_t instead of yty_t.

The simplest example is the random walk yt=yt−1+ϵty_t = y_{t-1} + \epsilon_t, whose differences ∇yt=ϵt\nabla y_t = \epsilon_t are white noise. Below is a simulated random walk together with its sample ACF, and the sample ACF of its differences. The sample ACF of the random walk decays very slowly, which looks like strong and complicated dependence, yet after differencing nothing is left but white noise. We shall see subsequently that the sample ACF of the log-GDP series has a similar structure.

<Figure size 1400x350 with 3 Axes>

The sample ACF of log GDP has exactly this slowly decaying shape, as can be seen below.

<Figure size 800x350 with 1 Axes>
Sample ACF of log GDP at lags 1, 2, 3, 10, 20: [0.991 0.981 0.971 0.904 0.806]

We therefore work with the differences of log GDP: ∇log⁡yt=log⁡yt−log⁡yt−1\nabla \log y_t = \log y_t - \log y_{t-1}. Note that these differences are the quarterly growth rates of GDP. One can check that the differenced series fluctuates around a fixed level (about 0.016, i.e., 1.6% growth per quarter), and its sample ACF decays quickly.

Mean quarterly growth rate in the training data: 0.0159
<Figure size 1000x350 with 1 Axes>

We will fit an AR or MA or ARMA model to the growth rates.

Below are the sample ACF and the sample PACF of the growth rates. The sample PACF at lag hh is ϕ^h,h\hat{\phi}_{h,h}, the coefficient of the last lag when an AR(hh) model is fit to the data; this is the plot that we used in Lecture 19 to choose the AR order (the option method = 'ols' computes ϕ^h,h\hat{\phi}_{h, h} by least squares, as in Lecture 19).

<Figure size 1200x350 with 2 Axes>
Sample ACF  at lags 1-6: [ 0.49   0.369  0.128  0.051 -0.07   0.024]
Sample PACF at lags 1-6: [ 0.493  0.17  -0.147 -0.022 -0.083  0.135]

The sample PACF cuts off after lag 2 or 3. This is the signature of an AR(2) or AR(3) model for the growth rates, i.e., of ARIMA(2, 1, 0) or ARIMA(3, 1, 0) for log GDP.

Fitting ARIMA(pp, 1, qq) with the ARIMA function

ARIMA(p,d,qp, d, q) models are fit by ARIMA(y, order = (p, d, q)). With d=1d = 1, the function fits an ARMA(p,qp, q) model to the first differences of y, and its forecasts are forecasts of y itself (the differencing is undone automatically). One important detail: when d≥1d \geq 1, the ARIMA function does not include a constant by default (we noticed this for the varve data in the last lecture). The growth rates of GDP have a clearly nonzero mean (1.6% per quarter), so we must include the constant. This is done with the option trend = 't' (a constant in the differenced series is the same thing as a linear trend in the original series, hence the letter t).

We first fit ARIMA(3, 1, 0), which is the model suggested by the ACF/PACF plots.

                               SARIMAX Results                                
==============================================================================
Dep. Variable:                      y   No. Observations:                  269
Model:                 ARIMA(3, 1, 0)   Log Likelihood                 869.099
Date:                Wed, 11 Nov 2026   AIC                          -1728.198
Time:                        20:04:47   BIC                          -1710.243
Sample:                             0   HQIC                         -1720.986
                                - 269                                         
Covariance Type:                  opg                                         
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
x1             0.0158      0.001     12.847      0.000       0.013       0.018
ar.L1          0.4344      0.051      8.476      0.000       0.334       0.535
ar.L2          0.2303      0.053      4.352      0.000       0.127       0.334
ar.L3         -0.1499      0.047     -3.186      0.001      -0.242      -0.058
sigma2      8.912e-05   5.29e-06     16.844      0.000    7.87e-05    9.95e-05
===================================================================================
Ljung-Box (L1) (Q):                   0.00   Jarque-Bera (JB):                76.56
Prob(Q):                              0.96   Prob(JB):                         0.00
Heteroskedasticity (H):               0.31   Skew:                             0.44
Prob(H) (two-sided):                  0.00   Kurtosis:                         5.47
===================================================================================

Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).

The coefficients ar.L1, ar.L2, ar.L3 are ϕ1,ϕ2,ϕ3\phi_1, \phi_2, \phi_3 and sigma2 is σ2\sigma^2. The coefficient labeled x1 (0.0158) is the mean μ\mu of the growth rates: as mentioned in the notes, the ARIMA function always parametrizes the constant as the mean μ\mu of the (differenced) series rather than as the intercept ϕ0\phi_0 of the AR equation. The two are related by ϕ0=μ(1−ϕ1−ϕ2−ϕ3)\phi_0 = \mu (1 - \phi_1 - \phi_2 - \phi_3). One can check, as follows, that the fitted ARMA model is stable (by looking at the moduli of the roots of the AR polynomial); so the predictions eventually approach μ^\hat{\mu}.

Estimated mean growth rate per quarter (x1): 0.0158
Sample mean of the growth rates:             0.0159
Implied intercept phi_0 = mu (1 - phi_1 - phi_2 - phi_3): 0.0077
Moduli of the AR roots: [1.883 1.882 1.882]

To choose pp and qq, we can use go over all values of p,qp, q in a given range and then find the model for which the AIC or BIC is the smallest.

Choosing pp and qq by AIC/BIC (with d=1d = 1 fixed)

We now fit all ARIMA(pp, 1, qq) models with p,q≤3p, q \leq 3 (all with the constant) and compare their AIC and BIC values. Note that dd is held fixed at 1 throughout: AIC/BIC values are only comparable across models fit to the same data (see the notes).

Models sorted by AIC (best first):
 p  d  q          AIC          BIC
 3  1  0 -1728.197800 -1710.242865
 1  1  2 -1727.057695 -1709.102760
 3  1  1 -1725.972831 -1704.426909
 2  1  1 -1725.528846 -1707.573911
 0  1  3 -1725.389785 -1707.434850
 1  1  3 -1725.366501 -1703.820580

Models sorted by BIC (best first):
 p  d  q          AIC          BIC
 3  1  0 -1728.197800 -1710.242865
 2  1  0 -1724.270559 -1709.906611
 1  1  2 -1727.057695 -1709.102760
 1  1  0 -1718.502329 -1707.729368
 2  1  1 -1725.528846 -1707.573911
 0  1  3 -1725.389785 -1707.434850

Both AIC and BIC pick ARIMA(3, 1, 0), with ARIMA(2, 1, 0) a close second by BIC and ARIMA(1, 1, 2) a close second by AIC. The models near the top of both lists have similar forecasts, so the choice among them is not critical. We go with ARIMA(3, 1, 0).

Why AIC/BIC cannot be used to choose dd. The log-likelihood of an ARIMA model with d=1d = 1 is the log-likelihood of the differenced data. The following check shows this: fitting ARIMA(0, 1, 2) with a constant to log GDP gives exactly the same log-likelihood as fitting MA(2) with a constant to the differenced log GDP.

Log-likelihood of ARIMA(0, 1, 2) fit to log GDP:         864.644  (number of observations: 269 )
Log-likelihood of MA(2) fit to the differenced log GDP:  864.644  (number of observations: 268 )

A model with d=0d = 0, on the other hand, has the log-likelihood of the undifferenced data (e.g., the ARMA(1, 2) model of the last lecture had log-likelihood 861.0 for the 269 values of log GDP). Likelihoods of different datasets are not comparable, and hence neither are their AIC or BIC values. In the last lecture’s notebook, we looped over d=0,1,2d = 0, 1, 2 as well as pp and qq; the comparisons across different values of dd in that loop should be taken with a grain of salt, while the comparisons for a fixed dd are fine. The value of dd should be chosen by looking at the data, as we did above.

Checking the residuals

If the model is adequate, the residuals should look like i.i.d noise. We plot the residuals and their sample ACF. For these models, the first few residuals are not well-defined. For example, for AR(pp) the residuals are yt−ϕ^0−∑j=1pϕ^jyt−jy_t - \hat{\phi}_0 - \sum_{j=1}^p \hat{\phi}_j y_{t-j}, which requires yt−1,…,yt−py_{t-1}, \dots, y_{t-p} and so is only defined for t>pt > p. The .resid attribute nevertheless returns a value for every tt, but the initial values are not meaningful as residuals in this sense. We therefore drop the first few residuals before plotting.

269 269
<Figure size 1200x350 with 2 Axes>

The residual ACF has no large autocorrelations. A few values (at lag 5 and near lags 9-11, i.e., around two and a half years) sit at the edge of the band; the ones near lags 9-11 were already visible in the ACF of the growth rates. A low-order ARIMA model cannot capture these and we accept the model.

Forecasting with ARIMA

The get_prediction method gives the forecasts (of log GDP itself, not of the differences), their standard errors, and prediction intervals.

<Figure size 1100x500 with 1 Axes>
Test MSE (log scale) of ARIMA(3, 1, 0) with drift: 0.00980999805728587

The forecast is a straight line (with slope equal to the estimated drift, 1.58% per quarter) plus a short-run adjustment in the first few quarters, and the prediction intervals keep widening with the horizon.

Let us compare with the AR(4) model (fit to the log-GDP data directly, and not to the differences) from Lecture 19. We compute the test MSE over the whole test period and also over the first 4 and first 8 quarters of the test period.

                       Model  MSE first 4 quarters  MSE first 8 quarters  MSE all 50 quarters
   ARIMA(3, 1, 0) with drift              0.000106              0.000304             0.009810
AR(4) in levels (Lecture 19)              0.000207              0.000150             0.001558

Average growth rate per quarter: training data 0.0159 ; test period 0.013

The ARIMA forecasts are better for the first few quarters but worse over the whole 50-quarter test period. The reason is the drift: the long-range ARIMA forecast grows at the average growth rate of the training period (1947-2013), which is 1.6% per quarter, while GDP actually grew at 1.3% per quarter during the test period (2014-2026), so the ARIMA forecasts overshoot. The AR(4) model in levels (whose root of modulus 1.0016 makes it essentially an ARIMA(3, 1, 0) model in disguise) extrapolated a lower growth rate and happened to land closer. The lesson: for a trending series, the orders pp and qq matter for short-range forecasts, while long-range forecasts are dominated by the assumed trend, which no choice of pp and qq can fix.

Seasonal ARIMA models

The CO2CO_2 data

The following data is the monthly mean atmospheric CO2CO_2 concentration (in parts per million) measured at the Mauna Loa Observatory in Hawaii, from March 1958 to September 2026 (823 months). The data is collected by NOAA (https://gml.noaa.gov/ccgg/trends/data.html). The data has a clear upward trend and a clear seasonal pattern: CO2CO_2 rises during the winter and falls during the summer (when plants in the Northern Hemisphere absorb CO2CO_2). We hold out the last 36 months (3 years) as test data.

      Date     CO2  CO2_deseasonalized
0  1958-03  315.71              314.44
1  1958-04  317.45              315.16
2  1958-05  317.51              314.69
3  1958-06  317.27              315.15
4  1958-07  315.87              315.20
<Figure size 1400x400 with 2 Axes>

Seasonal and ordinary differencing

The sample ACF of the raw series decays very slowly (as for log GDP), so differencing is needed. The two options are yt−yt−1y_t - y_{t-1} and yt−yt−12y_t - y_{t-12}. Let us first look at the first differences ∇yt=yt−yt−1\nabla y_t = y_t - y_{t-1} (the month-to-month changes).

<Figure size 1400x350 with 2 Axes>
Sample ACF of the first differences at lags 12, 24, 36, 48: [0.923 0.91  0.892 0.876]

The month-to-month changes still have a strong seasonal pattern that repeats every year: the sample ACF has large spikes at lags 12, 24, 36, 48 (0.92, 0.91, 0.89, 0.88) which decay very slowly.

Next we look at the seasonal differences yt−yt−12y_t - y_{t-12}. The seasonal difference yt−yt−12y_t - y_{t-12} is the change from the same month of the previous year (the annual increase in CO2_2).

<Figure size 1400x350 with 2 Axes>

The seasonal pattern is gone. But the annual increase wanders: it was below 1 ppm per year in the 1960s and is about 2.5 ppm per year now, and its sample ACF decays slowly. So we also take an ordinary difference, i.e., d=1d = 1. The series ∇∇12yt=yt−yt−1−yt−12+yt−13\nabla \nabla_{12} y_t = y_t - y_{t-1} - y_{t-12} + y_{t-13} fluctuates around zero with no trend and no seasonal pattern.

<Figure size 1600x350 with 3 Axes>
Sample ACF  at lags 1, 2, 3, 11, 12, 13, 24, 36: [-0.291 -0.033 -0.065  0.191 -0.47   0.066 -0.003  0.012]
Sample PACF at lags 1, 2, 3, 11, 12, 13, 24, 36: [-0.291 -0.128 -0.126  0.237 -0.4   -0.212 -0.272 -0.192]

Choosing p,q,P,Qp, q, P, Q by AIC/BIC (with d=D=1d = D = 1 fixed)

We now fit all models with p,q∈{0,1,2}p, q \in \{0, 1, 2\} and P,Q∈{0,1}P, Q \in \{0, 1\}, keeping d=D=1d = D = 1 fixed, and compare their AIC and BIC values (36 models; this takes a few seconds).

Models sorted by AIC (best first):
 p  d  q  P  D  Q        AIC        BIC
 1  1  1  0  1  1 424.674489 443.280776
 2  1  1  0  1  1 425.552427 448.810287
 1  1  2  0  1  1 425.888984 449.146844
 0  1  2  0  1  1 426.244975 444.851263
 1  1  1  1  1  1 426.672866 449.930726
 2  1  2  0  1  1 426.917381 454.826812

Models sorted by BIC (best first):
 p  d  q  P  D  Q        AIC        BIC
 0  1  1  0  1  1 428.564773 442.519489
 1  1  1  0  1  1 424.674489 443.280776
 0  1  2  0  1  1 426.244975 444.851263
 2  1  1  0  1  1 425.552427 448.810287
 1  1  2  0  1  1 425.888984 449.146844
 0  1  1  1  1  1 430.562768 449.169055

BIC picks the model ARIMA(0, 1, 1)×\times(0, 1, 1)12_{12} while AIC picks ARIMA(1, 1, 1)×\times(0, 1, 1)12_{12}, which has one extra AR coefficient. We fit both these models to the observed data as follows.

                                    SARIMAX Results                                     
========================================================================================
Dep. Variable:                                y   No. Observations:                  787
Model:             ARIMA(0, 1, 1)x(0, 1, 1, 12)   Log Likelihood                -211.282
Date:                          Wed, 11 Nov 2026   AIC                            428.565
Time:                                  21:22:10   BIC                            442.519
Sample:                                       0   HQIC                           433.934
                                          - 787                                         
Covariance Type:                            opg                                         
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
ma.L1         -0.3842      0.032    -12.037      0.000      -0.447      -0.322
ma.S.L12      -0.8648      0.020    -42.761      0.000      -0.904      -0.825
sigma2         0.0989      0.005     21.501      0.000       0.090       0.108
===================================================================================
Ljung-Box (L1) (Q):                   0.36   Jarque-Bera (JB):                 6.11
Prob(Q):                              0.55   Prob(JB):                         0.05
Heteroskedasticity (H):               1.22   Skew:                            -0.07
Prob(H) (two-sided):                  0.12   Kurtosis:                         3.41
===================================================================================

Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
                                    SARIMAX Results                                     
========================================================================================
Dep. Variable:                                y   No. Observations:                  787
Model:             ARIMA(1, 1, 1)x(0, 1, 1, 12)   Log Likelihood                -208.337
Date:                          Wed, 11 Nov 2026   AIC                            424.674
Time:                                  21:22:10   BIC                            443.281
Sample:                                       0   HQIC                           431.833
                                          - 787                                         
Covariance Type:                            opg                                         
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
ar.L1          0.2354      0.080      2.925      0.003       0.078       0.393
ma.L1         -0.5912      0.067     -8.869      0.000      -0.722      -0.461
ma.S.L12      -0.8645      0.020    -43.293      0.000      -0.904      -0.825
sigma2         0.0982      0.005     21.659      0.000       0.089       0.107
===================================================================================
Ljung-Box (L1) (Q):                   0.19   Jarque-Bera (JB):                 6.84
Prob(Q):                              0.66   Prob(JB):                         0.03
Heteroskedasticity (H):               1.20   Skew:                            -0.03
Prob(H) (two-sided):                  0.15   Kurtosis:                         3.46
===================================================================================

Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).

Next we obtain forecasts using these two models.

<Figure size 1500x500 with 2 Axes>

Let us check the residuals corresponding to the fitted models. Again, the initial residuals are not meaningful so we will drop them. Specifically, with d=1d = 1 and D=1D = 1, the first 1+12=131 + 12 = 13 residuals are not meaningful (the corresponding observations cannot be predicted from the past) and we drop them.

<Figure size 1400x350 with 2 Axes>

Airline passengers dataset

We repeat the prediction analysis for the airline passengers dataset. This is a popular dataset for evaluating prediction accuracy of various models. It contains monthly data on the number of international airline passengers (in thousands) from January 1949 to December 1960.

          time  value
0  1949.000000    112
1  1949.083333    118
2  1949.166667    132
3  1949.250000    129
4  1949.333333    121
<Figure size 640x480 with 1 Axes>

As usual, we fit models to logarithms.

<Figure size 640x480 with 1 Axes>

We fit models to the double differences ∇∇12yt\nabla \nabla_{12} y_t.

<Figure size 640x480 with 1 Axes>

We now search over a bunch of p,q,P,Qp, q, P, Q values to find the best model via AIC/BIC.

Models sorted by AIC (best first):
 p  d  q  P  D  Q         AIC         BIC
 0  1  1  0  1  1 -483.392918 -474.767326
 2  1  1  0  1  1 -482.260604 -467.884617
 0  1  1  1  1  1 -481.906210 -470.405420
 1  1  1  0  1  1 -481.892939 -470.392150
 0  1  2  0  1  1 -481.610058 -470.109269
 1  1  0  0  1  1 -481.483823 -472.858231

Models sorted by BIC (best first):
 p  d  q  P  D  Q         AIC         BIC
 0  1  1  0  1  1 -483.392918 -474.767326
 1  1  0  0  1  1 -481.483823 -472.858231
 0  1  1  1  1  1 -481.906210 -470.405420
 1  1  1  0  1  1 -481.892939 -470.392150
 0  1  2  0  1  1 -481.610058 -470.109269
 0  1  1  1  1  0 -477.398538 -468.772946

The best model, according to both AIC and BIC, is ARIMA(0,1,1)×(0,1,1)12(0, 1, 1) \times (0, 1, 1)_{12}.

                                    SARIMAX Results                                     
========================================================================================
Dep. Variable:                                y   No. Observations:                  144
Model:             ARIMA(0, 1, 1)x(0, 1, 1, 12)   Log Likelihood                 244.696
Date:                          Wed, 11 Nov 2026   AIC                           -483.393
Time:                                  21:30:23   BIC                           -474.767
Sample:                                       0   HQIC                          -479.888
                                          - 144                                         
Covariance Type:                            opg                                         
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
ma.L1         -0.4017      0.073     -5.505      0.000      -0.545      -0.259
ma.S.L12      -0.5572      0.096     -5.791      0.000      -0.746      -0.369
sigma2         0.0013      0.000      9.127      0.000       0.001       0.002
===================================================================================
Ljung-Box (L1) (Q):                   0.04   Jarque-Bera (JB):                 1.90
Prob(Q):                              0.84   Prob(JB):                         0.39
Heteroskedasticity (H):               0.58   Skew:                             0.02
Prob(H) (two-sided):                  0.08   Kurtosis:                         3.59
===================================================================================

Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).

Future predictions by this SARIMA model are obtained as follows.

<Figure size 1200x500 with 1 Axes>