Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/statsmodels/tsa/arima/estimators/burg.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"""
2Burg's method for estimating AR(p) model parameters.
4Author: Chad Fulton
5License: BSD-3
6"""
7import numpy as np
9from statsmodels.tools.tools import Bunch
10from statsmodels.regression import linear_model
12from statsmodels.tsa.arima.specification import SARIMAXSpecification
13from statsmodels.tsa.arima.params import SARIMAXParams
16def burg(endog, ar_order=0, demean=True):
17 """
18 Estimate AR parameters using Burg technique.
20 Parameters
21 ----------
22 endog : array_like or SARIMAXSpecification
23 Input time series array, assumed to be stationary.
24 ar_order : int, optional
25 Autoregressive order. Default is 0.
26 demean : bool, optional
27 Whether to estimate and remove the mean from the process prior to
28 fitting the autoregressive coefficients.
30 Returns
31 -------
32 parameters : SARIMAXParams object
33 Contains the parameter estimates from the final iteration.
34 other_results : Bunch
35 Includes one component, `spec`, which is the `SARIMAXSpecification`
36 instance corresponding to the input arguments.
38 Notes
39 -----
40 The primary reference is [1]_, section 5.1.2.
42 This procedure assumes that the series is stationary.
44 This function is a light wrapper around `statsmodels.linear_model.burg`.
46 References
47 ----------
48 .. [1] Brockwell, Peter J., and Richard A. Davis. 2016.
49 Introduction to Time Series and Forecasting. Springer.
50 """
51 spec = SARIMAXSpecification(endog, ar_order=ar_order)
52 endog = spec.endog
54 # Workaround for statsmodels.tsa.stattools.pacf_burg which doesn't work
55 # on integer input
56 # TODO: remove when possible
57 if np.issubdtype(endog.dtype, np.dtype(int)):
58 endog = endog * 1.0
60 if not spec.is_ar_consecutive:
61 raise ValueError('Burg estimation unavailable for models with'
62 ' seasonal or otherwise non-consecutive AR orders.')
64 p = SARIMAXParams(spec=spec)
66 if ar_order == 0:
67 p.sigma2 = np.var(endog)
68 else:
69 p.ar_params, p.sigma2 = linear_model.burg(endog, order=ar_order,
70 demean=demean)
72 # Construct other results
73 other_results = Bunch({
74 'spec': spec,
75 })
77 return p, other_results