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


Python stats.binom_test方法代码示例

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


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

示例1: binom_tost

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def binom_tost(count, nobs, low, upp):
    '''exact TOST test for one proportion using binomial distribution

    Parameters
    ----------
    count : integer or array_like
        the number of successes in nobs trials.
    nobs : integer
        the number of trials or observations.
    low, upp : floats
        lower and upper limit of equivalence region

    Returns
    -------
    pvalue : float
        p-value of equivalence test
    pval_low, pval_upp : floats
        p-values of lower and upper one-sided tests

    '''
    # binom_test_stat only returns pval
    tt1 = binom_test(count, nobs, alternative='larger', prop=low)
    tt2 = binom_test(count, nobs, alternative='smaller', prop=upp)
    return np.maximum(tt1, tt2), tt1, tt2, 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:proportion.py

示例2: test_binomtest

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_binomtest():
    # precision tests compared to R for ticket:986
    pp = np.concatenate((np.linspace(0.1,0.2,5), np.linspace(0.45,0.65,5),
                          np.linspace(0.85,0.95,5)))
    n = 501
    x = 450
    results = [0.0, 0.0, 1.0159969301994141e-304,
    2.9752418572150531e-275, 7.7668382922535275e-250,
    2.3381250925167094e-099, 7.8284591587323951e-081,
    9.9155947819961383e-065, 2.8729390725176308e-050,
    1.7175066298388421e-037, 0.0021070691951093692,
    0.12044570587262322, 0.88154763174802508, 0.027120993063129286,
    2.6102587134694721e-006]

    for p, res in zip(pp,results):
        assert_approx_equal(stats.binom_test(x, n, p), res,
                            significant=12, err_msg='fail forp=%f' % p)

    assert_approx_equal(stats.binom_test(50,100,0.1), 5.8320387857343647e-024,
                            significant=12, err_msg='fail forp=%f' % p) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:test_stats.py

示例3: test_binomtest2

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_binomtest2():
    # test added for issue #2384
    res2 = [
    [1.0, 1.0],
    [0.5,1.0,0.5],
    [0.25,1.00,1.00,0.25],
    [0.125,0.625,1.000,0.625,0.125],
    [0.0625,0.3750,1.0000,1.0000,0.3750,0.0625],
    [0.03125,0.21875,0.68750,1.00000,0.68750,0.21875,0.03125],
    [0.015625,0.125000,0.453125,1.000000,1.000000,0.453125,0.125000,0.015625],
    [0.0078125,0.0703125,0.2890625,0.7265625,1.0000000,0.7265625,0.2890625,
     0.0703125,0.0078125],
    [0.00390625,0.03906250,0.17968750,0.50781250,1.00000000,1.00000000,
     0.50781250,0.17968750,0.03906250,0.00390625],
    [0.001953125,0.021484375,0.109375000,0.343750000,0.753906250,1.000000000,
     0.753906250,0.343750000,0.109375000,0.021484375,0.001953125]
    ]

    for k in range(1, 11):
        res1 = [stats.binom_test(v, k, 0.5) for v in range(k + 1)]
        assert_almost_equal(res1, res2[k-1], decimal=10) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:23,代码来源:test_stats.py

示例4: pbinom

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def pbinom(x,n,p):
	
	# handling special cases
	if x<0:
		return 0
	if n<=0:
		return 0
	if x>n:
		return 1
		
	# use scipy.binom_test to calculate binomial test p-value
	pv=binom_test(x,n,p,alternative="less")
	if (1-pv)<=sys.float_info.epsilon/2:
		return 1
	else:
		return pv 
开发者ID:phoenixding,项目名称:scdiff,代码行数:18,代码来源:StatTest.py

示例5: test_t_EB_coverage

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_t_EB_coverage(seed, alpha, N):
    trials = 100

    random_st = np.random.RandomState(seed)

    fail = 0
    for tt in range(trials):
        x = random_st.randn(N)

        EB = stats.t_EB(x, alpha=alpha)
        mu = np.nanmean(x)
        LB, UB = mu - EB, mu + EB
        assert np.isfinite(LB) and np.isfinite(UB)
        fail += (0.0 < LB) or (UB < 0.0)
    pval = sst.binom_test(fail, trials, alpha)

    assert pval >= 0.05 / 100  # Assume we run 100 times 
