Search code examples
pythonstatsmodelsarima

Model equation out from ARIMA result


I'm using ARIMA from statsmodels for time series analysis. Now I stumbled across the following site

In this example an ARIMA(3,1,0) model was built with the following result thru ARIMA.fit():

          coef
ar.L1   -0.5353
ar.L2   -0.3974
ar.L3   -0.3856

The model equation will be:

Δy_t = −0.5232y_(t−1) − 0.3836y_(t−2) − 0.3758y_(t−3) + w_t,

Any ideas where the values of the AR-coefficients for the lagged variables in the model equation come from? Or I am not seeing the wood for the trees. I thought that the AR-coefficients can be directly seen in the result object of ARIMA.fit().

Edit: I know that the coefficient values can be directly accessed via params dictionary. The problem I struggle with are the concrete values used in the model equation. They simply differ from the values in params dictionary, e.g. params: ar1 = -0.5353 and equation: ar1 = -0.5232.

Thanks in advance!


Solution

  • The answer should be in cells 20 and 21 on the linked site.

    In the summary you see all coefficients, together with their standard error and more:

    from statsmodels.tsa.arima.model import ARIMA
    
    model = ARIMA(data, order=(3, 1, 0))
    model_fit = model.fit()
    print(model_fit.summary())
    

    You can directly access the parameters via the params dictionary. So to define the function given above manually, you could use

    import math
    
    ar1 = model_fit.params["ar.L1"]
    ar2 = model_fit.params["ar.L2"]
    ar3 = model_fit.params["ar.L3"]
    sigma2 = model_fit.params["ar.sigma2"]
    
    def calc_delta_y(y, t=0):
       """delta_y calculated from this specific ARIMA model"""
       return ar1*y[t-1] + ar2*y[t-2] + ar3*y[t-3] + math.sqrt(sigma2) 
    

    I guess you were not seeing the wood for the trees, but I also know you are not the first to search for those parameters.