Skip to content

BUG: ARMA better start_params, fix MA - #2594

Closed
josef-pkt wants to merge 1 commit into
statsmodels:masterfrom
josef-pkt:arma_startparams
Closed

josef-pkt wants to merge 1 commit into
statsmodels:masterfrom
josef-pkt:arma_startparams

Conversation

@josef-pkt

Copy link
Copy Markdown
Member

see #1301

two minimal changes to try out how well it works
one fix in pure MA, and set lags for auxiliary AR to max(p,q) + 1

additional options in PR #2550

@josef-pkt

Copy link
Copy Markdown
Member Author

I'm stopping here for today. Here's my current trying-out script

# -*- coding: utf-8 -*-
"""
Created on Mon Aug 17 15:12:30 2015

Author: Josef Perktold
License: BSD-3
"""

import numpy as np
from statsmodels.tsa.arima_model import ARMA, ARIMA

lynx = np.array(
      [ 269,  321,  585,  871, 1475, 2821, 3928, 5943, 4950, 2577,  523,
         98,  184,  279,  409, 2285, 2685, 3409, 1824,  409,  151,   45,
         68,  213,  546, 1033, 2129, 2536,  957,  361,  377,  225,  360,
        731, 1638, 2725, 2871, 2119,  684,  299,  236,  245,  552, 1623,
       3311, 6721, 4254,  687,  255,  473,  358,  784, 1594, 1676, 2251,
       1426,  756,  299,  201,  229,  469,  736, 2042, 2811, 4431, 2511,
        389,   73,   39,   49,   59,  188,  377, 1292, 4031, 3495,  587,
        105,  153,  387,  758, 1307, 3465, 6991, 6313, 3794, 1836,  345,
        382,  808, 1388, 2713, 3800, 3091, 2985, 3790,  674,   81,   80,
        108,  229,  399, 1132, 2432, 3574, 2935, 1537,  529,  485,  662,
       1000, 1590, 2657, 3396], dtype=np.int64)

lynx = lynx * 1.       
lynx = (lynx - lynx.mean()) / lynx.std()

mod = ARMA(lynx, order=(1,5))
#res = mod.fit(disp=0)

#print(res.summary())

#print(ARMA(lynx-lynx.mean(), order=(1,5)).fit(start_params=[0.1]*7, disp=0).params)
#print(ARMA(lynx-lynx.mean(), order=(1,5)).fit(disp=0).params)
#print(ARMA(lynx-lynx.mean(), order=(0,5)).fit(start_params=[0.1]*6, disp=0).params)
#print(ARMA(lynx-lynx.mean(), order=(0,5)).fit(disp=0).params)

success_hr = []
failed = {'sp':[], 'hr':[], 'tp':[]}
for p in range(12):
    for q in range(6):
        sp = np.r_[[0], 1. / np.arange(2, p+2)**2, 1. / np.arange(2, q+2)**2]
        #sp = np.zeros(1+p+q)
        try:
            res_pq0 = ARMA(lynx-lynx.mean(), order=(p, q)).fit(start_params=sp, disp=0)
            print(p, q, res_pq0.params)


        except: # ValueError:
            print ('sp failed at ', p, q)
            failed['sp'].append([p,q])
        try:
            res_pq = ARMA(lynx-lynx.mean(), order=(p, q)).fit(disp=0)
            print(p, q, res_pq.params)
        except: # ValueError:
            print ('hr failed at ', p, q)
            failed['hr'].append([p,q])
            success_hr.append([p,q])

        try:
            res_pq = ARMA(lynx-lynx.mean(), order=(p, q)).fit(transparams=False, disp=0)
            print(p, q, res_pq.params)
        except: # ValueError:
            print ('tp failed at ', p, q)
            failed['tp'].append([p,q])

res_10_1 = ARMA(lynx-lynx.mean(), order=(10, 1)).fit(disp=0)

for key in 'hr sp tp'.split():
    print(failed[key])


'''
>>> [(k, len(v)) for k,v in failed.items()]
[('sp', 2), ('hr', 32), ('tp', 28)]

>>> len([(p, q) for p in range(12) for q in range(6)])
72
>>> 12*6
72

>>> 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]]
>>> 
'''

@chelleych

Copy link
Copy Markdown
Contributor

An auxiliary AR as max(p,q) + 1 may not be big enough.

@josef-pkt

Copy link
Copy Markdown
Member Author

@chelleych to clarify: this is a partial fix to check possible defaults in one example. I still think we should also add the user option for maxlag that is in #2550.

@bashtage

bashtage commented Jun 9, 2019

Copy link
Copy Markdown
Member

Closing in favor of #4513

@bashtage bashtage closed this Jun 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants