B
    Z                 @   s0   d Z ddlmZmZ ddlZG dd deZdS )zgBase classes for statistical test results

Created on Mon Apr 22 14:03:21 2013

Author: Josef Perktold
    )lzipzipNc               @   s<   e Zd ZdZdddZdddZdd	 Zd
d Zdd ZdS )AllPairsResultsa  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).

    hsNc                sj   || _ || _|d kr&t|d | _n|| _|| _ | _ d krRdd |D | _n fdd|D | _d S )N   c             S   s   g | ]}d |f qS )z%r ).0pairsr   r   5lib/python3.7/site-packages/statsmodels/stats/base.py
<listcomp>5   s    z,AllPairsResults.__init__.<locals>.<listcomp>c                s(   g | ] }d  |d   |d  f qS )z%s-%sr   r   r   )r   r	   )levelsr   r
   r   7   s   )	pvals_raw	all_pairsnpmaxn_levelsmultitest_methodr   all_pairs_names)selfr   r   r   r   r   r   )r   r
   __init__'   s    
zAllPairsResults.__init__c             C   s4   ddl m  m} |dkr | j}|j| j|dd S )zp-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.

        r   N)methodr   )statsmodels.stats.multiteststats	multitestr   Zmultipletestsr   )r   r   smtr   r   r
   pval_corrected;   s    zAllPairsResults.pval_correctedc             C   s   |   S )N)summary)r   r   r   r
   __str__H   s    zAllPairsResults.__str__c             C   s*   | j }t||f}|  |t| j < |S )zcreate a (n_levels, n_levels) array with corrected p_values

        this needs to improve, similar to R pairwise output
        )r   r   Zzerosr   r   r   )r   kZ	pvals_matr   r   r
   
pval_tableK   s    zAllPairsResults.pval_tablec             C   sz   ddl m  m} tdd | jD }d|j| j  }|dd|d d	   d
 7 }|ddd t| j| 	 D 7 }|S )zreturns text summarizing the results

        uses the default pvalue correction of the instance stored in
        ``self.multitest_method``
        r   Nc             s   s   | ]}t |V  qd S )N)len)r   Zssr   r   r
   	<genexpr>^   s    z*AllPairsResults.summary.<locals>.<genexpr>z0Corrected p-values using %s p-value correction

ZPairs    r   z	p-values

c             s   s   | ]\}}d ||f V  qdS )z	%s  %6.4gNr   )r   r	   Zpvr   r   r
   r!   c   s    )
r   r   r   r   r   Zmultitest_methods_namesr   joinr   r   )r   r   maxleveltextr   r   r
   r   W   s    zAllPairsResults.summary)r   NN)N)	__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r
   r      s    

r   )r+   Zstatsmodels.compat.pythonr   r   Znumpyr   objectr   r   r   r   r
   <module>   s   