
    >h                     `    S r SSKrSSKJr  SSKJr  SSKJr   " S S\5      r	 " S	 S
\	5      r
g)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                       \ rS rSrSrS rSrg)	_ANOVAOpt   zL

Class containing functions that are optimized over when
conducting ANOVA.
c                    U R                   nU R                  nU R                  n[        R                  " X$45      nSn[        [        U5      5       H"  nU[        X7   5      -   nX7   U-
  XVU2U4'   UnM$     Un	[        R                  " U	R                  S   5      SU	R                  S   -  -  n
U R                  [        R                  " U5      X5      nS[        R                  " XR                  5      -   nSU-  S-  U-  U l        [        R                  " [        R                  " X R                  -  5      5      nSU-  $ )z
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                 nC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\statsmodels/emplike/elanova.py_opt_common_mu_ANOVAOpt._opt_common_mu   s    yy

__
$!34SZ(G!C$77K;@><M;.78!G	 )
 !gghnnQ'(B(..2C,DE%%bhhz&:HJRVVHjj119r>E1ffRVVD#3#3345Cx    )r   N)__name__
__module____qualname____firstlineno____doc__r'   __static_attributes__ r)   r&   r   r      s    
r)   r   c                   (    \ rS rSrSrS rSS jrSrg)ANOVA:   z
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                     Xl         [        U R                   5      U l        SU l        U R                    H   nU R                  [        U5      -   U l        M"     g )Nr   )r   r   r   r   )r   r   is      r&   __init__ANOVA.__init__F   s?    
djj/	A		CF*DI r)   Nc                    UbP  U R                  U5      nS[        R                  " X@R                  S-
  5      -
  nU(       a  XEXR                  4$ XEU4$ [
        R                  " U R                   USSS9nUS   n[        [        R                  " US   5      5      nS[        R                  " X@R                  S-
  5      -
  nU(       a  XEXpR                  4$ XEU4$ )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_ANOVAANOVA.compute_ANOVAM   s    8 >%%b)Ctxx__q%899D"&6&666"}$&&t':':H345BCa&CbjjQ01Itxx__q%899D)-=-===)++r)   )r   r   r   )Nr   r   )r*   r+   r,   r-   r.   r6   rD   r/   r0   r)   r&   r2   r2   :   s    	+,,r)   r2   )r.   numpyr   descriptiver   scipyr   scipy.statsr   r   r2   r0   r)   r&   <module>rJ      s1   
  #  %
 %P?,I ?,r)   