本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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])
示例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)
示例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)
示例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)
示例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)
示例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)
示例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