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


Python binom.cdf方法代码示例

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


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

示例1: cdf

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def cdf(self, y, f):
        r"""
        Cumulative density function of the likelihood.

        Parameters
        ----------
        y: ndarray
            query quantiles, i.e.\  :math:`P(Y \leq y)`.
        f: ndarray
            latent function from the GLM prior (:math:`\mathbf{f} =
            \boldsymbol\Phi \mathbf{w}`)

        Returns
        -------
        cdf: ndarray
            Cumulative density function evaluated at y.
        """
        return bernoulli.cdf(y, expit(f)) 
开发者ID:NICTA,项目名称:revrand,代码行数:20,代码来源:likelihoods.py

示例2: test_shapes

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def test_shapes():

    N = 100
    y = np.ones(N)
    f = np.ones(N) * 2

    assert_shape = lambda x: x.shape == (N,)
    assert_args = lambda out, args: \
        all([o.shape == a.shape if not np.isscalar(a) else np.isscalar(o)
             for o, a in zip(out, args)])

    for like, args in zip(likelihoods, likelihood_args):

        lobj = like()
        assert_shape(lobj.loglike(y, f, *args))
        assert_shape(lobj.Ey(f, *args))
        assert_shape(lobj.df(y, f, *args))
        assert_shape(lobj.cdf(y, f, *args))
        assert_args(lobj.dp(y, f, *args), args) 
开发者ID:NICTA,项目名称:revrand,代码行数:21,代码来源:test_likelihoods.py

示例3: test_bernoulli

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def test_bernoulli():

    # Test we can at match a Bernoulli distribution from scipy

    p = 0.5
    dist = lk.Bernoulli()

    x = np.array([0, 1])

    p1 = bernoulli.logpmf(x, p)
    p2 = dist.loglike(x, p)

    np.allclose(p1, p2)

    p1 = bernoulli.cdf(x, p)
    p2 = dist.cdf(x, p)

    np.allclose(p1, p2) 
开发者ID:NICTA,项目名称:revrand,代码行数:20,代码来源:test_likelihoods.py

示例4: test_binom

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def test_binom():

    # Test we can at match a Binomial distribution from scipy

    p = 0.5
    n = 5
    dist = lk.Binomial()

    x = np.random.randint(low=0, high=n, size=(10,))

    p1 = binom.logpmf(x, p=p, n=n)
    p2 = dist.loglike(x, p, n)

    np.allclose(p1, p2)

    p1 = binom.cdf(x, p=p, n=n)
    p2 = dist.cdf(x, p, n)

    np.allclose(p1, p2) 
开发者ID:NICTA,项目名称:revrand,代码行数:21,代码来源:test_likelihoods.py

示例5: test_poisson

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def test_poisson():

    # Test we can at match a Binomial distribution from scipy

    mu = 2
    dist = lk.Poisson()

    x = np.random.randint(low=0, high=5, size=(10,))

    p1 = poisson.logpmf(x, mu)
    p2 = dist.loglike(x, mu)

    np.allclose(p1, p2)

    p1 = poisson.cdf(x, mu)
    p2 = dist.cdf(x, mu)

    np.allclose(p1, p2) 
开发者ID:NICTA,项目名称:revrand,代码行数:20,代码来源:test_likelihoods.py

示例6: sign_test

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def sign_test(data):
    """ Given the results drawn from two algorithms/methods X and Y, the sign test analyses if
    there is a difference between X and Y.

    .. note:: Null Hypothesis: Pr(X<Y)= 0.5

    :param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem.
    :return p_value: The associated p-value from the binomial distribution.
    :return bstat: Number of successes.
    """

    if type(data) == pd.DataFrame:
        data = data.values

    if data.shape[1] == 2:
        X, Y = data[:, 0], data[:, 1]
        n_perf = data.shape[0]
    else:
        raise ValueError(
            'Initialization ERROR. Incorrect number of dimensions for axis 1')

    # Compute the differences
    Z = X - Y
    # Compute the number of pairs Z<0
    Wminus = sum(Z < 0)
    # If H_0 is true ---> W follows Binomial(n,0.5)
    p_value_minus = 1 - binom.cdf(k=Wminus, p=0.5, n=n_perf)

    # Compute the number of pairs Z>0
    Wplus = sum(Z > 0)
    # If H_0 is true ---> W follows Binomial(n,0.5)
    p_value_plus = 1 - binom.cdf(k=Wplus, p=0.5, n=n_perf)

    p_value = 2 * min([p_value_minus, p_value_plus])

    return pd.DataFrame(data=np.array([Wminus, Wplus, p_value]), index=['Num X<Y', 'Num X>Y', 'p-value'],
                        columns=['Results']) 
