
    Vfd                     B    d Z ddlZddlmZ ddlmZmZmZ d
dZ	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                 J   t          | dd          } t          |d          }t          |d          }t          j        | |          }|j        |         }|r|dk    r{t          j        t          j        | |          |          }t          j        t          j        | d|	          |          }||z
  |z  }	t          j
                            |	          }
not          |          r$|                    |           } |j        |g|R  }
n<t          d
          t          |          r |j        |g|R  }
nt          d          t          j        d|dz             }dg| j        z  }t#          d          ||<   t%          |          }t#          d          g| j        z  }t#          ddd          ||<   t%          |          }t          j        d||         z  dz
  |z  t          j        |
          t          j        |
|                    z   z  |          }| |z
  }|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      )ddofr   z!dist must be 'norm' or a Callablez+if fit is false, then dist must be callable   g      ?)r   r   r   npsortshapeexpand_dimsmeanstdr   r   cdfcallabler   
ValueErroraranger   slicetuplesumloglog1p)r
   distr   paramsr   ynobsxbarswzisl1sl2a2s                  9lib/python3.11/site-packages/statsmodels/stats/_adnorm.pyanderson_statisticr.      s   0 	1c%%%A
C

CD&!!D
A74=D
 L6>>>"'!$"7"7"7>>Drvaad;;;TBBATQA
q!!AAd^^ 	BXXa[[F$V$$$AA@AAAD>> 	L$V$$$AAJKKK
	!TAXA&16/CdCI
**C;;-!&
 CdD"%%CI
**C
AcF
S D(BF1II!C&8I8I,IJ	 	 	A
BI    c                 >   t          | dd|          }| j        |         }|dd|z  z   d|dz  z  z   z  }t          j        |          dk    r|dk    r.|d	k     r(dt          j        d
d|z  z   d|dz  z  z
            z
  }n|dk     r'dt          j        dd|z  z   d|dz  z  z
            z
  }n|dk     r$t          j        dd|z  z
  d|dz  z  z
            }n|dk    r$t          j        dd|z  z
  d|dz  z  z             }nd}nt          j        g d          }d }d }d }	d }
d }|||	|
|g}t          j        ||d           }t          j        t          j        |          z  }t          d!          D ]"}||k    } ||         ||                   ||<   #||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           皙?Zd;*)\HY@(\k@(\?A`Т SeE@MbM@333333? Ac]?V-@Gz?   \m?t@Έ?)r1   r2   r6   r:   c                 D    t           j        t          j        |           z  S )N)r   nan	ones_likead2as    r-   <lambda>znormal_ad.<locals>.<lambda>x   s    RVbl4&8&88 r/   c                 N    dt          j        dd| z  z   d| dz  z  z
            z
  S )Nr   r3   r4   r5   r   r   exprE   s    r-   rG   znormal_ad.<locals>.<lambda>y   s3    Qftm#ftqy&88": ": : r/   c                 N    dt          j        dd| z  z   d| dz  z  z
            z
  S )Nr   r7   r8   r9   r   rI   rE   s    r-   rG   znormal_ad.<locals>.<lambda>{   s3    QVd]"Vdai%77"9 "9 9 r/   c                 H    t          j        dd| z  z
  d| dz  z  z
            S )Nr;   r<   r=   r   rI   rE   s    r-   rG   znormal_ad.<locals>.<lambda>}   s'    RVFUT\$9D419<L$LMM r/   c                 H    t          j        dd| z  z
  d| dz  z  z             S )Nr?   r@   rA   r   rI   rE   s    r-   rG   znormal_ad.<locals>.<lambda>~   s'    RVFUT\$9FTQY<N$NOO r/   right)side   )
r.   r   r   sizerJ   arraysearchsortedrC   rD   range)r
   r   ad2nrF   pvalboundspval0pval1pval2pval3pval4pvalliidxr)   masks                   r-   	normal_adra   I   s   6 QVD
A
A
AC	A!dQh,Q./D	wt}}DLLTE\\rvg58JJKKKDDE\\rvfv}4v	7IIJJJDDE\\6&54</$2BBCCDDRZZ6&54</&4192DDEEDDDD 4445588: :9 9MMOOue4ofd999vT***q 	/ 	/A1HD"4:..DJJ9r/   )r   Tr   r   )r   )__doc__numpyr   scipyr   statsmodels.tools.validationr   r   r   r.   ra   r   r/   r-   <module>rf      s               H H H H H H H H H H8 8 8 8v? ? ? ? ? ?r/   