Ë
    ¢�DjÓ  ã                   ó`   — d Z ddlZddlmZ ddlmZ ddlmZ  G d„ de«      Z	 G d	„ d
e	«      Z
y)a   
This script contains empirical likelihood ANOVA.

Currently the script only contains one feature that allows the user to compare
means of multiple groups.

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

Owen, A. B. (2001). Empirical Likelihood. Chapman and Hall.
é    Né   )Ú
_OptFuncts)Úoptimize)Úchi2c                   ó   — e Zd ZdZd„ Zy)Ú	_ANOVAOptzX

    Class containing functions that are optimized over when
    conducting ANOVA.
    c                 ó†  — | j                   }| j                  }| j                  }t        j                  ||f«      }d}t        t        |«      «      D ]$  }|t        ||   «      z   }||   |z
  |||…|f<   |}Œ& |}	t        j                  |	j                  d   «      d|	j                  d   z  z  }
| j                  t        j                  |«      |	|
«      }dt        j                  ||	j                  «      z   }d|z  dz  |z  | _        t        j                  t        j                  || j                  z  «      «      }d|z  S )a7  
        Optimizes the likelihood under the null hypothesis that all groups have
        mean mu.

        Parameters
        ----------
        mu : float
            The common mean.

        Returns
        -------
        llr : float
            -2 times the llr ratio, which is the test statistic.
        r   g      ð?éþÿÿÿ)ÚnobsÚendogÚ
num_groupsÚnpÚzerosÚrangeÚlenÚonesÚshapeÚ_modif_newtonÚdotÚTÚnew_weightsÚsumÚlog)ÚselfÚmur   r   r   Úendog_asarrayÚobs_numÚarr_numÚnew_obs_numÚest_vectÚwtsÚeta_starÚdenomÚllrs                 ú_C:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\statsmodels/emplike/elanova.pyÚ_opt_common_muz_ANOVAOpt._opt_common_mu   s.  € ð �y‰yˆØ—
‘
ˆØ—_‘_ˆ
ÜŸ™ $¨
Ð!3Ó4ˆØˆÜœS ›ZÓ(ò 	"ˆGØ!¤C¨¨g©Ó$7Ñ7ˆKØ;@À¹>Øñ<ˆM˜' ;Ð.°Ð7Ñ8à!‰Gð		"ð
 !ˆÜ�g‰g�h—n‘n QÑ'Ó(¨B°(·.±.ÀÑ2CÑ,DÑEˆØ×%Ñ%¤b§h¡h¨zÓ&:¸HÀcÓJˆØ”R—V‘V˜H h§j¡jÓ1Ñ1ˆØ ™9 r™>¨EÑ1ˆÔÜ�f‰f”R—V‘V˜D 4×#3Ñ#3Ñ3Ó4Ó5ˆØ�C‰xˆó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   © r'   r%   r   r      s   „ ñó
r'   r   c                   ó   — e Zd ZdZd„ Zdd„Zy)ÚANOVAzë
    A class for ANOVA and comparing means.

    Parameters
    ----------

    endog : list of arrays
        endog should be a list containing 1 dimensional arrays.  Each array
        is the data collected from a certain group.
    c                 ó°   — || _         t        | j                   «      | _        d| _        | j                   D ]  }| j                  t        |«      z   | _        Œ! y )Nr   )r   r   r   r   )r   r   Úis      r%   Ú__init__zANOVA.__init__F   sF   € ØˆŒ
Ü˜dŸj™j›/ˆŒØˆŒ	Ø—‘ò 	+ˆAØŸ	™	¤C¨£FÑ*ˆD�Iñ	+r'   Nc                 ó®  — |�N| j                  |«      }dt        j                  || j                  dz
  «      z
  }|r|||| j                  fS |||fS t        j                  | j                   |dd¬«      }|d   }t        t        j                  |d   «      «      }dt        j                  || j                  dz
  «      z
  }|r|||| j                  fS |||fS )a(  
        Returns -2 log likelihood, the pvalue and the maximum likelihood
        estimate for a common mean.

        Parameters
        ----------

        mu : float
            If a mu is specified, ANOVA is conducted with mu as the
            common mean.  Otherwise, the common mean is the maximum
            empirical likelihood estimate of the common mean.
            Default is None.

        mu_start : float
            Starting value for commean mean if specific mu is not specified.
            Default = 0.

        return_weights : bool
            if TRUE, returns the weights on observations that maximize the
            likelihood.  Default is FALSE.

        Returns
        -------

        res: tuple
            The log-likelihood, p-value and estimate for the common mean.
        r   F)Úfull_outputÚdispr   )
r&   r   Úcdfr   r   r   Úfmin_powellÚfloatr   Úsqueeze)r   r   Úmu_startÚreturn_weightsr$   ÚpvalÚresÚ	mu_commons           r%   Úcompute_ANOVAzANOVA.compute_ANOVAM   sÞ   € ð8 ˆ>Ø×%Ñ% bÓ)ˆCØ”t—x‘x  T§_¡_°qÑ%8Ó9Ñ9ˆDÙØ˜D " d×&6Ñ&6Ð6Ð6à˜D "�}Ð$ä×&Ñ& t×':Ñ':¸HØ34¸5ôBˆCà�a‘&ˆCÜœbŸj™j¨¨Q©Ó0Ó1ˆIØ”t—x‘x  T§_¡_°qÑ%8Ó9Ñ9ˆDÙØ˜D )¨T×-=Ñ-=Ð=Ð=à˜D )Ð+Ð+r'   )Nr   r   )r(   r)   r*   r+   r1   r>   r,   r'   r%   r.   r.   :   s   „ ñ	ò+ô,,r'   r.   )r+   Únumpyr   Údescriptiver   Úscipyr   Úscipy.statsr   r   r.   r,   r'   r%   ú<module>rC      s1   ðñ
ó Ý #Ý Ý ô%�
ô %ôP?,ˆIõ ?,r'   