开发者ID:jMetal,项目名称:jMetalPy,代码行数:39,代码来源:functions.py

示例7: friedman_test

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def friedman_test(data):
    """ Friedman ranking test.

    ..note:: Null Hypothesis: In a set of k (>=2) treaments (or tested algorithms), all the treatments are equivalent, so their average ranks should be equal.

    :param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem.
    :return p_value: The associated p-value.
    :return friedman_stat: Friedman's chi-square.
    """

    # Initial Checking
    if type(data) == pd.DataFrame:
        data = data.values

    if data.ndim == 2:
        n_samples, k = data.shape
    else:
        raise ValueError(
            'Initialization ERROR. Incorrect number of array dimensions')
    if k < 2:
        raise ValueError(
            'Initialization Error. Incorrect number of dimensions for axis 1.')

    # Compute ranks.
    datarank = ranks(data)

    # Compute for each algorithm the ranking average.
    avranks = np.mean(datarank, axis=0)

    # Get Friedman statistics
    friedman_stat = (12.0 * n_samples) / (k * (k + 1.0)) * \
                    (np.sum(avranks ** 2) - (k * (k + 1) ** 2) / 4.0)

    # Compute p-value
    p_value = (1.0 - chi2.cdf(friedman_stat, df=(k - 1)))

    return pd.DataFrame(data=np.array([friedman_stat, p_value]), index=['Friedman-statistic', 'p-value'],
                        columns=['Results']) 
开发者ID:jMetal,项目名称:jMetalPy,代码行数:40,代码来源:functions.py

示例8: binomial_p

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom 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

示例9: test_hypergeometric

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom 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

示例10: test_binomial_p

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom 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

示例11: pbinom

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def pbinom(k, n):
    """
    Compute cdf for binomial with prob = 0.5
    compare to R pbinom
    :param k:
    :param n:
    :return: cumulative probability
    """

    return binom.cdf(k, n, 0.5) 
开发者ID:linkedin,项目名称:luminol,代码行数:12,代码来源:utils.py

示例12: calculate_present_pvalue

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def calculate_present_pvalue(mut_reads, coverage, fpr):
    """
    Calculate the p-value for the given FPR and number of mutant reads and coverage at this position
    :param mut_reads: number of mutant reads
    :param coverage: coverage at this position
    :param fpr: false-positive rate
    :return: p-value
    """

    return 1.0 - binom.cdf(mut_reads-1, coverage, fpr) 
开发者ID:johannesreiter,项目名称:treeomics,代码行数:12,代码来源:statistics.py

示例13: calculate_absent_pvalue

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def calculate_absent_pvalue(mut_reads, coverage, min_maf):
    """
    Calculate the p-value that no mutation exists with a larger MAF
    for the number of mutant reads and coverage at this position
    P(X<=k|H_0); H_0: MAF > min_freq
    min frequency already accounts for false-positives
    :param mut_reads: number of mutant reads
    :param coverage: coverage at this position
    :param min_maf: minimal mutant allele frequency
    :return: p-value
    """
    return binom.cdf(mut_reads, coverage, min_maf) 
开发者ID:johannesreiter,项目名称:treeomics,代码行数:14,代码来源:statistics.py

