def levinson_durbin(s, nlags=10, isacov=False):
    'Levinson-Durbin recursion for autoregressive processes\n\n    Parameters\n    ----------\n    s : array_like\n        If isacov is False, then this is the time series. If iasacov is true\n        then this is interpreted as autocovariance starting with lag 0\n    nlags : integer\n        largest lag to include in recursion or order of the autoregressive\n        process\n    isacov : boolean\n        flag to indicate whether the first argument, s, contains the\n        autocovariances or the data series.\n\n    Returns\n    -------\n    sigma_v : float\n        estimate of the error variance ?\n    arcoefs : ndarray\n        estimate of the autoregressive coefficients\n    pacf : ndarray\n        partial autocorrelation function\n    sigma : ndarray\n        entire sigma array from intermediate result, last value is sigma_v\n    phi : ndarray\n        entire phi array from intermediate result, last column contains\n        autoregressive coefficients for AR(nlags) with a leading 1\n\n    Notes\n    -----\n    This function returns currently all results, but maybe we drop sigma and\n    phi from the returns.\n\n    If this function is called with the time series (isacov=False), then the\n    sample autocovariance function is calculated with the default options\n    (biased, no fft).\n    '
    s = np.asarray(s)
    order = nlags
    if isacov:
        sxx_m = s
    else:
        sxx_m = acovf(s)[:(order + 1)]
    phi = np.zeros(((order + 1), (order + 1)), 'd')
    sig = np.zeros((order + 1))
    phi[(1, 1)] = (sxx_m[1] / sxx_m[0])
    sig[1] = (sxx_m[0] - (phi[(1, 1)] * sxx_m[1]))
    for k in range(2, (order + 1)):
        phi[(k, k)] = ((sxx_m[k] - np.dot(phi[1:k, (k - 1)], sxx_m[1:k][::(- 1)])) / sig[(k - 1)])
        for j in range(1, k):
            phi[(j, k)] = (phi[(j, (k - 1))] - (phi[(k, k)] * phi[((k - j), (k - 1))]))
        sig[k] = (sig[(k - 1)] * (1 - (phi[(k, k)] ** 2)))
    sigma_v = sig[(- 1)]
    arcoefs = phi[1:, (- 1)]
    pacf_ = np.diag(phi).copy()
    pacf_[0] = 1.0
    return (sigma_v, arcoefs, pacf_, sig, phi)
Levinson-Durbin recursion for autoregressive processes

Parameters
----------
s : array_like
    If isacov is False, then this is the time series. If iasacov is true
    then this is interpreted as autocovariance starting with lag 0
nlags : integer
    largest lag to include in recursion or order of the autoregressive
    process
isacov : boolean
    flag to indicate whether the first argument, s, contains the
    autocovariances or the data series.

Returns
-------
sigma_v : float
    estimate of the error variance ?
arcoefs : ndarray
    estimate of the autoregressive coefficients
pacf : ndarray
    partial autocorrelation function
sigma : ndarray
    entire sigma array from intermediate result, last value is sigma_v
phi : ndarray
    entire phi array from intermediate result, last column contains
    autoregressive coefficients for AR(nlags) with a leading 1

Notes
-----
This function returns currently all results, but maybe we drop sigma and
phi from the returns.

If this function is called with the time series (isacov=False), then the
sample autocovariance function is calculated with the default options
(biased, no fft).
def levinson_durbin(s, nlags=10, isacov=False):
    'Levinson-Durbin recursion for autoregressive processes\n\n    Parameters\n    ----------\n    s : array_like\n        If isacov is False, then this is the time series. If iasacov is true\n        then this is interpreted as autocovariance starting with lag 0\n    nlags : integer\n        largest lag to include in recursion or order of the autoregressive\n        process\n    isacov : boolean\n        flag to indicate whether the first argument, s, contains the\n        autocovariances or the data series.\n\n    Returns\n    -------\n    sigma_v : float\n        estimate of the error variance ?\n    arcoefs : ndarray\n        estimate of the autoregressive coefficients\n    pacf : ndarray\n        partial autocorrelation function\n    sigma : ndarray\n        entire sigma array from intermediate result, last value is sigma_v\n    phi : ndarray\n        entire phi array from intermediate result, last column contains\n        autoregressive coefficients for AR(nlags) with a leading 1\n\n    Notes\n    -----\n    This function returns currently all results, but maybe we drop sigma and\n    phi from the returns.\n\n    If this function is called with the time series (isacov=False), then the\n    sample autocovariance function is calculated with the default options\n    (biased, no fft).\n    '
    s = np.asarray(s)
    order = nlags
    if isacov:
        sxx_m = s
    else:
        sxx_m = acovf(s)[:(order + 1)]
    phi = np.zeros(((order + 1), (order + 1)), 'd')
    sig = np.zeros((order + 1))
    phi[(1, 1)] = (sxx_m[1] / sxx_m[0])
    sig[1] = (sxx_m[0] - (phi[(1, 1)] * sxx_m[1]))
    for k in range(2, (order + 1)):
        phi[(k, k)] = ((sxx_m[k] - np.dot(phi[1:k, (k - 1)], sxx_m[1:k][::(- 1)])) / sig[(k - 1)])
        for j in range(1, k):
            phi[(j, k)] = (phi[(j, (k - 1))] - (phi[(k, k)] * phi[((k - j), (k - 1))]))
        sig[k] = (sig[(k - 1)] * (1 - (phi[(k, k)] ** 2)))
    sigma_v = sig[(- 1)]
    arcoefs = phi[1:, (- 1)]
    pacf_ = np.diag(phi).copy()
    pacf_[0] = 1.0
    return (sigma_v, arcoefs, pacf_, sig, phi)