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.
- order
int,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.
- df
int,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
YuleWalkerResultNamedTuple instead of a plain tuple. IfNone(the default), the current tuple-returning behavior is used and aFutureWarningis issued. Ifinvis True, aYuleWalkerResultis 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. Setresult_object=Trueto opt in now, orresult_object=Falseto silence the warning and keep the current return type.YuleWalkerResultwill become mandatory in release 0.17.0 or after July 2028, whichever is later.
- Returns:
YuleWalkerResultIf
result_object=True, a NamedTuple with fieldsrho,sigma, andRinv(RinvisNoneunlessinv=True). SeeYuleWalkerResult.Otherwise(thedeprecateddefault),aplaintuplemadeupof:- rho
ndarray AR(p) coefficients computed using the Yule-Walker method.
- sigma
float The estimate of the residual standard deviation.
- Rinv
ndarray,optional The inverse of R. Only returned if
invis True, otherwiseNone.
See also
burgBurg’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
Ris the Toeplitz autocovariance matrix constructed from the estimated autocovariances at lags 0 throughp - 1,\phiis the vector of AR(p) parameters, andris the vector of estimated autocovariances at lags 1 throughp.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