Skip to content

Revisit and generalize Hannan-Risannen method #1301

Closed

Description

@jseabold

I'm not positive that the HR method for approximate ARMA parameters is done "correctly". This needs revisiting, and maybe needs some generalization. Just came across another reference in the X13ARIMA docs. Haven't read it yet though.

Gomez, V. and A. Maravall (2001). Automatic modeling methods for univariate series. In D. Pena, G. C. Tiao, and R. S. Tsay (Eds.), A Course in Time Series Analysis. New York, NY: J. Wiley and Sons.

Activity

  1. jseabold commented on Jan 29, 2014

    @jseabold
    MemberAuthor

    Starting to think that start_params should all be .1 for ARMA models by default with "hr" as an option. Running into this a lot.

  2. chor0020 commented on May 19, 2015

    @chor0020

    I may have found the source of the problem.

    Hannan-Risannen requires an initial estimate of an AR model with an order greater than the AR and MA of the ARMA model you are trying to fit. In _fit_start_params_hr, the initial AR model is fit with:

    armod = AR(endog).fit(ic='bic', trend='nc', maxlag=maxlag)
    

    This finds the best model order by minimizing bic, which will not necessarily be a higher order than the desired ARIMA. I have made a small modification with:

    maxlag = max(p, q) + 1
    armod = AR(endog).fit(trend='nc', maxlag=maxlag)
    

    This ensures that the initial AR is large enough. Since making this change, I have never found start_params to be nonstationary or noninvertible. Success!

  3. josef-pkt commented on Jul 17, 2015

    @josef-pkt
    Member

    @chor0020 did we ever have a PR for this? I thought this was changed, but it's not.

    see #2521 making maxlag settable
    see #2533 start_params can be a callable

    I started to read a bit about Hannan Risannen. Mathematica uses aic for model selection. Most references just specify p_temp > max(p, q)

    I think we need to change the default number of lags for the initial estimate: bic produces a "true" model, while "aic" finds the best approximating model, and "aic" produces usually larger model (not ARIMA specific).
    My guess is that doing any kind of model search for the initial step of HR is overkill, and a waste of time if the model search is not optimized. (ic based search should also use a minimum model size.)

    Getting better defaults is independent of the other options for start_params in the two related issues.

    Brockwell and Davis (IIRC) mention to switch to, for example, 0.1, if the Hannan/Risannen starting values are not stationary and invertible. Maybe converting the exception to a warning might be more useful, and the switch start_params automatically.

    Also, I think a standalone HR estimation would be useful for a preliminary model search in larger models. My guess is that this could be made cheaper than the full MLE estimation. (see also #2198)

  4. chelleych commented on Jul 20, 2015

    @chelleych
    Contributor

    Note that for large model orders, setting all starting parameters to 0.1 will result in nonstationary/noninvertible start_params (0.1 will be too large). I advocate forcing stationarity/invertibility with parameter values proportional to the model order, like

        start_params = np.array([1.] * k + [1./(p+1)] * p + [1./(q+1)] * q)
  5. added this to the 0.7 milestone on Aug 12, 2015
  6. josef-pkt commented on Aug 12, 2015

    @josef-pkt
    Member
  7. chelleych commented on Aug 17, 2015

    @chelleych
    Contributor

    One possible fix: #2550 allows start_params to be fit by basically setting p_temp and skipping the "doing any kind of model search for the initial step of HR"

  8. josef-pkt commented on Aug 17, 2015

    @josef-pkt
    Member

    @chelleych Yes, i think we should go for something like #2550. However, I will suggest different name and different default (*). (I'll look at it more carefully most likely later today. I just started a branch for #2587)

    (*) maxlag = max(p, q) + 1 (and maybe allow string 'aic', 'bic' for the future when we have a minimum lag in the min ic search)

  9. josef-pkt commented on Aug 17, 2015

    @josef-pkt
    Member

    fixed starting values:

    1./(p+1) might get too close to nonstationary for large lags, p./(p+1) -> 1

    1 / (1 + k)**2 might be reasonable, and assumes larger values for smaller lags (k = 1,2,3, ...)

    >>> (1. / np.arange(2, 21)**2).cumsum()
    array([ 0.25      ,  0.36111111,  0.42361111,  0.46361111,  0.49138889,
            0.51179705,  0.52742205,  0.53976773,  0.54976773,  0.55803219,
            0.56497664,  0.5708938 ,  0.57599584,  0.58044028,  0.58434653,
            0.58780674,  0.59089316,  0.59366324,  0.59616324])
    >>> (1. / np.arange(2, 21)**2)
    array([ 0.25      ,  0.11111111,  0.0625    ,  0.04      ,  0.02777778,
            0.02040816,  0.015625  ,  0.01234568,  0.01      ,  0.00826446,
            0.00694444,  0.00591716,  0.00510204,  0.00444444,  0.00390625,
            0.00346021,  0.00308642,  0.00277008,  0.0025    ])
    
  10. josef-pkt commented on Aug 17, 2015

    @josef-pkt
    Member

    another possible issue with start_params

    if q !=0 and p == 0:
    we have

    else:
                    start_params[k+p:k+p+q] = yule_walker(endog, order=q)[0]
    

    My guess is that this should be yule_walker of AR resid and not of endog
    mailing list example is for ARMA(0,0,2) which wouldn't end up using Hannan-Risannen.

    edit
    or maybe simpler: we can invert the AR process to get the MA representation and truncate at q

  11. josef-pkt commented on Aug 18, 2015

    @josef-pkt
    Member

    I am trying out a few changes with the lynx data, which is difficult because it has essentially a cyclical unit root.

    sp: using starting values sp = np.r_[[0], 1. / np.arange(2, p+2)**2, 1. / np.arange(2, q+2)**2]
    raises exception in 2 out of 72 cases (I didn't count convergence warnings)
    hr: hannan-risannen (changes: fixed maxlag and converting in pure MA) raises in 32 out of 72 cases
    tp: setting transparams to False raises in 28 out of 72 cases

    Exception are either ValueError from nonstationary start_params, or LinalgErrors in numpy or even in MKL (invalid values)

    >>> [(k, len(v)) for k,v in failed.items()]
    [('sp', 2), ('hr', 32), ('tp', 28)]
    
    >>> failed['hr']
    [[2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5], [5, 2], [5, 3], [5, 4], [5, 5], [6, 1], [6, 3], [6, 4], [6, 5], [7, 2], [7, 4], [7, 5], [8, 4], [9, 3], [9, 4], [9, 5], [10, 2], [10, 3], [10, 4], [10, 5], [11, 1], [11, 2], [11, 3], [11, 4], [11, 5]]
    
    >>> failed['sp']
    [[2, 4], [2, 5]]
    
    >>> failed['tp']
    [[2, 4], [2, 5], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5], [5, 2], [5, 3], [5, 4], [5, 5], [6, 1], [6, 3], [6, 4], [6, 5], [7, 4], [7, 5], [9, 4], [9, 5], [10, 2], [10, 3], [10, 4], [10, 5], [11, 1], [11, 2], [11, 3], [11, 4], [11, 5]]
    >>> 
    

    no timing

  12. josef-pkt commented on Aug 18, 2015

    @josef-pkt
    Member

    (after git stash, checking the script with the current master version)

    fixing maxlag at max(p, q) + 1 doesn't actually help much in the lynx example.

    For hr the old version errors in 37 instead of 32 cases, 4 of them are fixing pure MA starting values.

    The case of transparams=False worked much better in the old version

    The old version has many Intel MKL ERROR: Parameter 4 was incorrect on entry to DLASCL.

    >>> [(k, len(v)) for k,v in failed.items()]
    [('sp', 2), ('hr', 37), ('tp', 10)]
    
    >>> sorted(set(tuple(case) for case in failed['hr']) - set(tuple(case) for case in fnew))
    [(0, 2), (0, 3), (0, 4), (0, 5), (1, 3), (1, 4), (1, 5), (2, 3), (3, 1), (6, 2), (7, 3), (8, 3), (8, 5), (9, 2), (10, 1)]
    >>> sorted(set(tuple(case) for case in fnew) - set(tuple(case) for case in failed['hr']))
    [(4, 3), (5, 3), (5, 4), (5, 5), (7, 5), (9, 3), (9, 5), (10, 2), (10, 3), (11, 5)]
    
  13. josef-pkt commented on Aug 18, 2015

    @josef-pkt
    Member

    One more issue: scale invariance (lynx data are large integers)

    If I standardize the data, then I get one less error in hr, but one more in sp.

    (with new HR)

    >>> [(k, len(v)) for k,v in failed.items()]
    [('tp', 28), ('sp', 3), ('hr', 31)]
    
  14. chelleych commented on Aug 18, 2015

    @chelleych
    Contributor

    I've found that fixing maxlag at max(p, q) + 1 will often not be nearly large enough, especially when q > 1 and p > 1.

  15. josef-pkt commented on Aug 18, 2015

    @josef-pkt
    Member

    @chelleych Do you have a artificial or real dataset that illustrates these problems, so we can use it for experimenting or as a unit test case?
    Does the ar autolag search yield a larger maxlag for any of the other information or selection criteria, e.g. AIC?
    The lynx data is useful because it breaks things, but it's not really an example for a stationary ARMA.

    I'm a bit pessimistic and I think there will remain large ranges of "not nice" problems where the defaults break, and we will need to leave it to the user to figure those out. The start_arlags option in your PR is one option for users to try a different option.

    I think we should make the immediate changes for 0.7, and leave further improvements for a future release.

    Aside: we should attach more information about the start_params selection to the results instance, I didn't see any yet.

  16. chelleych commented on Aug 18, 2015

    @chelleych
    Contributor

    I work with medical data, so I don't think I can make it publicly available. They are also very long time series (~50,000 time points).
    I've never tested the AR autolag search with AIC instead of BIC, if that's what you mean.

    I agree that we will pretty much always have problems with bad starting parameters. The best we can do is provide a set of options to give possibly good starting values, which is important for improving the speed and results.

    Aside: we should attach more information about the start_params selection to the results instance, I didn't see any yet.

    I'm not sure what you mean by "results instance." I'm new at this github stuff.

  17. josef-pkt commented on Aug 18, 2015

    @josef-pkt
    Member

    I work with medical data, so I don't think I can make it publicly available. They are also very long time series (~50,000 time points).

    Can you post the estimated coefficients for some of the problematic ARMA models, if you manage to estimate with some start_params? Maybe we are able to simulate some problematic data.

    I'm not sure what you mean by "results instance." I'm new at this github stuff.

    fit returns an instance of a results class that has some optimizer and optimization information attached, but nothing directly about the hannan-risannen calculation, AFAICS.

    res_pq = ARMA(mydata, order).fit()

    >>> res_pq.mle_retvals
    {'converged': False, 'warnflag': 2, 'fcalls': 273, 'gopt': array([-0.03925013, -0.69156862, -0.11573452,  0.35465532,  0.5940786 ,
            0.61146517,  0.43169559,  0.03469044, -0.42412212, -0.67031248,
           -0.56556337, -0.23848691]), 'fopt': nan}
    
    >>> res_pq.mle_settings
    {'retall': False, 'callback': None, 'factr': 100.0, 'm': 12, 'fargs': (), 'full_output': 1, 'bounds': [(None, None), (None, None), (None, None), (None, None), (None, None), (None, None), (None, None), (None, None), (None, None), (None, None), (None, None), (None, None)], 'optimizer': 'lbfgs', 'disp': 0, 'approx_grad': True, 'maxiter': 50, 'pgtol': 1e-08, 'start_params': array([-0.03347287,  0.63020207, -0.37654498,  0.17804832, -0.08383597,
           -0.02373538,  0.06713224, -0.1232866 ,  0.08083999,  0.01808427,
            0.0582774 , -0.05454529]), 'extra_fit_funcs': {}}
    
  18. josef-pkt commented on Feb 2, 2017

    @josef-pkt
    Member

    @ChadFulton
    The status here is that there has been a partial option added in #2550 - #3084 but it doesn't fix the underlying problems.
    In my interpretation, the lag search with information criteria should never choose an AR lag length small than the AR order of the desired ARMA(p, q).
    #2594 was supposed to fix this, so hannan-risannen follows more the text book description.
    I think something like #2594 is still necessary.

    The main problem for users is that the default hr start_params often don't work well enough. I don't remember what SARIMAX uses. (users can work around by providing their own start_params, but many users will not try.)

    (partially related: #3173 standalone hannan-risannen might be useful for specification search, but the idea is from a long time ago, maybe 1970s, when computers were much slower.)

  19. modified the milestones: 0.7, 0.10 on Apr 17, 2018
  20. bashtage commented on Jul 25, 2019

    @bashtage
    Member

    Headed into master.

  21. modified the milestones: 0.10, 0.11 on Dec 18, 2019
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