def main():
    """
    Toy program to test the KPSS autolag method of Hobijn et al (1998).
    Unit tests using statsmodels data sets verified against SAS 9.3. To
    use, modify the following lines in main KPSS method:

      old:
        if lags is None:
            # from Kwiatkowski et al. referencing Schwert (1989)
            lags = int(np.ceil(12. * np.power(nobs / 100., 1 / 4.)))

      new:
        if lags is None:
            # autolag method of Hobijn et al. (1998)
            lags = _kpss_autolag(resids, nobs)
    """
    print("KPSS autolag method of Hobijn et al. (1998)")
    # real GDP from macrodata data set
    with warnings.catch_warnings(record=True) as w:
        res = kpss(macrodata.load().data['realgdp'], 'c')
    print("  realgdp('c'): stat =", "{0:0.5f}".format(res[0]), " pval =",
          "{0:0.5f}".format(res[1]), " lags =", format(res[2]))
    assert_almost_equal(res[0], 2.06851, decimal=3)
    assert_equal(res[2], 9)
    # sunspot activity from sunspots data set
    with warnings.catch_warnings(record=True) as w:
        res = kpss(sunspots.load().data['SUNACTIVITY'], 'c')
    print("  sunactivity('c'): stat =", "{0:0.5f}".format(res[0]), " pval =",
          "{0:0.5f}".format(res[1]), " lags =", format(res[2]))
    assert_almost_equal(res[0], 0.66987, decimal=3)
    assert_equal(res[2], 7)
    # volumes from nile data set
    with warnings.catch_warnings(record=True) as w:
        res = kpss(nile.load().data['volume'], 'c')
    print("  volume('c'): stat =", "{0:0.5f}".format(res[0]), " pval =",
          "{0:0.5f}".format(res[1]), " lags =", format(res[2]))
    assert_almost_equal(res[0], 0.86912, decimal=3)
    assert_equal(res[2], 5)
    # log-coinsurance from randhie data set
    with warnings.catch_warnings(record=True) as w:
        res = kpss(randhie.load().data['lncoins'], 'ct')
    print("  lncoins('ct'): stat =", "{0:0.5f}".format(res[0]), " pval =",
          "{0:0.5f}".format(res[1]), " lags =", format(res[2]))
    assert_almost_equal(res[0], 0.36762, decimal=3)
    assert_equal(res[2], 75)
    # in-vehicle time from modechoice data set
    with warnings.catch_warnings(record=True) as w:
        res = kpss(modechoice.load().data['invt'], 'ct')
    print("  invt('ct'): stat =", "{0:0.5f}".format(res[0]), " pval =",
          "{0:0.5f}".format(res[1]), " lags =", format(res[2]))
    assert_almost_equal(res[0], 0.40258, decimal=3)
    assert_equal(res[2], 18)
Example #2
0
 def test_lags(self):
     # real GDP from macrodata data set
     with pytest.warns(InterpolationWarning):
         res = kpss(self.x, 'c', nlags='auto')
     assert_equal(res[2], 9)
     # real interest rates from macrodata data set
     res = kpss(sunspots.load(True).data['SUNACTIVITY'], 'c', nlags='auto')
     assert_equal(res[2], 7)
     # volumes from nile data set
     with pytest.warns(InterpolationWarning):
         res = kpss(nile.load(True).data['volume'], 'c', nlags='auto')
     assert_equal(res[2], 5)
     # log-coinsurance from randhie data set
     with pytest.warns(InterpolationWarning):
         res = kpss(randhie.load(True).data['lncoins'], 'ct', nlags='auto')
     assert_equal(res[2], 75)
     # in-vehicle time from modechoice data set
     with pytest.warns(InterpolationWarning):
         res = kpss(modechoice.load(True).data['invt'], 'ct', nlags='auto')
     assert_equal(res[2], 18)
Example #3
0
 def test_lags(self):
     # real GDP from macrodata data set
     with pytest.warns(InterpolationWarning):
         res = kpss(self.x, "c", nlags="auto")
     assert_equal(res[2], 9)
     # real interest rates from macrodata data set
     res = kpss(sunspots.load().data["SUNACTIVITY"], "c", nlags="auto")
     assert_equal(res[2], 7)
     # volumes from nile data set
     with pytest.warns(InterpolationWarning):
         res = kpss(nile.load().data["volume"], "c", nlags="auto")
     assert_equal(res[2], 5)
     # log-coinsurance from randhie data set
     with pytest.warns(InterpolationWarning):
         res = kpss(randhie.load().data["lncoins"], "ct", nlags="auto")
     assert_equal(res[2], 75)
     # in-vehicle time from modechoice data set
     with pytest.warns(InterpolationWarning):
         res = kpss(modechoice.load().data["invt"], "ct", nlags="auto")
     assert_equal(res[2], 18)
