
p7]c           @  s[  d  Z  d d l m Z d d l m Z d d l Z d d l m Z d e	 d# d d  Z
 d d	  Z e d
 k rWe j d d d d d d d d d d d d d d d d d d d d g  Z e j d d  g  Z e e  \ Z Z e e e  e e e e g  e e
 e e j   e j   d! e j d" d  e e
 e d! e j d" e	  n  d S($   sb   
Created on Sun Sep 25 21:23:38 2011

Author: Josef Perktold and Scipy developers
License : BSD-3
i(   t   print_function(   t   rangeN(   t   statst   normi    c         C  s  t  j |   }  t  j |  d | } | j | } | r | d k r t  j t  j |  d | |  } t  j t  j |  d d d | |  } | | | }	 t j j	 |	  }
 qt
 |  r| j |   } | j	 | |  }
 t |
  qn- t
 |  r| j	 | |  }
 n t d   t  j d | d  } d	 g |  j } t d	  | | <t |  } t d	  g |  j } t d	 d	 d  | | <t |  } t  j d | | d | t  j |
  t  j d |
 |  d | } | | } | S(
   s  calculate anderson-darling A2 statistic

    Parameters
    ----------
    x : array_like
        data
    dist : 'norm' or callable
        null distribution for the 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
        optional distribution parameters if fit is False
    axis : integer
        If dist is 'norm' or fit is False, then data can be an n-dimensional
        and axis specifies the axis of a variable

    Returns
    -------
    ad2 : float or ndarray
        Anderson-Darling statistic


    t   axisR   t   ddofi   s/   if fit is false, then dist needs to be callableii   g      ?N(   t   npt   asarrayt   sortt   shapet   expand_dimst   meant   stdR   R   t   cdft   callablet   fitt   printt
   ValueErrort   aranget   Nonet   ndimt   slicet   tuplet   sumt   log(   t   xt   distR   t   paramsR   t   yt   Nt   xbart   st   wt   zt   it   sl1t   sl2t   St   A2(    (    s8   lib/python2.7/site-packages/statsmodels/stats/_adnorm.pyt   anderson_statistic   s4    !'Gc         C  s  t  |  d d d t d | } |  j | } | d d | d | d } t j |  d k rC| d	 k r | d
 k  r d t j d d | d | d  } q	| d k  r d t j d d | d | d  } q	| d k  rt j d d | d | d  } q	| d k r:t j d d | d | d  } q	d	 } n t j d	 d
 d d g  } d   } d   } d   }	 d   }
 d   } | | |	 |
 | g } t j | | d d  } t j t j	 |  } x8 t
 d!  D]* } | | k } | | | |  | | <qW| | f S("   s{  Anderson-Darling test for normal distribution unknown mean and variance

    Parameters
    ----------
    x : array_like
        data array, currently only 1d

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

    R   R   R   R   i   g      ?g      @i   g        g?gZd;*g)\HY@g(\k@g(\?gA`Т gSeE@gMbM@g333333?g Ac]?gV-@gGz?i   g\m?gt@gΈ?c         S  s   t  j t  j |   S(   N(   R   t   nant	   ones_like(   t   ad2a(    (    s8   lib/python2.7/site-packages/statsmodels/stats/_adnorm.pyt   <lambda>n   t    c         S  s%   d t  j d d |  d |  d  S(   Ni   gZd;*g)\HY@g(\k@i   (   R   t   exp(   R*   (    (    s8   lib/python2.7/site-packages/statsmodels/stats/_adnorm.pyR+   o   R,   c         S  s%   d t  j d d |  d |  d  S(   Ni   gA`Т gSeE@gMbM@i   (   R   R-   (   R*   (    (    s8   lib/python2.7/site-packages/statsmodels/stats/_adnorm.pyR+   p   R,   c         S  s!   t  j d d |  d |  d  S(   Ng Ac]?gV-@gGz?i   (   R   R-   (   R*   (    (    s8   lib/python2.7/site-packages/statsmodels/stats/_adnorm.pyR+   q   R,   c         S  s!   t  j d d |  d |  d  S(   Ng\m?gt@gΈ?i   (   R   R-   (   R*   (    (    s8   lib/python2.7/site-packages/statsmodels/stats/_adnorm.pyR+   r   R,   t   sidet   righti   (   R'   t   TrueR	   R   t   sizeR-   t   arrayt   searchsortedR(   R)   R   (   R   R   t   ad2t   nR*   t   pvalt   boundst   pval0t   pval1t   pval2t   pval3t   pval4t   pvallit   idxR"   t   mask(    (    s8   lib/python2.7/site-packages/statsmodels/stats/_adnorm.pyt	   normal_adH   s4    **&&						t   __main__g_vOgBiqg o_y?g/$g47ؿg^K=Ϳg}?5^gZӼ˿gׁsF?g6<R?gGr׿g	?gz6ÿg7[ Ag2U0*g$~?gea?gJY8Ϳgc]KgCl?g"op?gVd?R   R   (    (   t   __doc__t
   __future__R    t   statsmodels.compat.pythonR   t   numpyR   t   scipyR   R0   R'   R@   t   __name__R2   R   t   r_resR4   R6   R   R   R   R   (    (    (    s8   lib/python2.7/site-packages/statsmodels/stats/_adnorm.pyt   <module>   s    :73