当前位置: 首页>>代码示例>>Python>>正文


Python hypergeom.cdf方法代码示例

本文整理汇总了Python中scipy.stats.hypergeom.cdf方法的典型用法代码示例。如果您正苦于以下问题:Python hypergeom.cdf方法的具体用法?Python hypergeom.cdf怎么用?Python hypergeom.cdf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats.hypergeom的用法示例。


在下文中一共展示了hypergeom.cdf方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: hypergeometric_test

# 需要导入模块: from scipy.stats import hypergeom [as 别名]
# 或者: from scipy.stats.hypergeom import cdf [as 别名]
def hypergeometric_test(x, M, n, N):
    """
    The hypergeometric distribution models drawing objects from a bin.
    - M is total number of objects
    - n is total number of Type I objects. 
    - x (random variate) represents the number of Type I objects in N drawn without replacement from the total population

    - http://en.wikipedia.org/wiki/Hypergeometric_distribution
    - https://www.biostars.org/p/66729/
    - http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.hypergeom.html
    - http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.hypergeometric.html
    - http://stackoverflow.com/questions/6594840/what-are-equivalents-to-rs-phyper-function-in-python
    """

    assert n <= M
    assert x <= n
    assert N <= M
    pv_le = hypergeom.cdf(x+1, M, n, N)
    pv_gt = hypergeom.sf(x-1, M, n, N)# 1-cdf sometimes more accurate
    return pv_le, pv_gt 
开发者ID:gis-rpd,项目名称:pipelines,代码行数:22,代码来源:essential_genes_from_tables.py

示例2: binomial_p

# 需要导入模块: from scipy.stats import hypergeom [as 别名]
# 或者: from scipy.stats.hypergeom import cdf [as 别名]
def binomial_p(x, n, p, alternative='greater'):
    """
    Parameters
    ----------
    x : array-like
       list of elements consisting of x in {0, 1} where 0 represents a failure and
       1 represents a seccuess
    p : int
       hypothesized number of successes in n trials
    n : int
       number of trials 
    alternative : {'greater', 'less', 'two-sided'}
       alternative hypothesis to test (default: 'greater')
    Returns
    -------
    float
       estimated p-value 
    """

    assert alternative in ("two-sided", "less", "greater")
    if n < x:
        raise ValueError("Cannot observe more successes than the population size")

    plower = binom.cdf(x, n, p)
    pupper = binom.sf(x-1, n, p)
    if alternative == 'two-sided':
        pvalue = 2*np.min([plower, pupper, 0.5])
    elif alternative == 'greater':
        pvalue = pupper
    elif alternative == 'less':
        pvalue = plower
    return pvalue 
开发者ID:statlab,项目名称:permute,代码行数:34,代码来源:utils.py

示例3: test_hypergeometric

# 需要导入模块: from scipy.stats import hypergeom [as 别名]
# 或者: from scipy.stats.hypergeom import cdf [as 别名]
def test_hypergeometric():
    assert_almost_equal(hypergeometric(4, 10, 5, 6, 'greater'), 
                        1-hypergeom.cdf(3, 10, 5, 6))
    assert_almost_equal(hypergeometric(4, 10, 5, 6, 'less'), 
                        hypergeom.cdf(4, 10, 5, 6))
    assert_almost_equal(hypergeometric(4, 10, 5, 6, 'two-sided'), 
                        2*(1-hypergeom.cdf(3, 10, 5, 6))) 
开发者ID:statlab,项目名称:permute,代码行数:9,代码来源:test_utils.py

示例4: test_binomial_p

# 需要导入模块: from scipy.stats import hypergeom [as 别名]
# 或者: from scipy.stats.hypergeom import cdf [as 别名]
def test_binomial_p():
    assert_almost_equal(binomial_p(5, 10, 0.5, 'greater'), 
                        1-binom.cdf(4, 10, 0.5))
    assert_almost_equal(binomial_p(5, 10, 0.5, 'less'), 
                        binom.cdf(5, 10, 0.5))
    assert_almost_equal(binomial_p(5, 10, 0.5, 'two-sided'), 1) 
开发者ID:statlab,项目名称:permute,代码行数:8,代码来源:test_utils.py

示例5: score_hypergeometric_test

