<commit_before>from __future__ import division, print_function, absolute_import

import numpy as np
from scipy.stats import norm, rankdata


# Combining functions

def fisher(pvalues):
    '''
    Apply Fisher's combining function
    
    .. math:: \-2\sum_i \log(p_i)
    
    Parameters
    ----------
    pvalues : array_like
        Array of p-values to combine
        
    Returns
    -------
    float
        Fisher's combined test statistic
    '''
    return -2*np.log(np.prod(pvalues))


def liptak(pvalues):
    '''
    Apply Liptak's combining function
    
    .. math:: \\sum_i \Phi^{-1}(1-p_i)
    
    where $\Phi^{-1}$ is the inverse CDF of the standard normal distribution.
    
    Parameters
    ----------
    pvalues : array_like
        Array of p-values to combine
        
    Returns
    -------
    float
        Liptak's combined test statistic
    '''
    return np.sum(norm.ppf(1-pvalues))


def tippett(pvalues):
    '''
    Apply Tippett's combining function
    
    .. math:: \\max_i \{1-p_i\}
    
    Parameters
    ----------
    pvalues : array_like
        Array of p-values to combine
        
    Returns
    -------
    float
        Tippett's combined test statistic
    '''
    return np.max(1-pvalues)


# Nonparametric combination of tests

def t2p(stat, distr, alternative="greater"):
    '''
    Use the empirical distribution of a test statistic to compute
    its p-value.
    
    Parameters<commit_msg>ENH: Add inverse sample size weighting combining function<commit_after>from __future__ import division, print_function, absolute_import

import numpy as np
from scipy.stats import norm, rankdata


# Combining functions

def fisher(pvalues):
    '''
    Apply Fisher's combining function
    
    .. math:: \-2\sum_i \log(p_i)
    
    Parameters
    ----------
    pvalues : array_like
        Array of p-values to combine
        
    Returns
    -------
    float
        Fisher's combined test statistic
    '''
    return -2*np.log(np.prod(pvalues))


def liptak(pvalues):
    '''
    Apply Liptak's combining function
    
    .. math:: \\sum_i \Phi^{-1}(1-p_i)
    
    where $\Phi^{-1}$ is the inverse CDF of the standard normal distribution.
    
    Parameters
    ----------
    pvalues : array_like
        Array of p-values to combine
        
    Returns
    -------
    float
        Liptak's combined test statistic
    '''
    return np.sum(norm.ppf(1-pvalues))


def tippett(pvalues):
    '''
    Apply Tippett's combining function
    
    .. math:: \\max_i \{1-p_i\}
    
    Parameters
    ----------
    pvalues : array_like
        Array of p-values to combine
        
    Returns
    -------
    float
        Tippett's combined test statistic
    '''
    return np.max(1-pvalues)
    

def inverse_n_weight(pvalues, size):
    """
    Compute the test statistic

    .. math:: -\\sum_{s=1}^S\\frac{p_s}{\sqrt{N_s}}

    Parameters
    ----------
    pvalues : array_like
        Array of p-values to combine
    size : array_like
        The $i$th entry is the sample size used for the $i$th test

    Returns
    -------
    float
        combined test statistic
    """
    weights = size ** (-1 / 2)
    return (-1 * pvalues * weights).sum()
    

# Nonparametric combination of tests

def t2p(stat, distr, alternative="greater"):
    '''
    Use the empirical distribution of a test statistic to compute
    its p-value.
    
    Parameters
{'fraction_non_alphanumeric': 0.12204379562043796, 'fraction_numerical': 0.006423357664233576, 'mean_word_length': 1.8478802992518704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7170120', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1012, 'n_words': 298}