statsmodels.regression.linear_model.yule_walker#

statsmodels.regression.linear_model.yule_walker(x, order=1, method='adjusted', df=None, inv=False, demean=True, *, result_object=None)[source]#

Estimate AR(p) parameters from a sequence using the Yule-Walker equations. The method provides either adjusted or maximum-likelihood estimates, depending on the value of method.

Parameters:
xarray_like

A 1d array.

orderint, optional

The order of the autoregressive process. Default is 1.

method{‘adjusted’, ‘mle’}, optional

Method determines the denominator used to estimate the autocovariance at lag k. If ‘mle’, the denominator is n=X.shape[0], if ‘adjusted’ the denominator is n-k. The default is adjusted.

dfint, optional

Specifies the degrees of freedom. If df is supplied, then it is assumed the X has df degrees of freedom rather than n. Default is None.

invbool, optional

If inv is True the inverse of R is also returned. Default is False.

demeanbool, optional

True, the mean is subtracted from X before estimation.

result_objectbool, optional

Flag indicating whether to return the results as a YuleWalkerResult NamedTuple instead of a plain tuple. If None (the default), the current tuple-returning behavior is used and a FutureWarning is issued. If inv is True, a YuleWalkerResult is always returned.

Deprecated since version 0.15.0: In release 0.16.0 or after July 2027, whichever is later, the default will change to returning a YuleWalkerResult. Set result_object=True to opt in now, or result_object=False to silence the warning and keep the current return type. YuleWalkerResult will become mandatory in release 0.17.0 or after July 2028, whichever is later.

Returns:
YuleWalkerResult

If result_object=True, a NamedTuple with fields rho, sigma, and Rinv (Rinv is None unless inv=True). See YuleWalkerResult.

Otherwise (the deprecated default), a plain tuple made up of:
rhondarray

AR(p) coefficients computed using the Yule-Walker method.

sigmafloat

The estimate of the residual standard deviation.

Rinvndarray, optional

The inverse of R. Only returned if inv is True, otherwise None.

See also

burg

Burg’s AR estimator.

Notes

The Yule-Walker estimator is based on the autocorrelation structure of a weakly stationary process. Under stationarity, the covariance between two observations depends only on their lag:

\[\operatorname{Cov}(X_t, X_{t-k}) = \gamma_k.\]

For an AR(p) process, the Yule-Walker equations can be written as

\[R \phi = r,\]

where R is the Toeplitz autocovariance matrix constructed from the estimated autocovariances at lags 0 through p - 1, \phi is the vector of AR(p) parameters, and r is the vector of estimated autocovariances at lags 1 through p.

In practice, the theoretical autocovariances are replaced by their sample estimates.

The reference below formulates the Yule-Walker equations in terms of autocorrelations, whereas this implementation uses autocovariances. The two formulations are equivalent up to normalization by the variance.

References

http://www-stat.wharton.upenn.edu/~steele/Courses/956/ResourceDetails/YWSourceFiles/YW-Eshel.pdf

Examples

>>> import statsmodels.api as sm
>>> from statsmodels.datasets.sunspots import load
>>> data = load()
>>> rho, sigma = sm.regression.yule_walker(data.endog, order=4,
...                                        method="mle")
>>> rho
array([ 1.28310031, -0.45240924, -0.20770299,  0.04794365])
>>> sigma
16.808022730464351