
    M/Ph                     `    d Z ddlmZ ddlZddlmZ  G d de          Z G d d          ZdS )	zgBase classes for statistical test results

Created on Mon Apr 22 14:03:21 2013

Author: Josef Perktold
    )lzipN)Holderc                   >     e Zd ZdZd	 fd	Zd Zd Zd Zd
dZ xZ	S )HolderTuplez Holder class with indexing

    Nc                       t                      j        di | |"t           fd|D                        _        d S  j         j        f _        d S )Nc              3   8   K   | ]}t          |          V  d S N)getattr).0attselfs     V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/stats/base.py	<genexpr>z'HolderTuple.__init__.<locals>.<genexpr>   s-      DDcwtS11DDDDDD     )super__init__tuple	statisticpvalue)r   tuple_kwds	__class__s   `  r   r   zHolderTuple.__init__   sc      4   DDDDVDDDDDDJJJ.$+6DJJJr   c              #   $   K   | j         E d {V  d S r	   r   r   s    r   __iter__zHolderTuple.__iter__   s&      :r   c                     | j         |         S r	   r   )r   idxs     r   __getitem__zHolderTuple.__getitem__   s    z#r   c                 *    t          | j                  S r	   )lenr   r   s    r   __len__zHolderTuple.__len__   s    4:r   Tc                 T    t          j        t          | j                  ||          S )N)dtypecopy)nparraylistr   )r   r%   r&   s      r   	__array__zHolderTuple.__array__!   s#    xTZ((DAAAAr   r	   )NT)
__name__
__module____qualname____doc__r   r   r    r#   r*   __classcell__)r   s   @r   r   r      s         7 7 7 7 7 7      B B B B B B B Br   r   c                   8    e Zd ZdZ	 	 d	dZd
dZd Zd Z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 : str
        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 : {list[str], None}
        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                     || _         || _        |t          j        |          dz   | _        n|| _        || _        | _        d |D             | _        d S fd|D             | _        d S )N   c                     g | ]}|S r   r   )r   pairss     r   
<listcomp>z,AllPairsResults.__init__.<locals>.<listcomp>M   s'     $ $ $!&5$ $ $r   c                 l    g | ]0}d                      |d                  |d                            1S )z{}-{}r   r4   )format)r   r6   levelss     r   r7   z,AllPairsResults.__init__.<locals>.<listcomp>Q   sP     $ $ $  58$fU1X&6 $ $ $r   )	pvals_raw	all_pairsr'   maxn_levelsmultitest_methodr:   all_pairs_names)r   r;   r<   r?   r:   r>   s       ` r   r   zAllPairsResults.__init__@   s    ""F9--1DMM$DM 0>$ $*3$ $ $D   $ $ $ $  )$ $ $D   r   c                 j    ddl mc m} || j        }|                    | j        |          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)methodr4   )statsmodels.stats.multiteststats	multitestr?   multipletestsr;   )r   rB   smts      r   pval_correctedzAllPairsResults.pval_correctedW   sL     	211111111>*F   ??BBr   c                 *    |                                  S r	   )summaryr   s    r   __str__zAllPairsResults.__str__d   s    ||~~r   c                     | j         }t          j        ||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'   zerosrH   r   r<   )r   k	pvals_mats      r   
pval_tablezAllPairsResults.pval_tableg   sA    
 MHaV$$	+/+>+>+@+@	$'(r   c           	      4   ddl mc m} t          d | j        D                       }d|j        | j                 z  }|dd|dz
  dz   z  z   d	z   z  }|d
                    d t          | j        | 	                                          D                       z  }|S )zreturns text summarizing the results

        uses the default pvalue correction of the instance stored in
        ``self.multitest_method``
        r   Nc              3   4   K   | ]}t          |          V  d S r	   )r"   )r   sss     r   r   z*AllPairsResults.summary.<locals>.<genexpr>y   s(      >>2s2ww>>>>>>r   z0Corrected p-values using %s p-value correction

Pairs    r4   z	p-values

c              3   ,   K   | ]\  }}| d |dV  dS )z  z6.4gNr   )r   r6   pvs      r   r   z*AllPairsResults.summary.<locals>.<genexpr>~   sO       L LKUBU//b/// L L L L L Lr   )
rC   rD   rE   r=   r@   multitest_methods_namesr?   joinziprH   )r   rG   maxleveltexts       r   rJ   zAllPairsResults.summaryr   s     	211111111>>)=>>>>>D-d.CDE3(Q,"234|CC		 L Ld2D4G4G4I4IJJL L L L L 	Lr   )r2   NNr	   )	r+   r,   r-   r.   r   rH   rK   rP   rJ   r   r   r   r1   r1   %   s         4 ?C'+   .C C C C  	 	 	    r   r1   )	r.   statsmodels.compat.pythonr   numpyr'   statsmodels.tools.testingr   r   r1   r   r   r   <module>rb      s     + * * * * *     , , , , , ,B B B B B& B B B2[ [ [ [ [ [ [ [ [ [r   