ó
áp7]c        
   @   sW  d  d l  m Z m Z m Z m Z d  d l Z d  d l m Z d  d l	 m
 Z
 d  d l m Z d „  Z d „  Z d Z e d	 d
 „ ƒ Z e e _ d e f d „  ƒ  YZ e d k rSe j d d d d d d g d d d d d d g d d d d d d g g ƒ Z e e ƒ Z d d d d d d d d d d g
 Z e j d e ƒ GHe j ƒ  GHe j d  d! ƒ GHe j d d d d d g d  d! ƒ GHe j d d" ƒ GHe j d1 d2 d3 g d( d) e f d* e f d4 d5 g ƒZ e j d6 d7 d8 g d( d) e f d* e f g ƒZ e j d d d d g d d d d g d d d d g g d( e ƒZ d/ e f d0 „  ƒ  YZ n  d S(9   iÿÿÿÿ(   t   lranget   lmapt   iterkeyst	   iteritemsN(   t   stats(   t   SimpleTable(   t   nottestc         C   s4   y t  j |  ƒ } Wn t k
 r/ t j } n X| S(   sd   wrapper for scipy.stats.kurtosis that returns nan instead of raising Error

    missing options
    (   R   t   kurtosist
   ValueErrort   npt   nan(   t   at   res(    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt	   _kurtosis   s
    c         C   s4   y t  j |  ƒ } Wn t k
 r/ t j } n X| S(   s`   wrapper for scipy.stats.skew that returns nan instead of raising Error

    missing options
    (   R   t   skewR   R	   R
   (   R   R   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   _skew   s
    s@  
    Signs test.

    Parameters
    ----------
    samp : array-like
        1d array. The sample for which you want to perform the signs
        test.
    mu0 : float
        See Notes for the definition of the sign test. mu0 is 0 by
        default, but it is common to set it to the median.

    Returns
    --------
    M, p-value

    Notes
    -----
    The signs test returns

    M = (N(+) - N(-))/2

    where N(+) is the number of values above `mu0`, N(-) is the number of
    values below.  Values equal to `mu0` are discarded.

    The p-value for M is calculated using the binomial distrubution
    and can be intrepreted the same as for a t-test. The test-statistic
    is distributed Binom(min(N(+), N(-)), n_trials, .5) where n_trials
    equals N(+) + N(-).

    See Also
    --------
    scipy.stats.wilcoxon
    i    c         C   ss   t  j |  ƒ }  t  j |  | k ƒ } t  j |  | k  ƒ } | | d } t j t | | ƒ | | d ƒ } | | f S(   Ng       @g      à?(   R	   t   asarrayt   sumR   t
   binom_testt   min(   t   sampt   mu0t   post   negt   Mt   p(    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt	   sign_test@   s    "t   Describec           B   sw   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d	 d
 „ Z	 d	 d „ Z
 d d „ Z e e _ RS(   sü   
    Calculates descriptive statistics for data.

    Defaults to a basic set of statistics, "all" can be specified, or a list
    can be given.

    Parameters
    ----------
    dataset : array-like
        2D dataset for descriptive statistics.
    c         C   s$  | |  _  t d t d  d  g d t j d  d  g d t j d  d  g d t j d  d  g d t j d  d  g d t j	 d  d  g d t j
 d  d  g d |  j d  d  g d	 |  j d  d  g d
 t j d  d  g d t j d  d  g d d „  d  d  g d t j d  d  g d |  j d  d  g ƒ |  _ d  |  _ d  |  _ d  S(   Nt   obst   meant   stdR   t   maxt   ptpt   vart   mode_valt   mode_bint   medianR   t   ussc         S   s    t  j t  j |  ƒ d d d ƒS(   Ni   t   axisi    (   R	   R   R   (   t   x(    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   <lambda>i   t    R   t   percentiles(   t   datasett   dictt   lent   NoneR	   R   R   R   R   R    R!   t	   _mode_valt	   _mode_binR$   R   R   R   t   _percentilest
   univariatet
   _arraytypet   _columns_list(   t   selfR+   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   __init__V   s$    		c      
   C   s)   g  d
 D] } t  j | | ƒ ^ q } | S(   Ni   i   i
   i   i2   iK   iZ   i_   ic   (	   i   i   i
   i   i2   iK   iZ   i_   ic   (   R   t   scoreatpercentile(   R5   R'   t   perR   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR1      s    "c         C   s   t  j | ƒ d d S(   Ni    (   R   t   mode(   R5   R'   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR/   …   s    c         C   s   t  j | ƒ d d S(   Ni   i    (   R   R9   (   R5   R'   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR0   ‡   s    c         C   s^   |  j  j j s d |  _ n? |  j  j j r6 d |  _ n$ |  j d k sZ |  j d k sZ t ‚ d S(   s   if not a sctructured arrayt   homogt   sctructN(   R+   t   dtypet   namesR3   t   AssertionError(   R5   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   _array_typerŠ   s
    c            s‰   ‡  ‡ f d †  } ‡  ‡ f d †  } | ƒ  r; | ƒ  r; d S| ƒ  rR | ƒ  rR d S| ƒ  s… | ƒ  s… t  d t ˆ j ˆ  d ƒ ƒ ‚ d S(   sŠ   
        Check whether self.dataset.[col][0] behaves like a string, numbern
        unknown. `numpy.lib._iotools._is_string_like`
        c              s6   y ˆ j  ˆ  d d Wn t t f k
 r1 t SXt S(   Ni    R)   (   R+   t	   TypeErrorR   t   Falset   True(    (   t   colR5   (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   string_likeš   s
    c              s6   y ˆ j  ˆ  d d Wn t t f k
 r1 t SXt S(   Ni    g      ð?(   R+   R@   R   RA   RB   (    (   RC   R5   (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   number_like£   s
    t   numbert   strings               Not sure of dtypei    N(   R>   t   strR+   (   R5   RC   RD   RE   (    (   RC   R5   sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   _is_dtype_like•   s    	t   basict   allt   autoc            s  |  j  d k r |  j ƒ  n  | d k r1 d$ } nP | d k rp d d d d d d d	 d
 d d d d d d g } n x | D] } qw Wd d l ‰ ‡ f d †  ‰  t ‡  f d †  d% Dƒ ƒ } d | k r|  j j | ƒ | j d ƒ } t t	 | ƒ ƒ | | | d +n  t
 g  t |  j ƒ D]  } | d | k r| d ^ qƒ r| d k r”g  |  _ |  j  d k rx|  j j j |  _ qüt |  j j d ƒ |  _ nh | |  _ |  j  d k rÞxM |  j D]! } | |  j j j k s¶t ‚ q¶Wn |  j |  j ƒ d  k süt ‚ |  j j }	 xç | D]ß } |  j | }
 |  j  d k r‡|  j |
 d <g  |  j D]2 } |  j | ƒ d  k rH|
 d |  j | ƒ ^ qH|
 d! <qg  |  j D] } d" t | ƒ ^ q‘|
 d <g  |  j D]) } |
 d |  j d d … | f ƒ ^ q»|
 d! <qW|  j | d# | ƒS|  j | d# | ƒSd S(&   s‘  
        Return a summary of descriptive statistics.

        Parameters
        ----------
        stats: list or str
            The desired statistics, Accepts 'basic' or 'all' or a list.
               'basic' = ('obs', 'mean', 'std', 'min', 'max')
               'all' = ('obs', 'mean', 'std', 'min', 'max', 'ptp', 'var',
                        'mode', 'meadian', 'skew', 'uss', 'kurtosis',
                        'percentiles')
        columns : list or str
          The columns/variables to report the statistics, default is 'all'
          If an object with named columns is given, you may specify the
          column names. For example
        RJ   R   R   R   R   R   RK   R    R!   R"   R#   R$   R%   R   R   R*   iÿÿÿÿNc            s   ‡  ‡ f d †  S(   Nc            s   ˆ j  j |  ˆ  ƒ S(   N(   R   R7   (   R'   (   R8   t   scipy(    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR(   á   R)   (    (   R8   (   RM   (   R8   sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   _funà   s    c         3   s.   |  ]$ } d  | ˆ  | ƒ d d g f Vq d S(   s	   perc_%02dN(   R.   (   t   .0R8   (   RN   (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pys	   <genexpr>ã   s   i   i   i
   i   i2   iK   iZ   i_   ic   i    R;   RF   i   s   Col t   orientation(   R   R   R   R   R   (	   i   i   i
   i   i2   iK   iZ   i_   ic   (   R3   R.   R?   t   scipy.statsR,   R2   t   updatet   indext   sortedR   t   anyR   R4   R+   R<   R=   R    t   shapeR>   RI   RH   t   print_summary(   R5   R   t   columnsRP   t   astatt   perdictt   idxt   aitemRC   t   columstypest   calc(    (   RN   RM   sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   summary²   sV    	  		"-*>c         C   s  d } | } |  j  d d } g  t t |  j  d d ƒ ƒ D]. } g  | D] } |  j  | d | ^ qH ^ q; } | d k sŸ | d k rÁ t | ƒ t | ƒ k  rÁ t d „  | Œ } | | } } n  t d d	 g t | ƒ d ƒ }	 t | | | d
 | d |	 ƒ}
 |
 S(   Ns   Summary StatisticsR   i   i   t   varcolsRL   c          W   s
   t  |  ƒ S(   N(   t   list(   t   row(    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR(   "  R)   t	   data_fmtss   %#8.4gt   titlet   txt_fmt(   R2   t   rangeR-   R   R,   R   (   R5   R   RP   Rd   t   headert   stubsRC   RY   t   datat   part_fmtt   table(    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyRW     s     O$ 	i    c         C   s   t  | | ƒ S(   N(   R   (   R5   R   R   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR   /  s    (   t   __name__t
   __module__t   __doc__R6   R1   R/   R0   R?   RI   R_   RW   R   t   _sign_test_doc(    (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR   J   s   	+					et   __main__i   i   i   i   i   i   i	   R   R   R   R   R   R    R$   R   R%   R   R   RP   R`   RK   R   t   aat   bt   bbt   ccR<   t   alphat   betat   gammas   |S1t   deltas   |S2t   TestSimpleTablec           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   s    d GHt  t ƒ } | j ƒ  GHd  S(   Nt   test_basic_1(   R   t   data1R_   (   R5   t   t1(    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyRz   _  s    c         C   s    d GHt  t ƒ } | j ƒ  GHd  S(   Nt   test_basic_2(   R   t   data2R_   (   R5   t   t2(    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR}   e  s    c         C   s    d GHt  t ƒ } | j ƒ  GHd  S(   Nt#   test_describe_summary_float_ndarray(   R   t   data3R_   (   R5   R|   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR€   j  s    c         C   s    d GHt  t ƒ } | j ƒ  GHd  S(   Nt   test_basic_4(   R   t   data4R_   (   R5   R|   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR‚   o  s    c         C   s/   d GHt  t ƒ } | j d d d d g ƒ GHd  S(   Nt   test_basic_1aR   RJ   RX   Ru   (   R   R{   R_   (   R5   R|   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR„   t  s    c         C   s,   d GHt  t ƒ } | j d d d d ƒ GHd  S(   Nt   test_basic_1bR   RJ   RX   RK   (   R   R{   R_   (   R5   R|   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR…   y  s    c         C   s&   d GHt  t ƒ } | j d d ƒ GHd  S(   Nt   test_basic_2aR   RK   (   R   R~   R_   (   R5   R   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyR†   ~  s    c         C   s!   t  t ƒ } | j d d ƒ GHd  S(   NR   RK   (   R   R   R_   (   t   aselfR|   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   test_basic_3ƒ  s    c         C   s!   t  t ƒ } | j d d ƒ GHd  S(   NR   RK   (   R   Rƒ   R_   (   R5   R|   (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   test_basic_4a‡  s    (   Rl   Rm   Rz   R}   R€   R‚   R„   R…   R†   Rˆ   R‰   (    (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyRy   \  s   								(   i   i   R   Rq   (   i   i   Rr   Rs   (   i   i   Rr   Rt   (   Rw   s   |S1(   Rx   s   |S2(   i   i   (   i   i   (   i   i   (    t   statsmodels.compat.pythonR    R   R   R   t   numpyR	   RM   R   t   statsmodels.iolib.tableR   t   statsmodels.tools.decoratorsR   R   R   Ro   R   Rn   t   objectR   Rl   t   arrayRƒ   R|   t   nopercR_   t   floatt   intR{   R~   R   Ry   (    (    (    sA   lib/python2.7/site-packages/statsmodels/stats/descriptivestats.pyt   <module>   sH   "		,	ï#				