
    M/Phk                        d dl mZ d dlZd dlZd dl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mZmZmZ d dlmZ d dlmZmZmZmZ d d	lmZ d dlmc mc mZ  d d
l!m"Z"  G d de j#                  Z$ G d de j%                  Z&dS )    )OrderedDictN)norm)
PandasData)cache_readonly)aicaiccbichqic)PrecisionWarning)_get_epsilonapprox_fprimeapprox_fprime_csapprox_hess_cs)pinv_extended)
_safe_condc                       e Zd ZdZ	 d fd	Zed             ZddZd Ze	d             Z
ej        d	             Zdd
Ze	d             Ze	d             Ze	 dd            ZddZ	 	 	 	 ddZd ZddZddZd Z xZS )StateSpaceMLEModelz{
    This is a temporary base model from ETS, here I just copy everything I need
    from statespace.mlemodel.MLEModel
    Nnonec                 b   t                                          |||||           || _        |                     | j                  \  | _        | _        t          | j        t                    | _	        | j        j
        d         | _        d| _        d | _        d | _        d | _        d | _        d S )N)endogexogdatesfreqmissingr   F)super__init___init_kwargsprepare_datadatar   r   
isinstancer   
use_pandasshapenobs_has_fixed_params_fixed_params_params_index_fixed_params_index_free_params_index)selfr   r   r   r   r   kwargs	__class__s          j/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tsa/exponential_smoothing/base.pyr   zStateSpaceMLEModel.__init__   s    
 	d%dG 	 	
 	
 	

 # !% 1 1$) < <
DI$TY
;; J$Q'	 "'!!#' "&    c                     t           NNotImplementedError)r   s    r,   r   zStateSpaceMLEModel.prepare_data8       !!r-   c                     t           r/   r0   )r)   r   r   r*   s       r,   clonezStateSpaceMLEModel.clone<   s    !!r-   c                 F    |D ]}|| j         vrt          d|z            d S )Nz$Invalid parameter name passed: "%s".)param_names
ValueError)r)   r6   
param_names      r,   _validate_can_fix_paramsz+StateSpaceMLEModel._validate_can_fix_params?   sH    % 	 	J!111 :ZG   2	 	r-   c                 *    t          | j                  S r/   )lenr6   r)   s    r,   k_paramszStateSpaceMLEModel.k_paramsF   s    4#$$$r-   c              #      K    j         Ei  _         t          t           j        t	          j         j                                       _         j                                         } j	        } j
        } j        }t          |                                          t           j                                                   z  }                     |            j                             |           t           fd j        D                        _         d _	         fd j                                         D              _
        t!          t          t	          j         j                                                 j
                             _        	 dV  | _	        | _         | _
        | _        dS # | _	        | _         | _
        | _        w xY w)a  
        Fix parameters to specific values (context manager)

        Parameters
        ----------
        params : dict
            Dictionary describing the fixed parameter values, of the form
            `param_name: fixed_value`. See the `param_names` property for valid
            parameter names.

        Examples
        --------
        >>> mod = sm.tsa.SARIMAX(endog, order=(1, 0, 1))
        >>> with mod.fix_params({'ar.L1': 0.5}):
                res = mod.fit()
        Nc                 @    g | ]}|j         v |j         |         fS  )r%   .0namer)   s     r,   
<listcomp>z1StateSpaceMLEModel.fix_params.<locals>.<listcomp>t   s>       4--- t)$/0---r-   Tc                 *    g | ]}j         |         S r@   )r&   )rB   keyr)   s     r,   rD   z1StateSpaceMLEModel.fix_params.<locals>.<listcomp>}   s.     $
 $
 $
