def pacf(x, nlags=40, method='ywunbiased', alpha=None):
    "\n    Partial autocorrelation estimated\n\n    Parameters\n    ----------\n    x : 1d array\n        observations of time series for which pacf is calculated\n    nlags : int\n        largest lag for which pacf is returned\n    method : {'ywunbiased', 'ywmle', 'ols'}\n        specifies which method for the calculations to use:\n\n        - yw or ywunbiased : yule walker with bias correction in denominator\n          for acovf. Default.\n        - ywm or ywmle : yule walker without bias correction\n        - ols - regression of time series on lags of it and on constant\n        - ld or ldunbiased : Levinson-Durbin recursion with bias correction\n        - ldb or ldbiased : Levinson-Durbin recursion without bias correction\n    alpha : float, optional\n        If a number is given, the confidence intervals for the given level are\n        returned. For instance if alpha=.05, 95 % confidence intervals are\n        returned where the standard deviation is computed according to\n        1/sqrt(len(x))\n\n    Returns\n    -------\n    pacf : 1d array\n        partial autocorrelations, nlags elements, including lag zero\n    confint : array, optional\n        Confidence intervals for the PACF. Returned if confint is not None.\n\n    Notes\n    -----\n    This solves yule_walker equations or ols for each desired lag\n    and contains currently duplicate calculations.\n    "
    if (method == 'ols'):
        ret = pacf_ols(x, nlags=nlags)
    elif (method in ['yw', 'ywu', 'ywunbiased', 'yw_unbiased']):
        ret = pacf_yw(x, nlags=nlags, method='unbiased')
    elif (method in ['ywm', 'ywmle', 'yw_mle']):
        ret = pacf_yw(x, nlags=nlags, method='mle')
    elif (method in ['ld', 'ldu', 'ldunbiase', 'ld_unbiased']):
        acv = acovf(x, unbiased=True)
        ld_ = levinson_durbin(acv, nlags=nlags, isacov=True)
        ret = ld_[2]
    elif (method in ['ldb', 'ldbiased', 'ld_biased']):
        acv = acovf(x, unbiased=False)
        ld_ = levinson_durbin(acv, nlags=nlags, isacov=True)
        ret = ld_[2]
    else:
        raise ValueError('method not available')
    if (alpha is not None):
        varacf = (1.0 / len(x))
        interval = (stats.norm.ppf((1.0 - (alpha / 2.0))) * np.sqrt(varacf))
        confint = np.array(lzip((ret - interval), (ret + interval)))
        confint[0] = ret[0]
        return (ret, confint)
    else:
        return ret
Partial autocorrelation estimated

Parameters
----------
x : 1d array
    observations of time series for which pacf is calculated
nlags : int
    largest lag for which pacf is returned
method : {'ywunbiased', 'ywmle', 'ols'}
    specifies which method for the calculations to use:

    - yw or ywunbiased : yule walker with bias correction in denominator
      for acovf. Default.
    - ywm or ywmle : yule walker without bias correction
    - ols - regression of time series on lags of it and on constant
    - ld or ldunbiased : Levinson-Durbin recursion with bias correction
    - ldb or ldbiased : Levinson-Durbin recursion without bias correction
alpha : float, optional
    If a number is given, the confidence intervals for the given level are
    returned. For instance if alpha=.05, 95 % confidence intervals are
    returned where the standard deviation is computed according to
    1/sqrt(len(x))

Returns
-------
pacf : 1d array
    partial autocorrelations, nlags elements, including lag zero
confint : array, optional
    Confidence intervals for the PACF. Returned if confint is not None.

Notes
-----
This solves yule_walker equations or ols for each desired lag
and contains currently duplicate calculations.
def pacf(x, nlags=40, method='ywunbiased', alpha=None):
    "\n    Partial autocorrelation estimated\n\n    Parameters\n    ----------\n    x : 1d array\n        observations of time series for which pacf is calculated\n    nlags : int\n        largest lag for which pacf is returned\n    method : {'ywunbiased', 'ywmle', 'ols'}\n        specifies which method for the calculations to use:\n\n        - yw or ywunbiased : yule walker with bias correction in denominator\n          for acovf. Default.\n        - ywm or ywmle : yule walker without bias correction\n        - ols - regression of time series on lags of it and on constant\n        - ld or ldunbiased : Levinson-Durbin recursion with bias correction\n        - ldb or ldbiased : Levinson-Durbin recursion without bias correction\n    alpha : float, optional\n        If a number is given, the confidence intervals for the given level are\n        returned. For instance if alpha=.05, 95 % confidence intervals are\n        returned where the standard deviation is computed according to\n        1/sqrt(len(x))\n\n    Returns\n    -------\n    pacf : 1d array\n        partial autocorrelations, nlags elements, including lag zero\n    confint : array, optional\n        Confidence intervals for the PACF. Returned if confint is not None.\n\n    Notes\n    -----\n    This solves yule_walker equations or ols for each desired lag\n    and contains currently duplicate calculations.\n    "
    if (method == 'ols'):
        ret = pacf_ols(x, nlags=nlags)
    elif (method in ['yw', 'ywu', 'ywunbiased', 'yw_unbiased']):
        ret = pacf_yw(x, nlags=nlags, method='unbiased')
    elif (method in ['ywm', 'ywmle', 'yw_mle']):
        ret = pacf_yw(x, nlags=nlags, method='mle')
    elif (method in ['ld', 'ldu', 'ldunbiase', 'ld_unbiased']):
        acv = acovf(x, unbiased=True)
        ld_ = levinson_durbin(acv, nlags=nlags, isacov=True)
        ret = ld_[2]
    elif (method in ['ldb', 'ldbiased', 'ld_biased']):
        acv = acovf(x, unbiased=False)
        ld_ = levinson_durbin(acv, nlags=nlags, isacov=True)
        ret = ld_[2]
    else:
        raise ValueError('method not available')
    if (alpha is not None):
        varacf = (1.0 / len(x))
        interval = (stats.norm.ppf((1.0 - (alpha / 2.0))) * np.sqrt(varacf))
        confint = np.array(lzip((ret - interval), (ret + interval)))
        confint[0] = ret[0]
        return (ret, confint)
    else:
        return ret