开发者ID:uber,项目名称:bayesmark,代码行数:19,代码来源:stats_test.py

示例6: predict

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def predict(self, x: torch.tensor, n: int, alpha: float, batch_size: int) -> int:
        """ Monte Carlo algorithm for evaluating the prediction of g at x.  With probability at least 1 - alpha, the
        class returned by this method will equal g(x).

        This function uses the hypothesis test described in https://arxiv.org/abs/1610.03944
        for identifying the top category of a multinomial distribution.

        :param x: the input [channel x height x width]
        :param n: the number of Monte Carlo samples to use
        :param alpha: the failure probability
        :param batch_size: batch size to use when evaluating the base classifier
        :return: the predicted class, or ABSTAIN
        """
        self.base_classifier.eval()
        counts = self._sample_noise(x, n, batch_size)
        top2 = counts.argsort()[::-1][:2]
        count1 = counts[top2[0]]
        count2 = counts[top2[1]]
        if binom_test(count1, count1 + count2, p=0.5) > alpha:
            return Smooth.ABSTAIN
        else:
            return top2[0] 
开发者ID:yaircarmon,项目名称:semisup-adv,代码行数:24,代码来源:smoothing.py

示例7: sign_test

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def sign_test(samp, mu0=0):
    samp = np.asarray(samp)
    pos = np.sum(samp > mu0)
    neg = np.sum(samp < mu0)
    M = (pos-neg)/2.
    p = stats.binom_test(min(pos,neg), pos+neg, .5)
    return M, p 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:descriptivestats.py

示例8: test_data

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_data(self):
        pval = stats.binom_test(100,250)
        assert_almost_equal(pval,0.0018833009350757682,11)
        pval = stats.binom_test(201,405)
        assert_almost_equal(pval,0.92085205962670713,11)
        pval = stats.binom_test([682,243],p=3.0/4)
        assert_almost_equal(pval,0.38249155957481695,11) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,代码来源:test_morestats.py

示例9: test_bad_len_x

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_bad_len_x(self):
        """Length of x must be 1 or 2."""
        assert_raises(ValueError, stats.binom_test, [1,2,3]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:5,代码来源:test_morestats.py

示例10: test_bad_n

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_bad_n(self):
        """len(x) is 1, but n is invalid."""
        # Missing n
        assert_raises(ValueError, stats.binom_test, [100])
        # n less than x[0]
        assert_raises(ValueError, stats.binom_test, [100], n=50) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:test_morestats.py

示例11: test_bad_p

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_bad_p(self):
        assert_raises(ValueError, stats.binom_test, [50, 50], p=2.0) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:4,代码来源:test_morestats.py

示例12: test_data

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_data(self):
        pval = stats.binom_test(100, 250)
        assert_almost_equal(pval, 0.0018833009350757682, 11)
        pval = stats.binom_test(201, 405)
        assert_almost_equal(pval, 0.92085205962670713, 11)
        pval = stats.binom_test([682, 243], p=3.0/4)
        assert_almost_equal(pval, 0.38249155957481695, 11) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_morestats.py

示例13: test_bad_len_x

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_bad_len_x(self):
        # Length of x must be 1 or 2.
        assert_raises(ValueError, stats.binom_test, [1, 2, 3]) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:5,代码来源:test_morestats.py

示例14: test_bad_n

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_bad_n(self):
        # len(x) is 1, but n is invalid.
        # Missing n
        assert_raises(ValueError, stats.binom_test, [100])
        # n less than x[0]
        assert_raises(ValueError, stats.binom_test, [100], n=50) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:8,代码来源:test_morestats.py

示例15: test_alternatives

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import binom_test [as 别名]
def test_alternatives(self):
        res = stats.binom_test(51, 235, p=1./6, alternative='less')
        assert_almost_equal(res, 0.982022657605858)

        res = stats.binom_test(51, 235, p=1./6, alternative='greater')
        assert_almost_equal(res, 0.02654424571169085)

        res = stats.binom_test(51, 235, p=1./6, alternative='two-sided')
        assert_almost_equal(res, 0.0437479701823997) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:11,代码来源:test_morestats.py


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