(+Ds#$
 $
 $
r-   )r%   r   zipr6   nparanger=   r&   copyr$   r'   r(   setkeysr9   updatelist
difference)r)   paramscache_fixed_paramscache_has_fixed_paramscache_fixed_params_indexcache_free_params_indexall_fixed_param_namess   `      r,   
fix_paramszStateSpaceMLEModel.fix_paramsJ   s      ( %!#D!,D$bi&>&>??" "D
 "/4466!%!7#'#; "&"9 T%7%<%<%>%>!?!?? 	 	%%&;<<< 	!!&)))(    ,  
 
 "&$
 $
 $
 $
/3/A/F/F/H/H$
 $
 $
  #'	$-(())44T5MNN#
 #
	>EEE &<D"!3D'?D$&=D### &<D"!3D'?D$&=D#====s   F> >Gc                 |    |                      |          5   | j        |fi |}ddd           n# 1 swxY w Y   |S )a2  
        Fit the model with some parameters subject to equality constraints.

        Parameters
        ----------
        constraints : dict
            Dictionary of constraints, of the form `param_name: fixed_value`.
            See the `param_names` property for valid parameter names.
        start_params : array_like, optional
            Initial guess of the solution for the loglikelihood maximization.
            If None, the default is given by Model.start_params.
        **fit_kwds : keyword arguments
            fit_kwds are used in the optimization of the remaining parameters.

        Returns
        -------
        results : Results instance

        Examples
        --------
        >>> mod = sm.tsa.SARIMAX(endog, order=(1, 0, 1))
        >>> res = mod.fit_constrained({'ar.L1': 0.5})
        N)rV   fit)r)   constraintsstart_paramsfit_kwdsress        r,   fit_constrainedz"StateSpaceMLEModel.fit_constrained   s    0 __[)) 	5 	5$(<44844C	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5
s   155c                 >    t          | d          r| j        S t          )zP
        (array) Starting parameters for maximum likelihood estimation.
        _start_params)hasattrr_   r1   r<   s    r,   rZ   zStateSpaceMLEModel.start_params   s%    
 4)) 	&%%%%r-   c                     t          | d          r| j        S 	 d t          t          | j                            D             }n# t
          $ r g }Y nw xY w|S )z
        (list of str) List of human readable parameter names (for parameters
        actually included in the model).
        _param_namesc                     g | ]}d |z  S )zparam.%dr@   rB   is     r,   rD   z2StateSpaceMLEModel.param_names.<locals>.<listcomp>   s    OOOAaOOOr-   )r`   rb   ranger;   rZ   r1   )r)   namess     r,   r6   zStateSpaceMLEModel.param_names   su     4(( 	$$OOs4;L7M7M1N1NOOO&   Ls   +A AAc                     t           )z8
        Not implemented for state space models
        r0   )clsformular   subset	drop_colsargsr*   s          r,   from_formulazStateSpaceMLEModel.from_formula   s
     "!r-   c                 B   |j         dk    r'|j        d         dk    rt          j        |d          }| j        re|j        d         r|                     ||          \  }}}}nd }|j         dk     rt          j        |||          }nt          j        |||          }|S )N   )axisr      )indexrC   )rs   columns)	ndimr"   rH   squeezer!   _get_prediction_indexpdSeries	DataFrame)r)   r   	start_idxend_idxrg   _rs   s          r,   
_wrap_datazStateSpaceMLEModel._wrap_data   s     9q==TZ]a//:d+++D? 	Fz!} !%!;!;Iw!O!O1ay1}}yU???|DuEEEr-   c                     |sPi }|||d<   |||d<   || j         d         d         }|| j         d         d         } || ||fi |}	 ||	          }|S )Ncov_typecov_kwdsrX   r   rp   )_res_classes)
r)   rP   result
return_rawr   r   results_classwrapper_classresult_kwargsr\   s
             r,   _wrap_resultsz StateSpaceMLEModel._wrap_results   s      	(M#,4j)#,4j)$ $ 1% 8 ;$ $ 1% 8 ;-ffFFFFC"]3''Fr-   c                     t          |dd t          |                    }d|d<   d|d<   t          || j        ||          S )Ng       @Ttransformedcomplex_stepepsilonr*   )r   r;   r   loglike)r)   rP   r*   r   s       r,   _score_complex_stepz&StateSpaceMLEModel._score_complex_step   sS     vr4V== $}!%~g'-/ / / 	/r-   Fc                 <    d|d<   t          || j        ||          S )NTr   )r*   centered)r   r   )r)   rP   approx_centeredr*   s       r,   _score_finite_differencez+StateSpaceMLEModel._score_finite_difference  s.     $}VT\&&57 7 7 	7r-   c                 4   t          j        |d          }t          j        dt          d           |s t          |dd t          |                    }n"t          |dd t          |                    dz  }t          || j        |||          }|| j	        z  S )	Nrp   )ndminzkCalculation of the Hessian using finite differences is usually subject to substantial approximation errors.   
stacklevel   rr   )r   r*   r   )
rH   arraywarningswarnr   r   r;   r   r   nobs_effective)r)   rP   r   r*   r   hessians         r,   _hessian_finite_differencez-StateSpaceMLEModel._hessian_finite_difference	  s    &*** ! '!"		 	 	 	  	E"61dCKK@@GG"61dCKK@@1DG(E(/)8: : : $-..r-   c                     t          |ddt          |                    }d|d<   d|d<   t          || j        ||          }|| j        z  S )zy
        Hessian matrix computed by second-order complex-step differentiation
        on the `loglike` function.
        g      @NTr   r   r   )r   r;   r   r   r   )r)   rP   r*   r   r   s        r,   _hessian_complex_stepz(StateSpaceMLEModel._hessian_complex_step   sc     vr4V== $}!%~ DL'&B B B
 $-..r-   )NNNr   r/   )NN)NNNN)F)__name__
__module____qualname____doc__r   staticmethodr   r4   r9   propertyr=   
contextlibcontextmanagerrV   r]   rZ   r6   classmethodrn   r~   r   r   r   r   r   __classcell__r+   s   @r,   r   r      s         @F' ' ' ' ' '4 " " \"" " " "   % % X% @> @> @>D   8 & & X&   X 37" " " ["   2    6/ / /7 7 7 7/ / / /./ / / / / / /r-   r   c                       e Zd ZdZd fd	Zed             Zed             Zed             Zed             Z	ed             Z
ed	             Zed
             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zd Z	 ddZed             Zd dZ	 	 d!dZd Z	 	 	 	 	 d"dZ xZS )#StateSpaceMLEResultsa  
    Class to hold results from fitting a state space model.

    Parameters
    ----------
    model : MLEModel instance
        The fitted model instance
    params : ndarray
        Fitted parameters

    Attributes
    ----------
    model : Model instance
        A reference to the model that was fit.
    nobs : float
        The number of observations used to fit the model.
    params : ndarray
        The parameters of the model.
          ?c                 L    |j          _         |j         j         _        t                                          ||d |            j        j         _         j        j         _         j        j         _         j        rO j        j	        
                                 _	        t           j	                                                   _        nd  _	        g  _         fd j         j        pg D              _         j        j         _         j        j         _        d  _        d S )N)scalec                 0    g | ]}|j         v rd |z  n|S )z
%s (fixed))fixed_paramsrA   s     r,   rD   z1StateSpaceMLEResults.__init__.<locals>.<listcomp>X  s@     
 
 
 $(4+<#<#<L4$
 
 
r-   )r   
orig_endogr   r   r   modelr$   r'   r(   r%   rJ   rN   rL   r   r6   r#   r=   _rank)r)   r   rP   r   r+   s   `   r,   r   zStateSpaceMLEResults.__init__F  s   J	Z*
E::: "&!=#':#A "&*"? ! 	#!%!9!>!>!@!@D $T%7%<%<%>%> ? ?D!%D "D
 
 
 
.4"
 
 
 JO	
+


r-   c                     t           r/   r0   r<   s    r,   r   z#StateSpaceMLEResults.nobs_effectivec  r2   r-   c                      | j         | j        z
  S r/   )r   df_modelr<   s    r,   df_residzStateSpaceMLEResults.df_residg  s    "T]22r-   c                 B    t          | j        | j        | j                  S )z6
        (float) Akaike Information Criterion
        )r   llfr   r   r<   s    r,   r   zStateSpaceMLEResults.aick      
 48T0$-@@@r-   c                 B    t          | j        | j        | j                  S )zS
        (float) Akaike Information Criterion with small sample correction
        )r   r   r   r   r<   s    r,   r   zStateSpaceMLEResults.aiccr  s    
 DHd14=AAAr-   c                 B    t          | j        | j        | j                  S )z5
        (float) Bayes Information Criterion
        )r	   r   r   r   r<   s    r,   r	   zStateSpaceMLEResults.bicy  r   r-   c                     t           r/   r0   r<   s    r,   fittedvaluesz!StateSpaceMLEResults.fittedvalues  s
     "!r-   c                 B    t          | j        | j        | j                  S )z<
        (float) Hannan-Quinn Information Criterion
        )r
   r   r   r   r<   s    r,   r
   zStateSpaceMLEResults.hqic  s     DHd14=AAAr-   c                     t           )zY
        (float) The value of the log-likelihood function evaluated at `params`.
        r0   r<   s    r,   r   zStateSpaceMLEResults.llf  s
    
 "!r-   c                 X    t          j        t          j        | j                            S )z-
        (float) Mean absolute error
        )rH   meanabsresidr<   s    r,   maezStateSpaceMLEResults.mae  s     
 wrvdj))***r-   c                      | j         | j        z  S )z,
        (float) Mean squared error
        )sser#   r<   s    r,   msezStateSpaceMLEResults.mse  s    
 x$)##r-   c                 D   t          j        | j                  t           j        z  }t          j        |t
                    }d|| j        <   |t          j        | j                   z  }t          j	        t          j
        | j        |                             dz  ||<   |S )z
        (array) The p-values associated with the z-statistics of the
        coefficients. Note that the coefficients are assumed to have a Normal
        distribution.
        )dtypeTrr   )rH   
