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


Python stats.tiecorrect方法代码示例

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


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

示例1: test_tie_correction

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import tiecorrect [as 别名]
def test_tie_correction():
    mult_data = multivariate_test_data()

    ranks = rankdata(mult_data[:, 1], 'average')

    ranks = np.column_stack([mult_data, ranks])

    tie_correct = tie_correction(ranks[:, 5])

    assert_almost_equal(tie_correct, tiecorrect(ranks[:, 5])) 
开发者ID:aschleg,项目名称:hypothetical,代码行数:12,代码来源:test_nonparametric.py

示例2: tiecorrect

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import tiecorrect [as 别名]
def tiecorrect(xranks):
    '''

    should be equivalent of scipy.stats.tiecorrect

    '''
    #casting to int rounds down, but not relevant for this case
    rankbincount = np.bincount(np.asarray(xranks,dtype=int))
    nties = rankbincount[rankbincount > 1]
    ntot = float(len(xranks));
    tiecorrection = 1 - (nties**3 - nties).sum()/(ntot**3 - ntot)
    return tiecorrection 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:14,代码来源:multicomp.py

示例3: kruskal

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import tiecorrect [as 别名]
def kruskal(self, pairs=None, multimethod='T'):
        '''
        pairwise comparison for kruskal-wallis test

        This is just a reimplementation of scipy.stats.kruskal and does
        not yet use a multiple comparison correction.

        '''
        self.getranks()
        tot = self.nobs
        meanranks = self.ranks.groupmean
        groupnobs = self.ranks.groupnobs


        # simultaneous/separate treatment of multiple tests
        f=(tot * (tot + 1.) / 12.) / stats.tiecorrect(self.rankdata) #(xranks)
        print('MultiComparison.kruskal')
        for i,j in zip(*self.pairindices):
            #pdiff = np.abs(mrs[i] - mrs[j])
            pdiff = np.abs(meanranks[i] - meanranks[j])
            se = np.sqrt(f * np.sum(1. / groupnobs[[i,j]] )) #np.array([8,8]))) #Fixme groupnobs[[i,j]] ))
            Q = pdiff / se

            # TODO : print(statments, fix
            print(i,j, pdiff, se, pdiff / se, pdiff / se > 2.6310)
            print(stats.norm.sf(Q) * 2)
            return stats.norm.sf(Q) * 2 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:29,代码来源:multicomp.py

示例4: test_empty

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import tiecorrect [as 别名]
def test_empty(self):
        """An empty array requires no correction, should return 1.0."""
        ranks = np.array([], dtype=np.float64)
        c = tiecorrect(ranks)
        assert_equal(c, 1.0) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_rank.py

示例5: test_one

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import tiecorrect [as 别名]
def test_one(self):
        """A single element requires no correction, should return 1.0."""
        ranks = np.array([1.0], dtype=np.float64)
        c = tiecorrect(ranks)
        assert_equal(c, 1.0) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_rank.py

示例6: test_no_correction

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import tiecorrect [as 别名]
def test_no_correction(self):
        """Arrays with no ties require no correction."""
        ranks = np.arange(2.0)
        c = tiecorrect(ranks)
        assert_equal(c, 1.0)
        ranks = np.arange(3.0)
        c = tiecorrect(ranks)
        assert_equal(c, 1.0) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_rank.py

示例7: test_basic

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import tiecorrect [as 别名]
def test_basic(self):
        """Check a few basic examples of the tie correction factor."""
        # One tie of two elements
        ranks = np.array([1.0, 2.5, 2.5])
        c = tiecorrect(ranks)
        T = 2.0
        N = ranks.size
        expected = 1.0 - (T**3 - T) / (N**3 - N)
        assert_equal(c, expected)

        # One tie of two elements (same as above, but tie is not at the end)
        ranks = np.array([1.5, 1.5, 3.0])
        c = tiecorrect(ranks)
        T = 2.0
        N = ranks.size
        expected = 1.0 - (T**3 - T) / (N**3 - N)
        assert_equal(c, expected)

        # One tie of three elements
        ranks = np.array([1.0, 3.0, 3.0, 3.0])
        c = tiecorrect(ranks)
        T = 3.0
        N = ranks.size
        expected = 1.0 - (T**3 - T) / (N**3 - N)
        assert_equal(c, expected)

        # Two ties, lengths 2 and 3.
        ranks = np.array([1.5, 1.5, 4.0, 4.0, 4.0])
        c = tiecorrect(ranks)
        T1 = 2.0
        T2 = 3.0
        N = ranks.size
        expected = 1.0 - ((T1**3 - T1) + (T2**3 - T2)) / (N**3 - N)
        assert_equal(c, expected) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:36,代码来源:test_rank.py

示例8: test_overflow

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import tiecorrect [as 别名]
def test_overflow(self):
        ntie, k = 2000, 5
        a = np.repeat(np.arange(k), ntie)
        n = a.size  # ntie * k
        out = tiecorrect(rankdata(a))
        assert_equal(out, 1.0 - k * (ntie**3 - ntie) / float(n**3 - n)) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:8,代码来源:test_rank.py

示例9: mannwhitneyu

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import tiecorrect [as 别名]
def mannwhitneyu(x, y, use_continuity=True):
    """
    Computes the Mann-Whitney rank test on samples x and y.

    Parameters
    ----------
    x, y : array_like
        Array of samples, should be one-dimensional.
    use_continuity : bool, optional
            Whether a continuity correction (1/2.) should be taken into
            account. Default is True.

    Returns
    -------
    u : float
        The Mann-Whitney statistics.
    prob : float
        One-sided p-value assuming a asymptotic normal distribution.

    Notes
    -----
    Use only when the number of observation in each sample is > 20 and
    you have 2 independent samples of ranks. Mann-Whitney U is
    significant if the u-obtained is LESS THAN or equal to the critical
    value of U.

    This test corrects for ties and by default uses a continuity correction.
    The reported p-value is for a one-sided hypothesis, to get the two-sided
    p-value multiply the returned p-value by 2.

    """
    x = asarray(x)
    y = asarray(y)
    n1 = len(x)
    n2 = len(y)
    ranked = rankdata(np.concatenate((x,y)))
    rankx = ranked[0:n1]       # get the x-ranks
    u1 = n1*n2 + (n1*(n1+1))/2.0 - np.sum(rankx,axis=0)  # calc U for x
    u2 = n1*n2 - u1                            # remainder is U for y
    bigu = max(u1,u2)
    smallu = min(u1,u2)
    T = tiecorrect(ranked)
    if T == 0:
        raise ValueError('All numbers are identical in amannwhitneyu')
    sd = np.sqrt(T*n1*n2*(n1+n2+1)/12.0)

    if use_continuity:
        # normal approximation for prob calc with continuity correction
        z = abs((bigu-0.5-n1*n2/2.0) / sd)
    else:
        z = abs((bigu-n1*n2/2.0) / sd)  # normal approximation for prob calc
    return smallu, distributions.norm.sf(z)  # (1.0 - zprob(z)) 
开发者ID:tedunderwood,项目名称:paceofchange,代码行数:54,代码来源:dunnings_coefficients.py


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