U
    Kvf  ã                   @   s,   d Z ddlZddlmZ G dd„ deƒZdS )a?  
Empirical Likelihood Linear Regression Inference

The script contains the function that is optimized over nuisance parameters to
 conduct inference on linear regression parameters.  It is called by eltest
in OLSResults.


General References
-----------------

Owen, A.B.(2001). Empirical Likelihood. Chapman and Hall

é    N)Ú
_OptFunctsc                   @   s"   e Zd ZdZdd„ Zddd„ZdS )Ú
_ELRegOptszæ

    A class that holds functions to be optimized over when conducting
    hypothesis tests and calculating confidence intervals.

    Parameters
    ----------

    OLSResults : Results instance
        A fitted OLS result.
    c                 C   s   d S )N© )Úselfr   r   úA/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/emplike/elregress.pyÚ__init__    s    z_ELRegOpts.__init__Nc
                 C   s˜  |||< t  t  t  |¡|¡¡}
|||
< | |d¡}|| _||t  t  ||¡¡  t|ƒd¡ }|	sðt j	|dddd… }t j
|| dddd… | }|dd…dd…f | }|| dd…dd…f | }t j||fdd}t j||fdd}t  t|ƒ¡d|  }t  |jd ¡ dd¡}zR|  |||¡}dt  ||j¡ }d| d | | _t  
t  || j ¡¡}d| W S  t jjjk
r’   t j Y S X dS )a½  
        A function that is optimized over nuisance parameters to conduct a
        hypothesis test for the parameters of interest.

        Parameters
        ----------
        nuisance_params: 1darray
            Parameters to be optimized over.

        Returns
        -------
        llr : float
            -2 x the log-likelihood of the nuisance parameters and the
            hypothesized value of the parameter(s) of interest.
        é   r   )ZaxisNg      ð?éÿÿÿÿéþÿÿÿ)ÚnpÚint_ÚdeleteZarangeZreshapeÚ
new_paramsZsqueezeÚdotÚintZmeanÚsumZconcatenateZonesÚzerosÚshapeZ_modif_newtonÚTZnew_weightsÚlogZlinalgZLinAlgErrorÚinf)r   Znuisance_paramsZ
param_numsZendogZexogZnobsZnvarÚparamsZb0_valsZstochastic_exogZnuis_param_indexr   Zest_vectZ
exog_meansZ	exog_mom2Zmean_est_vectZmom2_est_vectZregressor_est_vectZwtsZx0Zeta_starZdenomZllrr   r   r   Ú_opt_nuis_regress#   sB    ÿ ÿÿ
ÿ
ÿ
z_ELRegOpts._opt_nuis_regress)NNNNNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s               ýr   )r   Znumpyr   Zstatsmodels.emplike.descriptiver   r   r   r   r   r   Ú<module>   s   