zeros_likezvaluesnan	ones_likeboolr(   isnanr   sfr   )r)   pvaluesmasks      r,   r   zStateSpaceMLEResults.pvalues  s     ---6|G4000(,T$%$,''''t|D'9 : :;;a?r-   c                     t           r/   r0   r<   s    r,   r   zStateSpaceMLEResults.resid  r2   r-   c                 :    t          j        | j        dz            S )z/
        (float) Sum of squared errors
        rr   )rH   sumr   r<   s    r,   r   zStateSpaceMLEResults.sse  s    
 vdjAo&&&r-   c                      | j         | j        z  S )z@
        (array) The z-statistics for the coefficients.
        )rP   bser<   s    r,   r   zStateSpaceMLEResults.zvalues  s    
 {TX%%r-   c                 
   ||dk    rd}nM|dk    r| j         }n?| j                            |          \  }}}t          |t                    r|j        }|dz  }|dk     r
| j         |z   }|| j         k    rt          d          |S )z?Returns a valid numeric start index for predictions/simulationsNstartr   endrp   z/Cannot anchor simulation outside of the sample.)r#   r   _get_index_locr    slicer   r7   )r)   anchorilocr}   s       r,   _get_prediction_start_indexz0StateSpaceMLEResults._get_prediction_start_index  s    >Vw..DDu__9DD226::JD!Q$&& "zAID!889t#D$)NOOOr-   TFc           	         | j         | j                            | j        ddd||          z  }t	          | j                  dk    rt          j        | j        | j                  }t	          | j                  | j	        k     rt          ||                   \  }}nt          j        t          j        g}}t          j        |          t          j        z  }|||<   nt          |          \  }}| j                            | j        dd           | j        6t          j                            t          j        |                    | _        | S )NTapprox)rP   r   includes_fixedmethodapprox_complex_stepr   r   )r   r   )r   r   r   rP   r;   r   rH   ix_r(   r=   r   r   r   rM   r   linalgmatrix_rankdiag)r)   r   r   evaluated_hessianr   tmpsingular_valuesneg_covs           r,   _cov_params_approxz'StateSpaceMLEResults._cov_params_approx  s4    !/$*2D2D; 3+ 3E 3
 3
 
 t !!A%%6$143JKKD4$%%55)67H7N)O)O&oo')vx_m$566?GGDMM)67H)I)I&Wo
$+4MMM:..rw/G/GHHDJxr-   c                 B    |                      | j        | j                  S )z
        (array) The variance / covariance matrix. Computed using the numerical
        Hessian approximated by complex step or finite differences methods.
        )r   _cov_approx_complex_step_cov_approx_centeredr<   s    r,   cov_params_approxz&StateSpaceMLEResults.cov_params_approx  s'     &&)4+D
 
 	
r-   Nc                    |d}| j         t          d          |dk    s|dk    rDddlm} t	          | d          r*t          j        | j        | j                  }| j	        |z
  }n| j
        }g }|Bt          | j        dd          }|rt          d	|z  |d
z            }nt          d|d
z            }|dk    rd	dgnddg}t          | j        j                  D ]|}	t	          | d          r| j        j         |	         |d         }
n| j         }
 ||
||dk              }|                    t          j        |          dd|f         j                   }t
          j        |         }nt+          d          |S )a"  
        Ljung-Box test for no serial correlation of standardized residuals

        Null hypothesis is no serial correlation.

        Parameters
        ----------
        method : {'ljungbox', 'boxpierce', None}
            The statistical test for serial correlation. If None, an attempt is
            made to select an appropriate test.
        lags : None, int or array_like
            If lags is an integer then this is taken to be the largest lag
            that is included, the test result is reported for all smaller lag
            length.
            If lags is a list or array, then all lags are included up to the
            largest lag in the list, however only the tests for the lags in the
            list are reported.
            If lags is None, then the default maxlag is min(10, nobs//5) for
            non-seasonal time series and min (2*m, nobs//5) for seasonal time
            series.

        Returns
        -------
        output : ndarray
            An array with `(test_statistic, pvalue)` for each endogenous
            variable and each lag. The array is then sized
            `(k_endog, 2, lags)`. If the method is called as
            `ljungbox = res.test_serial_correlation()`, then `ljungbox[i]`
            holds the results of the Ljung-Box test (as would be returned by
            `statsmodels.stats.diagnostic.acorr_ljungbox`) for the `i` th
            endogenous variable.

        See Also
        --------
        statsmodels.stats.diagnostic.acorr_ljungbox
            Ljung-Box test for serial correlation.

        Notes
        -----
        For statespace models: let `d` = max(loglikelihood_burn, nobs_diffuse);
        this test is calculated ignoring the first `d` residuals.

        Output is nan for any endogenous variable which has missing values.
        NljungboxWCannot compute test statistic when standardized forecast errors have not been computed.	boxpiercer   )acorr_ljungboxloglikelihood_burnseasonal_periodsrr      
   r   rp   filter_results)lagsr   z'Invalid serial correlation test method.)standardized_forecasts_errorr7   statsmodels.stats.diagnosticr   r`   rH   maximumr   nobs_diffuser#   r   getattrr   minrf   k_endogr   appendasarrayTc_r1   )r)   r   r   r   dr   outputr   colsre   xresultss               r,   test_serial_correlationz,StateSpaceMLEResults.test_serial_correlation  s   Z >F,4 H I I I Z6[#8#8CCCCCCt122 5Jt68IJJ
 "&Q!%!4F |#*4:7I1#M#M # 8q#33^q5HIIDDr>Q#677D#{22Aq66AD4:-.. > >4!122 :+HKABBOAA9A(.DV{-B   bj11!!!T':<====U6]FF% '1 2 2 2r-   	two-sidedc                    |d}| j         t          d          |dk    rt          | d          r9| j        j         dz  }t	          j        | j        | j                  }| j        |z
  }nH| j         dz  }|j	        dk    r*t	          j
        |          }|t          j        ddf         }| j        }d}t	          j
        |          }g }g }t          | j        j                  D ]}	t!          t	          j        |dz                      }
||	|
 df         }|t	          j        |                    }t'          |          ||	|||
z   f         }|t	          j        |                    }t'          |          dk     r%t)          j        d	|	z  d
           t          j        }dk     r%t)          j        d|	z  d
           t          j        }t	          j        |          t	          j        |          z  }|rddlm fd}fd}nddlm fd}fd}|                                }|dv r ||          }nS|dv rd|z  } ||          }n>|dv r+dt	          j         ||           ||                    z  }nt          d          |                    |           |                    |           t          j        ||f         }nt?          d          |S )a  
        Test for heteroskedasticity of standardized residuals

        Tests whether the sum-of-squares in the first third of the sample is
        significantly different than the sum-of-squares in the last third
        of the sample. Analogous to a Goldfeld-Quandt test. The null hypothesis
        is of no heteroskedasticity.

        Parameters
        ----------
        method : {'breakvar', None}
            The statistical test for heteroskedasticity. Must be 'breakvar'
            for test of a break in the variance. If None, an attempt is
            made to select an appropriate test.
        alternative : str, 'increasing', 'decreasing' or 'two-sided'
            This specifies the alternative for the p-value calculation. Default
            is two-sided.
        use_f : bool, optional
            Whether or not to compare against the asymptotic distribution
            (chi-squared) or the approximate small-sample distribution (F).
            Default is True (i.e. default is to compare against an F
            distribution).

        Returns
        -------
        output : ndarray
            An array with `(test_statistic, pvalue)` for each endogenous
            variable. The array is then sized `(k_endog, 2)`. If the method is
            called as `het = res.test_heteroskedasticity()`, then `het[0]` is
            an array of size 2 corresponding to the first endogenous variable,
            where `het[0][0]` is the test statistic, and `het[0][1]` is the
            p-value.

        Notes
        -----
        The null hypothesis is of no heteroskedasticity. That means different
        things depending on which alternative is selected:

        - Increasing: Null hypothesis is that the variance is not increasing
          throughout the sample; that the sum-of-squares in the later
          subsample is *not* greater than the sum-of-squares in the earlier
          subsample.
        - Decreasing: Null hypothesis is that the variance is not decreasing
          throughout the sample; that the sum-of-squares in the earlier
          subsample is *not* greater than the sum-of-squares in the later
          subsample.
        - Two-sided: Null hypothesis is that the variance is not changing
          throughout the sample. Both that the sum-of-squares in the earlier
          subsample is not greater than the sum-of-squares in the later
          subsample *and* that the sum-of-squares in the later subsample is
          not greater than the sum-of-squares in the earlier subsample.

        For :math:`h = [T/3]`, the test statistic is:

        .. math::

            H(h) = \sum_{t=T-h+1}^T  \tilde v_t^2
            \Bigg / \sum_{t=d+1}^{d+1+h} \tilde v_t^2

        where :math:`d` = max(loglikelihood_burn, nobs_diffuse)` (usually
        corresponding to diffuse initialization under either the approximate
        or exact approach).

        This statistic can be tested against an :math:`F(h,h)` distribution.
        Alternatively, :math:`h H(h)` is asymptotically distributed according
        to :math:`\chi_h^2`; this second test can be applied by passing
        `asymptotic=True` as an argument.

        See section 5.4 of [1]_ for the above formula and discussion, as well
        as additional details.

        TODO

        - Allow specification of :math:`h`

        References
        ----------
        .. [1] Harvey, Andrew C. 1990. *Forecasting, Structural Time Series*
               *Models and the Kalman Filter.* Cambridge University Press.
        Nbreakvarr   r   rr   rp   r   r   zgEarly subset of data for variable %d  has too few non-missing observations to calculate test statistic.r   zgLater subset of data for variable %d  has too few non-missing observations to calculate test statistic.)fc                 2                         |           S r/   cdftest_statistics	denom_dofr  	numer_dofs    r,   <lambda>z>StateSpaceMLEResults.test_heteroskedasticity.<locals>.<lambda>  s    'I:? :? r-   c                 2                         |           S r/   r   r  s    r,   r  z>StateSpaceMLEResults.test_heteroskedasticity.<locals>.<lambda>  s    'I:? :? r-   )chi2c                 6                         | z            S r/   r  r  r   r  r  s    r,   r  z>StateSpaceMLEResults.test_heteroskedasticity.<locals>.<lambda>  s!    !O3Y:@ :@ r-   c                 6                         | z            S r/   r  r"  s    r,   r  z>StateSpaceMLEResults.test_heteroskedasticity.<locals>.<lambda>  s!    !O3Y:@ :@ r-   )re   inc
increasing)r  dec
decreasingr   )2z2-sidedr  zInvalid alternative.z'Invalid heteroskedasticity test method.) r  r7   r`   r   rH   r  r   r  r#   ru   r	  newaxisr   rf   r   r  introundr   r;   r   r   r   r   scipy.statsr  r   lowerminimumr  r  r1   )r)   r   alternativeuse_fsquared_residr  r   r  p_valuesre   hnumer_residdenom_residtest_statistic
pval_lower
pval_upperp_valuer  r   r  r  r  s                     @@@@r,   test_heteroskedasticityz,StateSpaceMLEResults.test_heteroskedasticityX  s   d >F,4 H I I I Zt-.. 'DaG  Jt68IJJ
 "&Q $ A1 D %**$&J}$=$=M$1"*aaa-$@M!%!4J}55M OH4:-.. 9) 9)!!34455+ArssF3)28K+@+@*@A,,	+AqQwJ7)28K+@+@*@A,,	q==M #?AB#C ./$ $ $ $
 #%&Kq==M #?AB#C ./$ $ $ $
 #%&K!#!4!4rvk7J7J!J  @------"? "? "? "? "? "?J"? "? "? "? "? "?JJ 100000"@ "@ "@ "@ "@ "@J"@ "@ "@ "@ "@ "@J *//11"<<<(j88GG $>>>%'.%8N(j88GG $AAA"*"
>22"
>22# # GG
 %%;<<<&&~666((((U?H45FF% '1 2 2 2 r-   c                    |d}| j         t          d          |dk    rddlm} t	          | d          r t          j        | j        | j                  }nd}g }t          | j
        j                  D ]i}t	          | d          r| j        j         ||df         }n| j         }t          j        |           }|                     |||                              jnt          d          t          j        |          S )	a  
        Test for normality of standardized residuals.

        Null hypothesis is normality.

        Parameters
        ----------
        method : {'jarquebera', None}
            The statistical test for normality. Must be 'jarquebera' for
            Jarque-Bera normality test. If None, an attempt is made to select
            an appropriate test.

        See Also
        --------
        statsmodels.stats.stattools.jarque_bera
            The Jarque-Bera test of normality.

        Notes
        -----
        For statespace models: let `d` = max(loglikelihood_burn, nobs_diffuse);
        this test is calculated ignoring the first `d` residuals.

        In the case of missing data, the maintained hypothesis is that the
        data are missing completely at random. This test is then run on the
        standardized residuals excluding those corresponding to missing
        observations.
        N
jarqueberar   r   )jarque_berar   fiter_resultszInvalid normality test method.)r  r7   statsmodels.stats.stattoolsr=  r`   rH   r  r   r  rf   r   r  r   r   r  r1   r   )r)   r   r=  r  r  re   r   r   s           r,   test_normalityz#StateSpaceMLEResults.test_normality
  s5   8 >!F,4 H I I I \!!??????t122 Jt68IJJF4:-.. 8 8411 > /L122EE !=E'kk%+6677778 &&FGGGxr-   皙?c           	         ddl m} | j        }|d}|d}| j        j        rS| j        j        }||         }	d|	j        |	j        |	j        fz  g}
|d         }	|
dd|	j        |	j        |	j        fz  z   gz  }
n&t          |          dt          | j	                  z   g}
||j
        j        }	 |                     d	
          }n3# t          $ r& t          j        t          j        gdz  g          }Y nw xY w	 |                     d
          }nH# t          $ r; t          j        t          j        gdz  g                              ddd          }Y nw xY w	 |                     d
          }n3# t          $ r& t          j        t          j        gdz  g          }Y nw xY wt)          |t*                    s|g}dg}|                    d|d         gf           t/          dt1          |                    D ]#}|                    dd||         z   gf           $|ddd|
d         gfd|
d         gfgz  }d| j	        gfdd| j        z  gfg}t5          | d          r |                    dd| j        z  gf           |dd| j        z  gfdd| j        z  gfdd| j        z  gfgz  }t5          | d           r4| j        ,| j        j         r |                    d!d| j!        z  gf           n |                    d!d| j!        z  gf           t5          | d"          r|                    d#| j"        gf           d$ }d% ||ddddf                   fd& ||ddddf                   fd' ||dddf                   fd( ||dddf                   fg}d) ||dddf                   fd* ||dddf                   fd+ ||dddf                   fd, ||ddd-f                   fg} |            }|#                    | |||.           t1          | j$                  dk    r |r|%                    | || j&        d/0           |#                    | ||d.           g }t5          | d"          r)d1| j'        v r |                    | j'        d1                    | j(        t1          | j$                  t1          | j)                  z
  k     rx| *                                }t1          | j)                  dk    r't          j+        | j,        | j,                  }||         }|                    d2t[          |          z             |rDd3 t]          |          D             }|/                    dd4           |0                    |           |S )5a  
        Summarize the Model

        Parameters
        ----------
        alpha : float, optional
            Significance level for the confidence intervals. Default is 0.05.
        start : int, optional
            Integer of the start observation. Default is 0.
        model_name : str
            The name of the model used. Default is to use model class name.

        Returns
        -------
        summary : Summary instance
            This holds the summary table and text, which can be printed or
            converted to various output formats.

        See Also
        --------
        statsmodels.iolib.summary.Summary
        r   )SummaryNzStatespace Model Resultsz%02d-%02d-%02dz- z - r  )r   rr   r   rp   r<  r   )zDep. Variable:NzModel: z+ )zDate:N)zTime:NzSample:zNo. Observations:zLog Likelihoodz%#5.3frsquaredz
R-squared:z%#8.3fAICBICHQICr   Scaler   zCovariance Type:c                 B    d                     d | D                       gS )Nz, c                     g | ]}|d S )z.2fr@   rd   s     r,   rD   zBStateSpaceMLEResults.summary.<locals>.<lambda>.<locals>.<listcomp>  s    111a!zz111r-   )join)r   s    r,   r  z.StateSpaceMLEResults.summary.<locals>.<lambda>  s'    II11511122$
 r-   zLjung-Box (Q):zProb(Q):zHeteroskedasticity (H):zProb(H) (two-sided):zJarque-Bera (JB):z	Prob(JB):zSkew:z	Kurtosis:r   )gleftgrighttitleF)alphaxnameuse_tdescriptionzmCovariance matrix is singular or near-singular, with condition number %6.3g. Standard errors may be unstable.c                 *    g | ]\  }}d |dz    d| S )[rp   z] r@   )rB   re   texts      r,   rD   z0StateSpaceMLEResults.summary.<locals>.<listcomp>  s>       (/4#AE##T##  r-   z	Warnings:)1statsmodels.iolib.summaryrC  r   _index_dates_indexmonthdayyearstrr#   r+   r   r:  	ExceptionrH   r   r   r  reshaper@  r    rN   r  rf   r;   r   r`   rF  r   r	   r
   r   filter_concentratedr   r   add_table_2colsrP   add_table_paramsr6   r   r   r   
cov_paramsr   r(   r   	enumerateinsertadd_extra_txt)r)   rQ  r   rP  
model_namedisplay_paramsrC  r   ixr  samplehetlbjbtop_leftre   	top_right
format_str
diagn_leftdiagn_rightsummaryetextrd  r   s                           r,   rt  zStateSpaceMLEResults.summaryB  s   < 	655555 
=.E=E:" 	:"B5	A&!'15!&)AABF2At.!'15!&1IIIJJFF%jj%#di.."89F 1J	+..j.AACC 	+ 	+ 	+(RVHqL>**CCC	+	;--Z-@@BB 	; 	; 	;BF8a<.))11!Q::BBB	;	*$$L$99BB 	* 	* 	*BF8a<.))BBB	* *d++ 	&$J,-JqM?3444q#j//** 	: 	:AOOR$A"6!789999$&)	
 	
 !49+.48 345
	 4$$ 	IlX-E,FGHHHX()*X()*h*+,
 	
	 4)** 	A'3+? 4   'Htz,A+B!CDDDg4:(='>?@@@4$$ 	COO/$-ABBB
 

 zz"QQQ2X,778Bqqq!RxL112&

3qqq!t9(=(=>#ZZAAAqD	%:%:;	

 !**R1X"6"67**R1X../jjAAAqD**+**R1X../	
 '))% 	  	
 	
 	
 t{aN$$E)9 %    	
;b 	  	
 	
 	

 4$$ 	7$-)G)GLL}5666:T[))C0A,B,BBCC**J4$%%))vd5t7NOO'-
LL)*556    	) 3<U3C3C  E LLK(((!!%(((s7   *C -C10C15D AEEE, ,-FF)r   )TFr/   )r  T)rA  NNNT)r   r   r   r   r   r   r   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r   r   r   r  r:  r@  rt  r   r   s   @r,   r   r   1  s        (     : " " ^" 3 3 ^3 A A ^A B B ^B A A ^A " " ^" B B ^B " " ^" + + ^+ $ $ ^$   ^ " " ^" ' ' ^' & & ^&  & 9>   < 
 
 ^
Y Y Y Yv ;F&*p p p pd6  6  6 t \ \ \ \ \ \ \ \r-   r   )'collectionsr   r   r   numpyrH   pandasrx   r,  r   statsmodels.base.datar   statsmodels.tools.decoratorsr   statsmodels.tools.eval_measuresr   r   r	   r
   statsmodels.tools.sm_exceptionsr   statsmodels.tools.numdiffr   r   r   r   statsmodels.tools.toolsr   statsmodels.tsa.base.tsa_modeltsabase	tsa_modeltsbase statsmodels.tsa.statespace.toolsr   TimeSeriesModelr   TimeSeriesModelResultsr   r@   r-   r,   <module>r     s   # # # # # #                    , , , , , , 7 7 7 7 7 7 @ @ @ @ @ @ @ @ @ @ @ @ < < < < < <            2 1 1 1 1 1 / / / / / / / / / / / / 7 7 7 7 7 7V/ V/ V/ V/ V// V/ V/ V/rm
 m
 m
 m
 m
68 m
 m
 m
 m
 m
r-   