Skip to content

Strange behavior with pacf yule-walker unbiased #332

Open

Description

@jseabold

Need to dig in further, but to replicate.

import statsmodels.api as sm
from statsmodels.datasets import macrodata
x = np.diff(macrodata.load().data['realgdp'])
pc = sm.tsa.pacf(x, nlags=199, method='ywbiased')
print pc[101]
-600.36057976934592

Activity

  1. jseabold commented on Jun 26, 2012

    @jseabold
    MemberAuthor

    Oh...

    n = len(x)
    x -= x.mean()
    denom = lambda k: n - k
    orders = [99, 100, 101, 102]
    for order in orders:
        r = np.zeros(order+1, np.float64)
        r[0] = (X**2).sum() / denom(0)
        for k in range(1,order+1):
            r[k] = (X[0:-k]*X[k:]).sum() / denom(k)
        R = toeplitz(r[:-1])
        print np.linalg.cond(R)
    
    1836.75103749
    3956.00109141
    3353002.38356
    6092.73841107

    Should we guard against this here? This seems too strict and affects the others unless we can give some cutoff for the condition number or recode yule walker in some other way.

    for order in orders:
        r = np.zeros(order+1, np.float64)
        r[0] = (X**2).sum() / denom(0)
        for k in range(1,order+1):
            r[k] = (X[0:-k]*X[k:]).sum() / denom(k)
        R = toeplitz(r[:-1])
    
        # guard against singular R
        rcond = 1./np.linalg.cond(R) + np.finfo(float).eps
        #rho = np.dot(np.linalg.pinv(R, rcond=rcond), r[1:])
        rho = np.linalg.solve(R, r[1:])
        print rho[-1]
    
  2. jseabold commented on May 1, 2013

    @jseabold
    MemberAuthor

    Another problem with yule_walker. This might be do to a unit root though. Trying to figure out the problems in arima start_params.

    endog = np.array([  -41.37540811,   -81.05603531,   -76.18763931,   -94.42351544,
             -83.08257331,   -37.40676791,   -49.04755944,  -110.41035244,
            -108.63524711,  -115.14552511,   -66.44614771,   -89.40900978,
             -68.61769271,     6.77943849,   -38.99407264,   -78.97566064,
             -70.55909964,   -91.13547464,   -26.72476478,   -51.42485864,
            -123.70562444,   -85.57595298,   -39.13361478,   -46.80172584,
             -88.36080824,   -84.69368591,   -50.23188958,   -21.11144678,
             -84.55601878,  -116.16556504,   -55.11520718,   -56.29111838,
            -105.35706078,  -112.17542038,   832.16035429,  1536.41388629,
             572.60651349,    47.67306616,    66.94658096,   -92.99072358,
             -60.95508331,   -65.90470498,   -44.81670051,    -4.33587364,
             -23.21699311,  -100.14294938,  -130.28211391,   -91.60215371])
    from statsmodels.regression import yule_walker
    yule_walker(endog, 15)
    

    Why is sigma a nan?

  3. josef-pkt commented on May 1, 2013

    @josef-pkt
    Member

    the data looks weird, what's the jump to 832 and 1536?

    I didn't run it yet to look at the nan.

    Main question: fail gracefully early on or try much harder.

    There might be a Ridge version of yule_walker or the equivalent estimation with some penalization to "force" reasonable starting values, #15 #675

  4. jseabold commented on May 1, 2013

    @jseabold
    MemberAuthor

    Definitely odd. I don't know the data, it was taken from the mailing list.

  5. added a commit that references this issue on Sep 26, 2014
    e117866
  6. ChadFulton commented on Mar 28, 2019

    @ChadFulton
    Member

    See also e.g. https://stackoverflow.com/questions/55252492/pacf-function-in-statsmodels-tsa-stattools-gives-numbers-greater-than-1-when-usi/55359388#55359388

    I also wanted to add that in some cases, errors are caused because the "unbiased" method produces an autocovariance matrix that is not positive semidefinite. But it seems like this is not always the problem - sometimes the autocovariance matrix is positive definite, but numerical issues still result in autocorrelations > 1 and negative variances.

  7. added
    type-possible-bug
    on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-tsacorner-casedesigntype-possible-bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions