
    !g                     R    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y)	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

    c                      t           di | |t         fd|D               _        y  j                   j                  f _        y )Nc              3   6   K   | ]  }t        |        y wN)getattr).0attselfs     S/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/stats/base.py	<genexpr>z'HolderTuple.__init__.<locals>.<genexpr>   s     DcwtS1Ds    )super__init__tuple	statisticpvalue)r   tuple_kwds	__class__s   `  r   r   zHolderTuple.__init__   s?     4 DVDDDJ..$++6DJ    c              #   8   K   | j                   E d {    y 7 wr	   r   r   s    r   __iter__zHolderTuple.__iter__   s     ::s   c                      | j                   |   S r	   r   )r   idxs     r   __getitem__zHolderTuple.__getitem__   s    zz#r   c                 ,    t        | j                        S r	   )lenr   r   s    r   __len__zHolderTuple.__len__   s    4::r   c                 X    t        j                  t        | j                        ||      S )N)dtypecopy)nparraylistr   )r   r%   r&   s      r   	__array__zHolderTuple.__array__!   s    xxTZZ(DAAr   r	   )NT)
__name__
__module____qualname____doc__r   r   r    r#   r*   __classcell__)r   s   @r   r   r      s"    7Br   r   c                   6    e Zd ZdZ	 	 ddZd	dZd Zd Zd Zy)
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).

    Nc           	      2   || _         || _        |t        j                  |      dz   | _        n|| _        || _        || _        ||D cg c]  }| c}| _        y |D cg c]   }dj                  ||d      ||d            " c}| _        y c c}w c c}w )N   z{}-{}r   )		pvals_raw	all_pairsr'   maxn_levelsmultitest_methodlevelsall_pairs_namesformat)r   r4   r5   r8   r9   r7   pairss          r   r   zAllPairsResults.__init__@   s    ""FF9-1DM$DM 0>*3$!&5)$D   )$  58$fU1X&6$D 	$$s   

B!%Bc                 p    ddl mc m} || j                  }|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)methodr3   )statsmodels.stats.multiteststats	multitestr8   multipletestsr4   )r   r>   smts      r   pval_correctedzAllPairsResults.pval_correctedW   s9     	21>**F   ?BBr   c                 "    | j                         S r	   )summaryr   s    r   __str__zAllPairsResults.__str__d   s    ||~r   c                     | j                   }t        j                  ||f      }| j                         |t	        | j
                   <   |S )zcreate a (n_levels, n_levels) array with corrected p_values

        this needs to improve, similar to R pairwise output
        )r7   r'   zerosrD   r   r5   )r   k	pvals_mats      r   
pval_tablezAllPairsResults.pval_tableg   sA    
 MMHHaV$	+/+>+>+@	$'(r   c           	      *   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
j                  d t        | j                  | 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   2   K   | ]  }t        |        y wr	   )r"   )r   sss     r   r   z*AllPairsResults.summary.<locals>.<genexpr>y   s     >2s2w>   z0Corrected p-values using %s p-value correction

Pairs    r3   z	p-values

c              3   2   K   | ]  \  }}| d |d  yw)z  z6.4gNr   )r   r<   pvs      r   r   z*AllPairsResults.summary.<locals>.<genexpr>~   s'      LKUBUG2bY/ LrP   )
r?   r@   rA   r6   r:   multitest_methods_namesr8   joinziprD   )r   rC   maxleveltexts       r   rF   zAllPairsResults.summaryr   s     	21>)=)=>>D--d.C.CDE3(Q,"234|CC		 Ld22D4G4G4IJL L 	Lr   )hsNNr	   )	r+   r,   r-   r.   r   rD   rG   rL   rF   r   r   r   r1   r1   %   s*    4 ?C'+.C	r   r1   )	r.   statsmodels.compat.pythonr   numpyr'   statsmodels.tools.testingr   r   r1   r   r   r   <module>r`      s/    +  ,B& B2[ [r   