Repository: statsmodels/statsmodels

Issue:
zivot_andrews autolag issue
I have been using statsmodels for my dissertation over the last few weeks. I think I found a bug in both the statstool.zivot_andrews function and possibly the string_like function.

I used the following function call and got the following error

Input: print(stattools.zivot_andrews(1d_array_to_check,autolag='AIC'))

Output: anaconda3\lib\site-packages\statsmodels\tools\validation\validation.py", line 363, in string_like raise ValueError(msg)

ValueError: If not None, autolag must be one of: 'AIC', 'BIC', 't-stat'

i was able to fix the issue by modifying the zivot_andrews call in the following way:

line 1980: autolag = string_like(autolag, 'autolag', options=('aic', 'bic', 't-stat'), optional=True)

this is important because line 1986 calls

adf_res = adfuller(x, maxlag=maxlag, regression='ct',autolag=autolag)

and adfuller expects options=('aic', 'bic', 't-stat') not options=('AIC', 'BIC', 't-stat')

I tested the string_like function and it also seems to have issues with strings of capital letters for some reason. This might be a python version issue? See the sm.show_versions() dump below.

INSTALLED VERSIONS
------------------
Python: 3.7.6.final.0

statsmodels
===========

Installed: 0.11.1 

Required Dependencies
=====================

cython: 0.29.15 
numpy: 1.18.1 
scipy: 1.4.1 
pandas: 1.0.1 
    dateutil: 2.8.1 
patsy: 0.5.1 

Optional Dependencies
=====================

matplotlib: 3.1.3 
cvxopt: Not installed
joblib: 0.14.1

Developer Tools
================

IPython: 7.12.0 
    jinja2: 2.11.1 
sphinx: 2.4.0 
    pygments: 2.5.2 
pytest: 5.3.5 
virtualenv: Not installed

zivot_andrews autolag issue
I have been using statsmodels for my dissertation over the last few weeks. I think I found a bug in both the statstool.zivot_andrews function and possibly the string_like function.

I used the following function call and got the following error

Input: print(stattools.zivot_andrews(1d_array_to_check,autolag='AIC'))

Output: anaconda3\lib\site-packages\statsmodels\tools\validation\validation.py", line 363, in string_like raise ValueError(msg)

ValueError: If not None, autolag must be one of: 'AIC', 'BIC', 't-stat'

i was able to fix the issue by modifying the zivot_andrews call in the following way:

line 1980: autolag = string_like(autolag, 'autolag', options=('aic', 'bic', 't-stat'), optional=True)

this is important because line 1986 calls

adf_res = adfuller(x, maxlag=maxlag, regression='ct',autolag=autolag)

and adfuller expects options=('aic', 'bic', 't-stat') not options=('AIC', 'BIC', 't-stat')

I tested the string_like function and it also seems to have issues with strings of capital letters for some reason. This might be a python version issue? See the sm.show_versions() dump below.

INSTALLED VERSIONS
------------------
Python: 3.7.6.final.0

statsmodels
===========

Installed: 0.11.1 

Required Dependencies
=====================

cython: 0.29.15 
numpy: 1.18.1 
scipy: 1.4.1 
pandas: 1.0.1 
    dateutil: 2.8.1 
patsy: 0.5.1 

Optional Dependencies
=====================

matplotlib: 3.1.3 
cvxopt: Not installed
joblib: 0.14.1

Developer Tools
================

IPython: 7.12.0 
    jinja2: 2.11.1 
sphinx: 2.4.0 
    pygments: 2.5.2 
pytest: 5.3.5 
virtualenv: Not installed



Discussion:

Resolving patch:
diff --git a/statsmodels/tsa/stattools.py b/statsmodels/tsa/stattools.py
--- a/statsmodels/tsa/stattools.py
+++ b/statsmodels/tsa/stattools.py
@@ -1978,7 +1978,7 @@ def run(self, x, trim=0.15, maxlag=None, regression='c', autolag='AIC'):
         regression = string_like(regression, 'regression',
                                  options=('c', 't', 'ct'))
         autolag = string_like(autolag, 'autolag',
-                              options=('AIC', 'BIC', 't-stat'), optional=True)
+                              options=('aic', 'bic', 't-stat'), optional=True)
         if trim < 0 or trim > (1. / 3.):
             raise ValueError('trim value must be a float in range [0, 1/3)')
         nobs = x.shape[0]


Test patch:
diff --git a/statsmodels/tsa/tests/test_stattools.py b/statsmodels/tsa/tests/test_stattools.py
--- a/statsmodels/tsa/tests/test_stattools.py
+++ b/statsmodels/tsa/tests/test_stattools.py
@@ -994,6 +994,11 @@ def test_fail_autolag_type(self):
         with pytest.raises(ValueError):
             zivot_andrews(self.fail_mdl, autolag='None')
 
+    @pytest.mark.parametrize('autolag', ["AIC", "aic", "Aic"])
+    def test_autolag_case_sensitivity(self, autolag):
+        res = zivot_andrews(self.fail_mdl, autolag=autolag)
+        assert res[3] == 1
+
     # following tests compare results to R package urca.ur.za (1.13-0)
     def test_rgnp_case(self):
         res = zivot_andrews(self.fail_mdl, maxlag=8, regression='c',