
    !g(                     H    d Z ddl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y)	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_likec                    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                  j                  |	      }
net        |      r%|j                  |       } |j                  |g| }
n5t        d
      t        |      r |j                  |g| }
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(                         5  t'        j*                  dd       d||   z  dz
  |z  t        j,                  |
      t        j.                  |
|          z   z  }t        j0                  ||      }ddd       | z
  }|S # 1 sw Y   xY w)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   norm   )ddofr   z!dist must be 'norm' or a Callablez+if fit is false, then dist must be callableignorez#divide by zero encountered in log1p)message   g      ?)r   r   r   npsortshapeexpand_dimsmeanstdr   r   cdfcallabler
   
ValueErroraranger	   slicetuplewarningscatch_warningsfilterwarningsloglog1psum)r   distr
   paramsr   ynobsxbarswzisl1sl2	ad_valuesa2s                   V/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/stats/_adnorm.pyanderson_statisticr3      s   0 	1c%A
C
CD&!D
A774=D
6>>>"''!$"7>Drvvaad;TBATQA

q!Ad^XXa[F$V$A@AAD>$V$AJKK
		!TAXA&166/CdCI
*C;-!&&
 CdD"%CI
*C		 	 	" )C	
 3Z#%-RXXqvg=N1NO	FF94() BI) )s   A-H??Ic                 J   t        | dd|      }| j                  |   }|dd|z  z   d|dz  z  z   z  }t        j                  |      dk(  r|dk\  r0|d	k  r+dt        j                  d
d|z  z   d|dz  z  z
        z
  }||fS |dk  r+dt        j                  dd|z  z   d|dz  z  z
        z
  }||fS |dk  r(t        j                  dd|z  z
  d|dz  z  z
        }||fS |dk  r(t        j                  dd|z  z
  d|dz  z  z         }||fS d}||fS t        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@Έ?)r5   r6   r:   r>   c                 N    t         j                  t        j                  |       z  S )N)r   nan	ones_likead2as    r2   <lambda>znormal_ad.<locals>.<lambda>}   s    RVVbll4&88     c                 P    dt        j                  dd| z  z   d| dz  z  z
        z
  S )Nr   r7   r8   r9   r   r   exprI   s    r2   rK   znormal_ad.<locals>.<lambda>~   s0    Qftm#ftqy&88": : rL   c                 P    dt        j                  dd| z  z   d| dz  z  z
        z
  S )Nr   r;   r<   r=   r   rN   rI   s    r2   rK   znormal_ad.<locals>.<lambda>   s0    QVd]"Vdai%77"9 9 rL   c                 J    t        j                  dd| z  z
  d| dz  z  z
        S )Nr?   r@   rA   r   rN   rI   s    r2   rK   znormal_ad.<locals>.<lambda>   s&    RVVFUT\$9D419<L$LM rL   c                 J    t        j                  dd| z  z
  d| dz  z  z         S )NrC   rD   rE   r   rN   rI   s    r2   rK   znormal_ad.<locals>.<lambda>   s&    RVVFUT\$9FTQY<N$NO rL   right)side   )
r3   r   r   sizerO   arraysearchsortedrG   rH   range)r   r   ad2nrJ   pvalboundspval0pval1pval2pval3pval4pvalliidxr-   masks                   r2   	normal_adrf   N   s    6 QVD
AC	A!dQh,Q./D	wwt}DLTE\rvvg58JJKKD: 99 E\rvvfv}4v	7IIJJD6 95 E\66&54</$2BBCD2 91 RZ66&54</&4192DDED. 9+ D* 9% 458:9MOue4oofd9vvT**q 	/A1HD"4:.DJ	/ 9rL   )r   T r   )r   )__doc__r   numpyr   scipyr   statsmodels.tools.validationr   r   r   r3   rf   rg   rL   r2   <module>rl      s&       H H<~?rL   