1
$\begingroup$

I'm trying to understand the ARIMA process by generating a sequence manually, then fitting an ARIMA model from statsmodel.tsa to check my results I've found an example there (not in english but doesn't matter): https://www.math.u-bordeaux.fr/~hzhang/m2/st/sas_tp_ind/node13.html

I have two problems:

  1. the plot I draw doesn't look at all like the plot they draw.
  2. the ar an ma parameters found by the statsmodel ARIMA implementation are not the one I expect (which may or may not due to problem #1)

Could someone please explain me what is wrong with my implementation and/or understanding of how to generate an ARIMA series in simple terms as my maths skills are somewhat limited.

import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.arima_model import ARIMA

# arima(1, 1, 1) with alpha1 = -2/3 and beta1 = 5/6
# (1 - 2/3 . B)(1 - B)Xt = Wt + 5/6 . Wt-1
# on canonical form:
# (1 - 2/3 B)(Xt - Xt-1) = Wt + 5/6 . Wt-1
# Xt - Xt-1 - 2/3 . Xt-1 + 2/3 . Xt-2 = Wt + 5/6 . Wt-1
# Xt = 5/3 . Xt-1 -2/3 . Xt-2 + Wt + 5/6 . Wt-1
# we now have an ARMA model with parameters alpha1 = 5/3, alpha2 = -2/3 and beta1 = 5/6

alpha1 = 5/3
alpha2 = -2/3
beta1 = 5/6
sigma = 0.2


w = np.random.rand(10000) * sigma
x = w.copy()

for t in range(2, len(w)):
    x[t] = alpha1 * x[t-1] + alpha2 * x[t-2] + w[t] + beta1 * w[t-1]


model = ARIMA(x, order=(1,1,1))
model_fit = model.fit(disp=0, trend='nc')
print(model_fit.summary())

plt.plot(x)

reference ARIMA(1, 1, 1)

my results incorrect

$\endgroup$

1 Answer 1

1
$\begingroup$

The main issue here is that you are using np.random.rand, which draws from a uniform distribution over [0, 1), whereas you should be using np.random.normal to draw from a Gaussian distribution. This means that your error term is always positive, and your time series only increases.

A second issue is that you are not including the intercept. I think you should have:

    x[t] = 0.1 + alpha1 * x[t-1] + alpha2 * x[t-2] + w[t] + beta1 * w[t-1]

A third issue is that the comparison code discards the first 50 draws (this mainly affects the starting point of the graph, not the overall look).

Also, you are drawing many more draws, which will tend to make the graph look different than the one you are comparing to.


NB: In recent updates to Statsmodels (not yet in a released version, but available on Github), you can simulate this model directly, as follows:

empty_dataset = np.zeros(150)
mod = sm.tsa.SARIMAX(empty_dataset, order=(2, 0, 1), trend='c', initialization='diffuse')
simulations = mod.simulate([0.1, 5/3, -2/3, 5/6, 0.2**2], 150)[50:]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.