
    "g                     l    d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ  edd	      dd
       Zy)zg
Durbin-Levinson recursions for estimating AR(p) model parameters.

Author: Chad Fulton
License: BSD-3
    )deprecate_kwargN)Bunch)SARIMAXParams)SARIMAXSpecification)acovfunbiasedadjustedc           	      R   t        | |      x}}|j                  } |j                  st        d      t	        | |d||j
                        }|j
                  dk(  rdg}|d   g}n4t        j                  |j
                  |j
                  f      }	t        j                  |j
                  dz         }
|d   |d   z  |	d<   |d   |
d<   |
d   d|	d   d	z  z
  z  |
d<   t        d|j
                        D ]q  }|	|dz
  d|f   }||dz      t        j                  |||dd
         z
  |
|   z  |	||f<   ||	||f   |ddd
   z  z
  |	|d|f<   |
|   d|	||f   d	z  z
  z  |
|dz   <   s dgt        |j
                        D cg c]  }|	|d|dz   f    c}z   }|
}g }t        |j
                  dz         D ][  }t        |      }t        |      }|dk(  r||   |_        n t        j                  ||   ||   f   |_        |j                  |       ] t        d|i      }||fS c c}w )a}  
    Estimate AR parameters at multiple orders using Durbin-Levinson recursions.

    Parameters
    ----------
    endog : array_like or SARIMAXSpecification
        Input time series array, assumed to be stationary.
    ar_order : int, optional
        Autoregressive order. Default is 0.
    demean : bool, optional
        Whether to estimate and remove the mean from the process prior to
        fitting the autoregressive coefficients. Default is True.
    adjusted : bool, optional
        Whether to use the "adjusted" autocovariance estimator, which uses
        n - h degrees of freedom rather than n. This option can result in
        a non-positive definite autocovariance matrix. Default is False.

    Returns
    -------
    parameters : list of SARIMAXParams objects
        List elements correspond to estimates at different `ar_order`. For
        example, parameters[0] is an `SARIMAXParams` instance corresponding to
        `ar_order=0`.
    other_results : Bunch
        Includes one component, `spec`, containing the `SARIMAXSpecification`
        instance corresponding to the input arguments.

    Notes
    -----
    The primary reference is [1]_, section 2.5.1.

    This procedure assumes that the series is stationary.

    References
    ----------
    .. [1] Brockwell, Peter J., and Richard A. Davis. 2016.
       Introduction to Time Series and Forecasting. Springer.
    )ar_orderzgDurbin-Levinson estimation unavailable for models with seasonal or otherwise non-consecutive AR orders.T)r	   fftdemeannlagr   N   )r   r      )specr   )r   endogis_ar_consecutive
ValueErrorr   r   npzerosrangedotr   paramsr_appendr   )r   r   r   r	   r   max_specgamma	ar_paramssigma2Phivitmpoutpother_resultss                   m/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/tsa/arima/estimators/durbin_levinson.pydurbin_levinsonr)      s   P +58DDD8NNE %% $ % 	% %(V((*E AF	( hh))8+<+<=>HHX&&*+!HuQx'D	Qx!tq3t9a<'(!q(++, 	1Aac2A2g,Cq1usE!Ab&M(BBadJC1IAqD	C"I 55C2A2Jtq3q!t9a</0Aa!eH		1 FeH<M<M6NOc!Va!eV)nOO	 C8$$q() #Q/t$6ayAHuuYq\6!945AH

1  M ' Ps   H$)r   TF)__doc__statsmodels.compat.pandasr   numpyr   statsmodels.tools.toolsr   statsmodels.tsa.arima.paramsr   #statsmodels.tsa.arima.specificationr   statsmodels.tsa.stattoolsr   r)        r(   <module>r3      s;    6  ) 6 D + Z(Y )Yr2   