Skip to content

FAQ/Design comparison ARMA, SARIMAX #2542

Closed

Description

@josef-pkt

What are the intentional differences in the API of ARMA and SARIMAX?
What are design inconsistencies that should be refactored and removed?

related models for special case AR and GLSAR with other differences.

treatment of constant and trend

stationary constant or regression constant?

ARMA still has trend in fit see #1049
SARIMAX doesn't allow trend='nc' ?
SARIMAX allows constant in exog and reports regression constant in that case

treatment of exog

no differences ?
ARMA does not allow constant in exog, constant only via trend

default assumptions

???
stationarity? imposed or optional?

results

SARIMAX includes variance (sigma2) in params (intentional)
ARMA concentrates out the scale?

Activity

  1. added this to the 0.8 milestone on Jul 16, 2015
  2. josef-pkt commented on Jul 16, 2015

    @josef-pkt
    MemberAuthor

    using pandas, names differ and cannot be correctly concatenated
    using example from examples\incomplete\glsar.py

    res_arma_pd = sm.tsa.ARIMA(y1, order=(3,0,0), exog=pd.DataFrame(X1[:,0], index=dti)).fit(trend='c', method='mle')
    res_sarma_pd = sm.tsa.SARIMAX(pd.Series(y1, index=dti), order=(3,0,0), exog=pd.DataFrame(X1[:,0], index=dti), trend=1).fit()
    
    >>> pd.concat((res_arma_pd.params, res_sarma_pd.params), axis=1)
                      0         1
    0          0.100039  0.100011
    ar.L1           NaN  0.507834
    ar.L1.y    0.493022       NaN
    ar.L2           NaN  0.188534
    ar.L2.y    0.206262       NaN
    ar.L3           NaN  0.014555
    ar.L3.y   -0.000710       NaN
    const      1.967656       NaN
    intercept       NaN  0.575110
    sigma2          NaN  0.247314
    >>> res_arma_pd.params
    const      1.967656
    0          0.100039
    ar.L1.y    0.493022
    ar.L2.y    0.206262
    ar.L3.y   -0.000710
    dtype: float64
    >>> res_sarma_pd.params
    intercept    0.575110
    0            0.100011
    ar.L1        0.507834
    ar.L2        0.188534
    ar.L3        0.014555
    sigma2       0.247314
    dtype: float64
    
  3. ChadFulton commented on Jul 16, 2015

    @ChadFulton
    Member

    SARIMAX doesn't allow trend='nc' ?

    I guess it's called trend='n' for no trend; I think this must have been because in ARIMA, the choice is a constant trend or no trend, whereas in SARIMAX it is between no trend 'n', constant / intercept 'c', linear 't', linear + intercept 'ct', and generic (e.g. trend=(1,0,1) for a constant and a quadratic, but not a linear). It could easily be renamed to trend=nc to denote no trend.

    SARIMAX allows constant in exog and reports regression constant in that case

    We can eliminate this behavior, but again we'd have to choose how much to check for, since the trend is arbitrary (i.e. do we just check for constant in exog? or constant and linear trend? or constant, linear and quadratic? or ...)

    stationarity? imposed or optional?

    In SARIMAX, stationarity (of the autoregressive lag polynomial) and invertibility (of the moving average lag polynomial) are controlled via keyword args enforce_stationarity and enforce_invertibility.

  4. ChadFulton commented on Jul 16, 2015

    @ChadFulton
    Member

    using pandas, names differ and cannot be correctly concatenated

    I don't see any reason why I couldn't change SARIMAX to be consistent with ARMA on the parameter names.

  5. ChadFulton commented on Jul 16, 2015

    @ChadFulton
    Member

    Although of course const in ARIMA and intercept in SARIMAX have different meanings, so maybe shouldn't have the same name.

  6. ChadFulton commented on Jul 16, 2015

    @ChadFulton
    Member

    SARIMAX allows constant in exog and reports regression constant in that case

    We can eliminate this behavior, but again we'd have to choose how much to check for, since the trend is arbitrary (i.e. do we just check for constant in exog? or constant and linear trend? or constant, linear and quadratic? or ...)

    Actually, there is another reason not to eliminate the ability to have constant regressors (although there's still a case for checking that both aren't specified), but I should document it more explicitly somewhere. It's related to the above point about const in ARIMA and intercept in SARIMAX.

    Without exogenous regressors, the SARIMA model is (these equations come from the documentation to the SARIMAX model):

    sarima

    With exogenous regressors, the SARIMAX model is specified as regression with SARIMA errors, like so:

    sarimax

    This means that a constant trend will yield the intercept of the time series, whereas a constant in exog will yield the mean of the time series. For example:

    from scipy.signal import lfilter
    
    # Parameters
    nobs = 1e3
    phi = 0.2
    mean = 4
    intercept = mean * (1 - phi)
    print 'mean = %.2f, intercept = %.2f' % (mean, intercept)
    
    # Generate data
    np.random.seed(12345)
    eps = np.random.normal(size=nobs)
    endog = lfilter([1], [1, -phi], eps) + mean
    
    # Estimate the mean via exog
    mod1 = sm.tsa.SARIMAX(endog, order=(1,0,0), exog=np.ones(nobs))
    res1 = mod1.fit()
    print 'exog method (mean)      ', res1.params
    
    # Estimate the intercept via trend
    mod2 = sm.tsa.SARIMAX(endog, order=(1,0,0), trend='c')
    res2 = mod2.fit()
    print 'trend method (intercept)', res2.params
    mean = 4.00, intercept = 3.20
    exog method (mean)       [ 3.99699561  0.19535563  0.95932446]
    trend method (intercept) [ 3.20457711  0.19831545  0.97312586]
    
  7. ChadFulton commented on Jul 16, 2015

    @ChadFulton
    Member

    although there's still a case for checking that both aren't specified

    However, the model won't break here if you do include both (i.e. there won't be a perfect multicollinearity problem), it's just that the intercept versus mean parameter obviously aren't separately identified:

    # Estimate both
    mod3 = sm.tsa.SARIMAX(endog, order=(1,0,0), trend='c', exog=np.ones(nobs))
    res3 = mod3.fit()
    print 'both', res3.params
    print '     -> mean = ', res3.params[1] + res3.params[0] / (1 - phi)
    print '     -> intercept = ', res3.params[0] + res3.params[1] * (1 - phi)
    both [ 0.16198673  3.79598123  0.19535748  0.95928814]
         -> mean =  3.99846464456
         -> intercept =  3.19877171565
    
  8. josef-pkt commented on Jul 16, 2015

    @josef-pkt
    MemberAuthor

    We don't necessarily have to adjust sarimax, i like the ability to use const in exog. Arma needs also refactoring to move trend to 'init'

  9. josef-pkt commented on Mar 31, 2018

    @josef-pkt
    MemberAuthor

    Another question on trend: (I suspect but I'm not sure.)

    In the differencing case, d=1, is the trend

    • in the differenced series (i.e. constant trend is actually drift)
    • subtracted from endog in the same way as exog, i.e. trend='c' means non-zero mean in levels but no drift.

    AFAICS, I think that SARIMAX uses the first (drift), while ARIMA uses the second (const in level)

    I'm trying to compare results for the #4412 testcase ARIMA(1, 1, 2) for CPI, which I haven't figured out yet.

  10. josef-pkt commented on Mar 31, 2018

    @josef-pkt
    MemberAuthor

    The description if the Stata documentation mixes cases, but the explicit statements sound like constant is treated in the same way as exog, i.e.

    z = y - x b
    z ~ SARIMA

    ie. like ARIMA and not like SARIMAX, AFAIU

  11. josef-pkt commented on Mar 31, 2018

    @josef-pkt
    MemberAuthor

    another issue:
    trend='c' in level is redundant, if initial state in ARIMA(p, 1, q) can be non-zero. And I get a hessian/cov_params warning in this case.

    E.g. estimating SARIMAX with trend='n', and without or with exog=np.ones(nobs) (const in exog)

    >>> res_sa_noconst.params
    array([-0.71993056,  0.04425516, -0.81504558,  0.60029831])
    
    >>> res_sa_const.params
    array([ -5.23042667e-08,  -7.19931479e-01,   4.42558959e-02,
            -8.15045730e-01,   6.00298166e-01])
    

    The redundant exog constant in the second case, with default OPG, causes

    [2] Covariance matrix is singular or near-singular, with condition number 5.35e+26. Standard errors may be unstable.
    
  12. ChadFulton commented on Apr 3, 2018

    @ChadFulton
    Member

    In the differencing case, d=1, is the trend

    • in the differenced series (i.e. constant trend is actually drift)
    • subtracted from endog in the same way as exog, i.e. trend='c' means non-zero mean in levels but no drift.

    AFAICS, I think that SARIMAX uses the first (drift), while ARIMA uses the second (const in level)

    Yes, in the default representation, the trend keyword puts the given trend on the stationary "state", which is essentially the differenced endog variable.

    I'm not sure about how ARIMA does it.

  13. ChadFulton commented on Apr 3, 2018

    @ChadFulton
    Member

    The description if the Stata documentation mixes cases, but the explicit statements sound like constant is treated in the same way as exog, i.e.

    z = y - x b
    z ~ SARIMA

    ie. like ARIMA and not like SARIMAX, AFAIU

    Stata is more like SARIMAX, in that trend=c in SARIMAX is the same as what you get with e.g. arima cpi, arima(1,1,2).

    If you wanted to get the same effect by using an exog (in either SARIMAX or Stata), for the d=1 case, you would need to put the time trend (so that the difference was a constant). e.g. The following are basically the same:

    • arima cpi, arima(1,1,2)
    • gen t = _n followed by arima cpi t, arima(1,1,2)

    or:

    • mod = SARIMAX(cpi, order=(1, 1, 2), trend='c')
    • mod = SARIMAX(cpi, order=(1, 1, 2), exog=np.arange(len(cpi)) + 1)

    However, the one wrinkle is that Stata reports the parameter in terms of the mean, while in SARIMAX it could be either the mean or the intercept. It is the mean if you use exog and it is the intercept if you use trend. So, to use SARIMAX to estimate the model as Stata does, one could do:

    mod = sarimax.SARIMAX(endog, order=(1, 1, 2), trend='c')
    stata_params = [.9281721822, -.8959349, 1.302477, .3024765, .8100338]
    
    params = stata_params[:]
    # Convert the mean parameter to intercept form
    params[0] *= (1 - params[1])
    # Convert the standard deviation to a variance
    params[4] **= 2
    res = mod.smooth(params)
    print(res.llf)

    or one could do:

    mod = sarimax.SARIMAX(endog, order=(1, 1, 2), exog=np.arange(len(endog)) + 1)
    stata_params = [.9281721822, -.8959349, 1.302477, .3024765, .8100338]
    
    params = stata_params[:]
    # Convert the standard deviation to a variance
    params[4] **= 2
    res = mod.smooth(params)
    print(res.llf)

    Either yields -245.4076, which is pretty close to Stata: -245.4078.

  14. mmhernandm commented on May 14, 2020

    @mmhernandm

    Which are the parameters that can determine sarimax or autoarima trend to predict more easily the low values than the higher peaks in a serie?

  15. bashtage commented on Aug 10, 2020

    @bashtage
    Member

    ARMA and the old ARIMA have been deprecated and will be removed after 0.12. Only the statespace implementation will persist, and so this issue has been mooted.

  16. modified the milestones: 0.8, 0.12 on Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions