U
    Ãmœd‰  ã                   @   sD   d Z ddlZddlmZ ddlmZmZmZ ddd	„Z	dd
d„Z
dS )zb
Created on Sun Sep 25 21:23:38 2011

Author: Josef Perktold and Scipy developers
License : BSD-3
é    N)Ústats)Ú
array_likeÚ	bool_likeÚint_likeÚnormT© c                 C   s|  t | ddd�} t|dƒ}t|dƒ}tj| |d�}|j| }|r¼|dkrŽt tj| |d�|¡}t tj| d|d	�|¡}|| | }	t	j
 |	¡}
qÞt|ƒr²| | ¡}|j|f|žŽ }
qÞtd
ƒ‚n"t|ƒrÖ|j|f|žŽ }
ntdƒ‚t d|d ¡}dg| j }tdƒ||< t|ƒ}tdƒg| j }tdddƒ||< t|ƒ}tjd||  d | t |
¡t |
|  ¡  |d�}| | }|S )a«  
    Calculate the Anderson-Darling a2 statistic.

    Parameters
    ----------
    x : array_like
        The data to test.
    dist : {'norm', callable}
        The assumed distribution under the null of test statistic.
    fit : bool
        If True, then the distribution parameters are estimated.
        Currently only for 1d data x, except in case dist='norm'.
    params : tuple
        The optional distribution parameters if fit is False.
    axis : int
        If dist is 'norm' or fit is False, then data can be an n-dimensional
        and axis specifies the axis of a variable.

    Returns
    -------
    {float, ndarray}
        The Anderson-Darling statistic.
    ÚxN)ÚndimÚfitÚaxis)r   r   é   )Zddofr   z!dist must be 'norm' or a Callablez+if fit is false, then dist must be callableéÿÿÿÿé   g      ð?)r   r   r   ÚnpÚsortÚshapeZexpand_dimsZmeanZstdr   r   ZcdfÚcallabler
   Ú
ValueErrorZaranger	   ÚsliceÚtupleÚsumÚlogÚlog1p)r   Údistr
   Úparamsr   ÚyZnobsZxbarÚsÚwÚzÚiZsl1Zsl2Za2r   r   úR/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/statsmodels/stats/_adnorm.pyÚanderson_statistic   s<    




0ÿ
r!   c                 C   s–  t | dd|d�}| j| }|dd|  d|d    }t |¡dkrú|dkrx|d	k rxdt d
d|  d|d   ¡ }n€|dk r¤dt dd|  d|d   ¡ }nT|dk rÌt dd|  d|d   ¡}n,|dkrôt dd|  d|d   ¡}nd}n”t dd	ddg¡}dd„ }dd„ }dd„ }	dd„ }
dd„ }|||	|
|g}tj||dd �}tjt |¡ }t	d!ƒD ]"}||k}|| || ƒ||< �qj||fS )"aÄ  
    Anderson-Darling test for normal distribution unknown mean and variance.

    Parameters
    ----------
    x : array_like
        The data array.
    axis : int
        The axis to perform the test along.

    Returns
    -------
    ad2 : float
        Anderson Darling test statistic.
    pval : float
        The pvalue for hypothesis that the data comes from a normal
        distribution with unknown mean and variance.

    See Also
    --------
    statsmodels.stats.diagnostic.anderson_statistic
        The Anderson-Darling a2 statistic.
    statsmodels.stats.diagnostic.kstest_fit
        Kolmogorov-Smirnov test with estimated parameters for Normal or
        Exponential distributions.
    r   T)r   r
   r   r   g      è?g      @r   g        gš™™™™™É?ç¬Zd;ß*Àç)\�ÂõHY@ç�Âõ(\÷k@gÃõ(\�ÂÕ?ç‰A`åÐ¢ ÀçÙÎ÷SãeE@çòÒMbøM@g333333ã?ç AñcÌ]í?çV-²@ç®Gázö?é   çû\mÅþ²ô?ç¼t“Ö@çÎˆÒÞà“?c                 S   s   t jt  | ¡ S )N)r   ÚnanÚ	ones_like©Úad2ar   r   r    Ú<lambda>x   ó    znormal_ad.<locals>.<lambda>c                 S   s"   dt  dd|   d| d   ¡ S )Nr   r"   r#   r$   r   ©r   Úexpr1   r   r   r    r3   y   s   ÿc                 S   s"   dt  dd|   d| d   ¡ S )Nr   r%   r&   r'   r   r5   r1   r   r   r    r3   {   s   ÿc                 S   s   t  dd|   d| d   ¡S )Nr(   r)   r*   r   r5   r1   r   r   r    r3   }   r4   c                 S   s   t  dd|   d| d   ¡S )Nr,   r-   r.   r   r5   r1   r   r   r    r3   ~   r4   Úright)Zsideé   )
r!   r   r   Úsizer6   ÚarrayZsearchsortedr/   r0   Úrange)r   r   Zad2Únr2   ZpvalZboundsZpval0Zpval1Zpval2Zpval3Zpval4ZpvalliÚidxr   Úmaskr   r   r    Ú	normal_adI   s4    
$$  r?   )r   Tr   r   )r   )Ú__doc__Únumpyr   Zscipyr   Zstatsmodels.tools.validationr   r   r   r!   r?   r   r   r   r    Ú<module>   s
   
;