Example #4
0
 def test_lags(self):
     # real GDP from macrodata data set
     with warnings.catch_warnings(record=True):
         lags = kpss(self.x, 'c', lags='auto')[2]
     assert_equal(lags, 9)
     # real interest rates from macrodata data set
     with warnings.catch_warnings(record=True):
         lags = kpss(sunspots.load().data['SUNACTIVITY'], 'c',
                     lags='auto')[2]
     assert_equal(lags, 7)
     # volumes from nile data set
     with warnings.catch_warnings(record=True):
         lags = kpss(nile.load().data['volume'], 'c', lags='auto')[2]
     assert_equal(lags, 5)
     # log-coinsurance from randhie data set
     with warnings.catch_warnings(record=True):
         lags = kpss(randhie.load().data['lncoins'], 'ct', lags='auto')[2]
     assert_equal(lags, 75)
     # in-vehicle time from modechoice data set
     with warnings.catch_warnings(record=True):
         lags = kpss(modechoice.load().data['invt'], 'ct', lags='auto')[2]
     assert_equal(lags, 18)
 def test_lags(self):
     # real GDP from macrodata data set
     with warnings.catch_warnings(record=True):
         lags = kpss(self.x, 'c', lags='auto')[2]
     assert_equal(lags, 9)
     # real interest rates from macrodata data set
     with warnings.catch_warnings(record=True):
         lags = kpss(sunspots.load().data['SUNACTIVITY'], 'c',
                     lags='auto')[2]
     assert_equal(lags, 7)
     # volumes from nile data set
     with warnings.catch_warnings(record=True):
         lags = kpss(nile.load().data['volume'], 'c', lags='auto')[2]
     assert_equal(lags, 5)
     # log-coinsurance from randhie data set
     with warnings.catch_warnings(record=True):
         lags = kpss(randhie.load().data['lncoins'], 'ct', lags='auto')[2]
     assert_equal(lags, 75)
     # in-vehicle time from modechoice data set
     with warnings.catch_warnings(record=True):
         lags = kpss(modechoice.load().data['invt'], 'ct', lags='auto')[2]
     assert_equal(lags, 18)
Example #6
0
    assert np.all(cv_50 <= cv_inf)


def test_adf_short_timeseries():
    # GH 262
    import numpy as np
    from arch.unitroot import ADF
    x = np.asarray([0., 0., 0., 0., 0., 0., 1., 1., 0., 0.])
    adf = ADF(x)
    assert_almost_equal(adf.stat, -2.236, decimal=3)
    assert adf.lags == 1


kpss_autolag_data = ((macrodata.load().data['realgdp'], 'c',
                      9), (sunspots.load().data['SUNACTIVITY'], 'c',
                           7), (nile.load().data['volume'], 'c',
                                5), (randhie.load().data['lncoins'], 'ct', 75),
                     (modechoice.load().data['invt'], 'ct', 18))


@pytest.mark.filterwarnings('ignore::DeprecationWarning')
@pytest.mark.parametrize('data,trend,lags', kpss_autolag_data)
def test_kpss_data_dependent_lags(data, trend, lags):
    # real GDP from macrodata data set
    kpss = KPSS(data, trend=trend)
    assert_equal(kpss.lags, lags)


za_test_result = namedtuple('za_test_result', [
    'stat',
    'pvalue',
Example #7
0
    assert np.all(cv_50 <= cv_inf)


def test_adf_short_timeseries():
    # GH 262
    import numpy as np
    from arch.unitroot import ADF
    x = np.asarray([0., 0., 0., 0., 0., 0., 1., 1., 0., 0.])
    adf = ADF(x)
    assert_almost_equal(adf.stat, -2.236, decimal=3)
    assert adf.lags == 1


kpss_autolag_data = ((macrodata.load().data['realgdp'], 'c', 9),
                     (sunspots.load().data['SUNACTIVITY'], 'c', 7),
                     (nile.load().data['volume'], 'c', 5),
                     (randhie.load().data['lncoins'], 'ct', 75),
                     (modechoice.load().data['invt'], 'ct', 18))


@pytest.mark.filterwarnings('ignore::DeprecationWarning')
@pytest.mark.parametrize('data,trend,lags', kpss_autolag_data)
def test_kpss_data_dependent_lags(data, trend, lags):
    # real GDP from macrodata data set
    kpss = KPSS(data, trend=trend)
    assert_equal(kpss.lags, lags)


za_test_result = namedtuple('za_test_result',
                            ['stat', 'pvalue', 'lags', 'trend',
                             'max_lags', 'method', 'actual_lags', ])