# 需要导入模块: from scipy.stats import hypergeom [as 别名]
# 或者: from scipy.stats.hypergeom import cdf [as 别名]
def score_hypergeometric_test(a, b, threshold=1, **kwargs):
    """
    Run a hypergeometric test. The probability in a two-sided test is approximated
    with the symmetric distribution with more extreme of the tails.
    """
    # type: (np.ndarray, np.ndarray, float) -> np.ndarray

    # Binary expression matrices
    _a = (a >= threshold).astype(int)
    _b = (b >= threshold).astype(int)
    alt = kwargs.get("alternative", ALT_TWO)
    assert alt in ALTERNATIVES

    # Test Parameters
    m = len(_a) + len(_b)
    n = len(_a)
    n_expr = _a.sum(axis=0) + _b.sum(axis=0)  # Number of cells expressing genes (overall)
    n_expr_clust = _a.sum(axis=0)  # Number of cells expressing genes (in cluster)

    # Test results --- both tails
    # Note: cumulatives do sum to >1 due to overlap at 1 point
    under = np.fromiter(map(lambda t: hypergeom.cdf(k=t[1], n=t[0], M=m, N=n), zip(n_expr, n_expr_clust)), dtype=float)
    over = np.fromiter(
        map(lambda t: hypergeom.sf(k=t[1] - 1, n=t[0], M=m, N=n), zip(n_expr, n_expr_clust)), dtype=float
    )
    signs = np.sign(under - over)
    if alt == ALT_TWO:
        pvalues = np.minimum(1.0, 2.0 * np.minimum(under, over))
    elif alt == ALT_LESS:
        pvalues = under
    else:
        pvalues = over
    scores = -np.log(pvalues) * signs
    return scores, pvalues 
开发者ID:biolab,项目名称:orange3-bioinformatics,代码行数:36,代码来源:statistics.py

示例6: _hypergeom_wrapper

# 需要导入模块: from scipy.stats import hypergeom [as 别名]
# 或者: from scipy.stats.hypergeom import cdf [as 别名]
def _hypergeom_wrapper(self, x):
            
        from scipy.stats import hypergeom
        p = hypergeom.cdf(x['lonely triplets at pos'],x['Num Triplets at Gene'],
                          x['lonely triplets at gen'],x['Num Triplets at Pos'])
        return p 
开发者ID:ambrosejcarr,项目名称:seqc,代码行数:8,代码来源:read_array.py

示例7: binom_conf_interval

# 需要导入模块: from scipy.stats import hypergeom [as 别名]
# 或者: from scipy.stats.hypergeom import cdf [as 别名]
def binom_conf_interval(n, x, cl=0.975, alternative="two-sided", p=None,
                        **kwargs):
    """
    Compute a confidence interval for a binomial p, the probability of success in each trial.

    Parameters
    ----------
    n : int
        The number of Bernoulli trials.
    x : int
        The number of successes.
    cl : float in (0, 1)
        The desired confidence level.
    alternative : {"two-sided", "lower", "upper"}
        Indicates the alternative hypothesis.
    p : float in (0, 1)
        Starting point in search for confidence bounds for probability of success in each trial.
    kwargs : dict
        Key word arguments

    Returns
    -------
    tuple
        lower and upper confidence level with coverage (approximately)
        1-alpha.

    Notes
    -----
    xtol : float
        Tolerance
    rtol : float
        Tolerance
    maxiter : int
        Maximum number of iterations.
    """
    assert alternative in ("two-sided", "lower", "upper")

    if p is None:
        p = x / n
    ci_low = 0.0
    ci_upp = 1.0

    if alternative == 'two-sided':
        cl = 1 - (1 - cl) / 2

    if alternative != "upper" and x > 0:
        f = lambda q: cl - binom.cdf(x - 1, n, q)
        while f(p) < 0:
            p = (p+1)/2
        ci_low = brentq(f, 0.0, p, *kwargs)
    if alternative != "lower" and x < n:
        f = lambda q: binom.cdf(x, n, q) - (1 - cl)
        while f(p) < 0:
            p = p/2
        ci_upp = brentq(f, 1.0, p, *kwargs)

    return ci_low, ci_upp 
开发者ID:statlab,项目名称:permute,代码行数:59,代码来源:utils.py

示例8: hypergeometric

# 需要导入模块: from scipy.stats import hypergeom [as 别名]
# 或者: from scipy.stats.hypergeom import cdf [as 别名]
def hypergeometric(x, N, n, G, alternative='greater'):
    
    """
    Parameters
    ----------
    x : int
        number of `good` elements observed in the sample
    N : int
        population size
    n : int
       sample size
    G : int
       hypothesized number of good elements in population
    alternative : {'greater', 'less', 'two-sided'}
       alternative hypothesis to test (default: 'greater')
    Returns
    -------
    float
       estimated p-value
    """
    if n < x:
        raise ValueError("Cannot observe more good elements than the sample size")
    if N < n:
        raise ValueError("Population size cannot be smaller than sample")
    if N < G:
        raise ValueError("Number of good elements can't exceed the population size")
    if G < x:
        raise ValueError("Number of observed good elements can't exceed the number in the population")

    assert alternative in ("two-sided", "less", "greater")
    if n < x:
        raise ValueError("Cannot observe more successes than the population size")

    plower = hypergeom.cdf(x, N, G, n)
    pupper = hypergeom.sf(x-1, N, G, n)
    if alternative == 'two-sided':
        pvalue = 2*np.min([plower, pupper, 0.5])
    elif alternative == 'greater':
        pvalue = pupper
    elif alternative == 'less':
        pvalue = plower
    return pvalue 
开发者ID:statlab,项目名称:permute,代码行数:44,代码来源:utils.py


注:本文中的scipy.stats.hypergeom.cdf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。