Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/statsmodels/tsa/arima/estimators/yule_walker.py : 33%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Yule-Walker method for estimating AR(p) model parameters.
4Author: Chad Fulton
5License: BSD-3
6"""
7from statsmodels.tools.tools import Bunch
8from statsmodels.regression import linear_model
10from statsmodels.tsa.arima.specification import SARIMAXSpecification
11from statsmodels.tsa.arima.params import SARIMAXParams
14def yule_walker(endog, ar_order=0, demean=True, unbiased=False):
15 """
16 Estimate AR parameters using Yule-Walker equations.
18 Parameters
19 ----------
20 endog : array_like or SARIMAXSpecification
21 Input time series array, assumed to be stationary.
22 ar_order : int, optional
23 Autoregressive order. Default is 0.
24 demean : bool, optional
25 Whether to estimate and remove the mean from the process prior to
26 fitting the autoregressive coefficients. Default is True.
27 unbiased : bool, optional
28 Whether to use the "unbiased" autocovariance estimator, which uses
29 n - h degrees of freedom rather than n. Note that despite the name, it
30 is only truly unbiased if the process mean is known (rather than
31 estimated) and for some processes it can result in a non-positive
32 definite autocovariance matrix. Default is False.
34 Returns
35 -------
36 parameters : SARIMAXParams object
37 Contains the parameter estimates from the final iteration.
38 other_results : Bunch
39 Includes one component, `spec`, which is the `SARIMAXSpecification`
40 instance corresponding to the input arguments.
42 Notes
43 -----
44 The primary reference is [1]_, section 5.1.1.
46 This procedure assumes that the series is stationary.
48 For a description of the effect of the "unbiased" estimate of the
49 autocovariance function, see 2.4.2 of [1]_.
51 References
52 ----------
53 .. [1] Brockwell, Peter J., and Richard A. Davis. 2016.
54 Introduction to Time Series and Forecasting. Springer.
55 """
56 spec = SARIMAXSpecification(endog, ar_order=ar_order)
57 endog = spec.endog
58 p = SARIMAXParams(spec=spec)
60 if not spec.is_ar_consecutive:
61 raise ValueError('Yule-Walker estimation unavailable for models with'
62 ' seasonal or non-consecutive AR orders.')
64 # Estimate parameters
65 method = 'unbiased' if unbiased else 'mle'
66 p.ar_params, sigma = linear_model.yule_walker(
67 endog, order=ar_order, demean=demean, method=method)
68 p.sigma2 = sigma**2
70 # Construct other results
71 other_results = Bunch({
72 'spec': spec,
73 })
75 return p, other_results