當前位置: 首頁>>代碼示例>>Python>>正文


Python stats.levene方法代碼示例

本文整理匯總了Python中scipy.stats.levene方法的典型用法代碼示例。如果您正苦於以下問題:Python stats.levene方法的具體用法?Python stats.levene怎麽用?Python stats.levene使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.stats的用法示例。


在下文中一共展示了stats.levene方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_trimmed2

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_trimmed2(self):
        x = [1.2, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 100.0]
        y = [0.0, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 200.0]
        np.random.seed(1234)
        x2 = np.random.permutation(x)

        # Use center='trimmed'
        W0, pval0 = stats.levene(x, y, center='trimmed',
                                 proportiontocut=0.125)
        W1, pval1 = stats.levene(x2, y, center='trimmed',
                                 proportiontocut=0.125)
        # Trim the data here, and use center='mean'
        W2, pval2 = stats.levene(x[1:-1], y[1:-1], center='mean')
        # Result should be the same.
        assert_almost_equal(W0, W2)
        assert_almost_equal(W1, W2)
        assert_almost_equal(pval1, pval2) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:19,代碼來源:test_morestats.py

示例2: test_weightstats_3

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_weightstats_3(self):
        x1_2d, x2_2d = self.x1_2d, self.x2_2d
        w1, w2 = self.w1, self.w2

        d1w_2d = DescrStatsW(x1_2d, weights=w1)
        d2w_2d = DescrStatsW(x2_2d, weights=w2)
        x1r_2d = d1w_2d.asrepeats()
        x2r_2d = d2w_2d.asrepeats()

        assert_almost_equal(x2r_2d.mean(0), d2w_2d.mean, 14)
        assert_almost_equal(x2r_2d.var(0), d2w_2d.var, 14)
        assert_almost_equal(x2r_2d.std(0), d2w_2d.std, 14)
        assert_almost_equal(np.cov(x2r_2d.T, bias=1), d2w_2d.cov, 14)
        assert_almost_equal(np.corrcoef(x2r_2d.T), d2w_2d.corrcoef, 14)

#        print d1w_2d.ttest_mean(3)
#        #scipy.stats.ttest is also vectorized
#        print stats.ttest_1samp(x1r_2d, 3)
        t, p, d = d1w_2d.ttest_mean(3)
        assert_almost_equal([t, p], stats.ttest_1samp(x1r_2d, 3), 11)
        # print [stats.ttest_1samp(xi, 3) for xi in x1r_2d.T]
        cm = CompareMeans(d1w_2d, d2w_2d)
        ressm = cm.ttest_ind()
        resss = stats.ttest_ind(x1r_2d, x2r_2d)
        assert_almost_equal(ressm[:2], resss, 14)

#        doesn't work for 2d, levene doesn't use weights
#        cm = CompareMeans(d1w_2d, d2w_2d)
#        ressm = cm.test_equal_var()
#        resss = stats.levene(x1r_2d, x2r_2d)
#        assert_almost_equal(ressm[:2], resss, 14) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:33,代碼來源:test_weightstats.py

示例3: ztost_ind

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def ztost_ind(self, low, upp, usevar='pooled'):
        '''
        test of equivalence for two independent samples, based on z-test

        Parameters
        ----------
        low, upp : float
            equivalence interval low < m1 - m2 < upp
        usevar : string, 'pooled' or 'unequal'
            If ``pooled``, then the standard deviation of the samples is assumed to be
            the same. If ``unequal``, then Welsh ttest with Satterthwait degrees
            of freedom is used

        Returns
        -------
        pvalue : float
            pvalue of the non-equivalence test
        t1, pv1 : tuple of floats
            test statistic and pvalue for lower threshold test
        t2, pv2 : tuple of floats
            test statistic and pvalue for upper threshold test
        '''
        tt1 = self.ztest_ind(alternative='larger', usevar=usevar, value=low)
        tt2 = self.ztest_ind(alternative='smaller', usevar=usevar, value=upp)
        #TODO: remove tuple return, use same as for function tost_ind
        return np.maximum(tt1[1], tt2[1]), tt1, tt2

    #tost.__doc__ = tost_ind.__doc__

#doesn't work for 2d, doesn't take weights into account
##    def test_equal_var(self):
##        '''Levene test for independence
##
##        '''
##        d1 = self.d1
##        d2 = self.d2
##        #rewrite this, for now just use scipy.stats
##        return stats.levene(d1.data, d2.data) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:40,代碼來源:weightstats.py