示例14: friedman_aligned_rank_test

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def friedman_aligned_rank_test(data):
    """ Method of aligned ranks for the Friedman test.

    ..note:: Null Hypothesis: In a set of k (>=2) treaments (or tested algorithms), all the treatments are equivalent, so their average ranks should be equal.

    :param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem.
    :return p_value: The associated p-value.
    :return aligned_rank_stat: Friedman's aligned rank chi-square statistic.
    """

    # Initial Checking
    if type(data) == pd.DataFrame:
        data = data.values

    if data.ndim == 2:
        n_samples, k = data.shape
    else:
        raise ValueError(
            'Initialization ERROR. Incorrect number of array dimensions')
    if k < 2:
        raise ValueError(
            'Initialization Error. Incorrect number of dimensions for axis 1.')

    # Compute the average value achieved by all algorithms in each problem
    control = np.mean(data, axis=1)
    # Compute the difference between control an data
    diff = [data[:, j] - control for j in range(data.shape[1])]
    # rank diff
    alignedRanks = ranks(np.ravel(diff))
    alignedRanks = np.reshape(alignedRanks, newshape=(n_samples, k), order='F')

    # Compute statistic
    Rhat_i = np.sum(alignedRanks, axis=1)
    Rhat_j = np.sum(alignedRanks, axis=0)
    si, sj = np.sum(Rhat_i ** 2), np.sum(Rhat_j ** 2)

    A = sj - (k * n_samples ** 2 / 4.0) * (k * n_samples + 1) ** 2
    B1 = (k * n_samples * (k * n_samples + 1) * (2 * k * n_samples + 1) / 6.0)
    B2 = si / float(k)

    alignedRanks_stat = ((k - 1) * A) / (B1 - B2)

    p_value = 1 - chi2.cdf(alignedRanks_stat, df=k - 1)

    return pd.DataFrame(data=np.array([alignedRanks_stat, p_value]), index=['Aligned Rank stat', 'p-value'],
                        columns=['Results']) 
开发者ID:jMetal,项目名称:jMetalPy,代码行数:48,代码来源:functions.py

示例15: quade_test

# 需要导入模块: from scipy.stats import binom [as 别名]
# 或者: from scipy.stats.binom import cdf [as 别名]
def quade_test(data):
    """ Quade test.

    ..note:: Null Hypothesis: In a set of k (>=2) treaments (or tested algorithms), all the treatments are equivalent, so their average ranks should be equal.

    :param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem.
    :return p_value: The associated p-value from the F-distribution.
    :return fq: Computed F-value.
    """

    # Initial Checking
    if type(data) == pd.DataFrame:
        data = data.values

    if data.ndim == 2:
        n_samples, k = data.shape
    else:
        raise ValueError(
            'Initialization ERROR. Incorrect number of array dimensions')
    if k < 2:
        raise ValueError(
            'Initialization Error. Incorrect number of dimensions for axis 1.')

    # Compute ranks.
    datarank = ranks(data)
    # Compute the range of each problem
    problemRange = np.max(data, axis=1) - np.min(data, axis=1)
    # Compute problem rank
    problemRank = ranks(problemRange)

    # Compute S_stat: weight of each observation within the problem, adjusted to reflect
    # the significance of the problem when it appears.
    S_stat = np.zeros((n_samples, k))
    for i in range(n_samples):
        S_stat[i, :] = problemRank[i] * (datarank[i, :] - 0.5 * (k + 1))
    Salg = np.sum(S_stat, axis=0)

    # Compute Fq (Quade Test statistic) and associated p_value
    A = np.sum(S_stat ** 2)
    B = np.sum(Salg ** 2) / float(n_samples)

    if A == B:
        Fq = np.Inf
        p_value = (1 / (np.math.factorial(k))) ** (n_samples - 1)
    else:
        Fq = (n_samples - 1.0) * B / (A - B)
        p_value = 1 - f.cdf(Fq, k - 1, (k - 1) * (n_samples - 1))

    return pd.DataFrame(data=np.array([Fq, p_value]), index=['Quade Test statistic', 'p-value'], columns=['Results']) 
开发者ID:jMetal,项目名称:jMetalPy,代码行数:51,代码来源:functions.py


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