ó
áp7]c           @   sB   d  Z  d d l m Z m Z d d l Z d e f d     YZ d S(   sg   Base classes for statistical test results

Created on Mon Apr 22 14:03:21 2013

Author: Josef Perktold
i˙˙˙˙(   t   lzipt   zipNt   AllPairsResultsc           B   sG   e  Z d  Z d d d d  Z d d  Z d   Z d   Z d   Z RS(   s  Results class for pairwise comparisons, based on p-values

    Parameters
    ----------
    pvals_raw : array_like, 1-D
        p-values from a pairwise comparison test
    all_pairs : list of tuples
        list of indices, one pair for each comparison
    multitest_method : string
        method that is used by default for p-value correction. This is used
        as default by the methods like if the multiple-testing method is not
        specified as argument.
    levels : None or list of strings
        optional names of the levels or groups
    n_levels : None or int
        If None, then the number of levels or groups is inferred from the
        other arguments. It can be explicitly specified, if the inferred
        number is incorrect.

    Notes
    -----
    This class can also be used for other pairwise comparisons, for example
    comparing several treatments to a control (as in Dunnet's test).

    t   hsc         C   sž   | |  _  | |  _ | d  k r7 t j |  d |  _ n	 | |  _ | |  _ | |  _ | d  k r g  | D] } d | f ^ qe |  _ n6 g  | D]& } d | | d | | d f ^ q |  _ d  S(   Ni   s   %rs   %s-%si    (	   t	   pvals_rawt	   all_pairst   Nonet   npt   maxt   n_levelst   multitest_methodt   levelst   all_pairs_names(   t   selfR   R   R
   R   R	   t   pairs(    (    s5   lib/python2.7/site-packages/statsmodels/stats/base.pyt   __init__'   s    					&c         C   sD   d d l  j j } | d k r* |  j } n  | j |  j d | d S(   sş   p-values corrected for multiple testing problem

        This uses the default p-value correction of the instance stored in
        ``self.multitest_method`` if method is None.

        i˙˙˙˙Nt   methodi   (   t   statsmodels.stats.multitestt   statst	   multitestR   R
   t   multipletestsR   (   R   R   t   smt(    (    s5   lib/python2.7/site-packages/statsmodels/stats/base.pyt   pval_corrected:   s    c         C   s
   |  j    S(   N(   t   summary(   R   (    (    s5   lib/python2.7/site-packages/statsmodels/stats/base.pyt   __str__G   s    c         C   s;   |  j  } t j | | f  } |  j   | t |  j   <| S(   s   create a (n_levels, n_levels) array with corrected p_values

        this needs to improve, similar to R pairwise output
        (   R	   R   t   zerosR   R    R   (   R   t   kt	   pvals_mat(    (    s5   lib/python2.7/site-packages/statsmodels/stats/base.pyt
   pval_tableJ   s    	c         C   s   d d l  j j } t d   |  j D  } d | j |  j } | d d | d d d	 7} | d
 j d   t |  j |  j	    D  7} | S(   s   returns text summarizing the results

        uses the default pvalue correction of the instance stored in
        ``self.multitest_method``
        i˙˙˙˙Nc         s   s   |  ] } t  |  Vq d  S(   N(   t   len(   t   .0t   ss(    (    s5   lib/python2.7/site-packages/statsmodels/stats/base.pys	   <genexpr>\   s    s0   Corrected p-values using %s p-value correction

t   Pairst    i   i   s	   p-values
s   
c         s   s%   |  ] \ } } d  | | f Vq d S(   s	   %s  %6.4gN(    (   R   R   t   pv(    (    s5   lib/python2.7/site-packages/statsmodels/stats/base.pys	   <genexpr>a   s    (
   R   R   R   R   R   t   multitest_methods_namesR
   t   joinR   R   (   R   R   t   maxlevelt   text(    (    s5   lib/python2.7/site-packages/statsmodels/stats/base.pyR   U   s     N(	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/statsmodels/stats/base.pyR      s   		(   R)   t   statsmodels.compat.pythonR    R   t   numpyR   t   objectR   (    (    (    s5   lib/python2.7/site-packages/statsmodels/stats/base.pyt   <module>   s   