示例4: test_data

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_data(self):
        args = [g1, g2, g3, g4, g5, g6, g7, g8, g9, g10]
        W, pval = stats.levene(*args)
        assert_almost_equal(W,1.7059176930008939,7)
        assert_almost_equal(pval,0.0990829755522,7) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:7,代碼來源:test_morestats.py

示例5: test_trimmed1

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_trimmed1(self):
        """Test that center='trimmed' gives the same result as center='mean' when proportiontocut=0."""
        W1, pval1 = stats.levene(g1, g2, g3, center='mean')
        W2, pval2 = stats.levene(g1, g2, g3, center='trimmed', proportiontocut=0.0)
        assert_almost_equal(W1, W2)
        assert_almost_equal(pval1, pval2) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:test_morestats.py

示例6: test_trimmed2

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_trimmed2(self):
        x = [1.2, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 100.0]
        y = [0.0, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 200.0]
        np.random.seed(1234)
        x2 = np.random.permutation(x)

        # Use center='trimmed'
        W0, pval0 = stats.levene(x, y, center='trimmed', proportiontocut=0.125)
        W1, pval1 = stats.levene(x2, y, center='trimmed', proportiontocut=0.125)
        # Trim the data here, and use center='mean'
        W2, pval2 = stats.levene(x[1:-1], y[1:-1], center='mean')
        # Result should be the same.
        assert_almost_equal(W0, W2)
        assert_almost_equal(W1, W2)
        assert_almost_equal(pval1, pval2) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:17,代碼來源:test_morestats.py

示例7: test_equal_mean_median

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_equal_mean_median(self):
        x = np.linspace(-1,1,21)
        np.random.seed(1234)
        x2 = np.random.permutation(x)
        y = x**3
        W1, pval1 = stats.levene(x, y, center='mean')
        W2, pval2 = stats.levene(x2, y, center='median')
        assert_almost_equal(W1, W2)
        assert_almost_equal(pval1, pval2) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:11,代碼來源:test_morestats.py

示例8: test_bad_keyword

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_bad_keyword(self):
        x = np.linspace(-1,1,21)
        assert_raises(TypeError, stats.levene, x, x, portiontocut=0.1) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:5,代碼來源:test_morestats.py

示例9: test_too_few_args

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_too_few_args(self):
        assert_raises(ValueError, stats.levene, [1]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:4,代碼來源:test_morestats.py

示例10: test_data

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_data(self):
        args = [g1, g2, g3, g4, g5, g6, g7, g8, g9, g10]
        W, pval = stats.levene(*args)
        assert_almost_equal(W, 1.7059176930008939, 7)
        assert_almost_equal(pval, 0.0990829755522, 7) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_morestats.py

示例11: test_trimmed1

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_trimmed1(self):
        # Test that center='trimmed' gives the same result as center='mean'
        # when proportiontocut=0.
        W1, pval1 = stats.levene(g1, g2, g3, center='mean')
        W2, pval2 = stats.levene(g1, g2, g3, center='trimmed',
                                 proportiontocut=0.0)
        assert_almost_equal(W1, W2)
        assert_almost_equal(pval1, pval2) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:10,代碼來源:test_morestats.py

示例12: test_equal_mean_median

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_equal_mean_median(self):
        x = np.linspace(-1, 1, 21)
        np.random.seed(1234)
        x2 = np.random.permutation(x)
        y = x**3
        W1, pval1 = stats.levene(x, y, center='mean')
        W2, pval2 = stats.levene(x2, y, center='median')
        assert_almost_equal(W1, W2)
        assert_almost_equal(pval1, pval2) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:11,代碼來源:test_morestats.py

示例13: test_bad_keyword

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_bad_keyword(self):
        x = np.linspace(-1, 1, 21)
        assert_raises(TypeError, stats.levene, x, x, portiontocut=0.1) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:5,代碼來源:test_morestats.py

示例14: test_result_attributes

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def test_result_attributes(self):
        args = [g1, g2, g3, g4, g5, g6, g7, g8, g9, g10]
        res = stats.levene(*args)
        attributes = ('statistic', 'pvalue')
        check_named_results(res, attributes) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_morestats.py

示例15: are_variations_equal

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import levene [as 別名]
def are_variations_equal(THRESHOLD, *args):
    '''
    Return a boolean, if p-value less than threshold, returns false
    '''
    return stats.levene(*args)[1] > THRESHOLD 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:7,代碼來源:utilities.py


注:本文中的scipy.stats.levene方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。