Python scipy.stats.wilcoxon() Examples

The following are code examples for showing how to use scipy.stats.wilcoxon(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
 Project: LaserTOF   Author: kyleuckert   File: test_morestats.py    MIT License 6 votes
```def test_wilcoxon_tie():
# Regression test for gh-2391.
# Corresponding R code is:
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=FALSE)
#   > result\$p.value
#   [1] 0.001565402
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=TRUE)
#   > result\$p.value
#   [1] 0.001904195
stat, p = stats.wilcoxon([0.1] * 10)
expected_p = 0.001565402
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6)

stat, p = stats.wilcoxon([0.1] * 10, correction=True)
expected_p = 0.001904195
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6) ```
Example 2
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_morestats.py    GNU General Public License v3.0 6 votes
```def test_wilcoxon_tie():
# Regression test for gh-2391.
# Corresponding R code is:
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=FALSE)
#   > result\$p.value
#   [1] 0.001565402
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=TRUE)
#   > result\$p.value
#   [1] 0.001904195
stat, p = stats.wilcoxon([0.1] * 10)
expected_p = 0.001565402
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6)

stat, p = stats.wilcoxon([0.1] * 10, correction=True)
expected_p = 0.001904195
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6) ```
Example 3
 Project: watlink   Author: dustalov   File: judgements.py    MIT License 6 votes
```def significance(metric):
if not args.significance:
return {}

desc, rank = sorted(results.items(), key=lambda item: item[1][metric], reverse=True), 1

ranks = {}

for (path1, results1), (path2, results2) in pairwise(desc):
x, y = list(results1['scores'][metric]), list(results2['scores'][metric])

ranks[path1] = rank

rank += int(wilcoxon(x, y).pvalue < args.alpha)

ranks[path2] = rank

return ranks ```
Example 4
 Project: watlink   Author: dustalov   File: pathwise.py    MIT License 6 votes
```def significance(metric):
if not args.significance:
return {}

desc, rank = sorted(results.items(), key=lambda item: item[1][metric], reverse=True), 1

ranks = {}

for (path1, results1), (path2, results2) in pairwise(desc):
x, y = list(results1['scores'][metric]), list(results2['scores'][metric])

ranks[path1] = rank

rank += int(wilcoxon(x, y).pvalue < args.alpha)

ranks[path2] = rank

return metric, ranks ```
Example 5
 Project: ble5-nrf52-mac   Author: tomasero   File: test_morestats.py    MIT License 6 votes
```def test_wilcoxon_tie():
# Regression test for gh-2391.
# Corresponding R code is:
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=FALSE)
#   > result\$p.value
#   [1] 0.001565402
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=TRUE)
#   > result\$p.value
#   [1] 0.001904195
stat, p = stats.wilcoxon([0.1] * 10)
expected_p = 0.001565402
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6)

stat, p = stats.wilcoxon([0.1] * 10, correction=True)
expected_p = 0.001904195
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6) ```
Example 6
 Project: poker   Author: surgebiswas   File: test_morestats.py    MIT License 6 votes
```def test_wilcoxon_tie():
# Regression test for gh-2391.
# Corresponding R code is:
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=FALSE)
#   > result\$p.value
#   [1] 0.001565402
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=TRUE)
#   > result\$p.value
#   [1] 0.001904195
stat, p = stats.wilcoxon([0.1] * 10)
expected_p = 0.001565402
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6)

stat, p = stats.wilcoxon([0.1] * 10, correction=True)
expected_p = 0.001904195
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6) ```
Example 7
 Project: P3_image_processing   Author: latedude2   File: test_morestats.py    MIT License 6 votes
```def test_wilcoxon_tie(self):
# Regression test for gh-2391.
# Corresponding R code is:
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=FALSE)
#   > result\$p.value
#   [1] 0.001565402
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=TRUE)
#   > result\$p.value
#   [1] 0.001904195
stat, p = stats.wilcoxon([0.1] * 10)
expected_p = 0.001565402
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6)

stat, p = stats.wilcoxon([0.1] * 10, correction=True)
expected_p = 0.001904195
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6) ```
Example 8
 Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_morestats.py    MIT License 6 votes
```def test_wilcoxon_tie():
# Regression test for gh-2391.
# Corresponding R code is:
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=FALSE)
#   > result\$p.value
#   [1] 0.001565402
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=TRUE)
#   > result\$p.value
#   [1] 0.001904195
stat, p = stats.wilcoxon([0.1] * 10)
expected_p = 0.001565402
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6)

stat, p = stats.wilcoxon([0.1] * 10, correction=True)
expected_p = 0.001904195
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6) ```
Example 9
 Project: EvoMSA   Author: INGEOTEC   File: utils.py    Apache License 2.0 6 votes
```def compute_p(syss):
from scipy.stats import wilcoxon
p = []
mu = syss.mean(axis=0)
best = mu.argmax()
for i in range(syss.shape[1]):
if i == best:
p.append(np.inf)
continue
try:
pv = wilcoxon(syss[:, best], syss[:, i])[1]
p.append(pv)
except ValueError:
p.append(np.inf)
ps = np.argsort(p)
alpha = [np.inf for _ in ps]
m = ps.shape[0] - 1
for r, i in enumerate(ps[:-1]):
alpha_c = (0.05 / (m + 1 - (r + 1)))
if p[i] > alpha_c:
break
alpha[i] = alpha_c
return p, alpha ```
Example 10
 Project: adaptive-concretization   Author: plum-umd   File: wilcoxon.py    MIT License 6 votes
```def compare(n, data, b, d1, d2):
d1_space = data[b][d1]["search space"] # [ s1_1, s1_2, s1_3, ... ]
d2_space = data[b][d2]["search space"] # [ s2_1, s2_2, s2_3, ... ]
d1_ttime = data[b][d1]["ttime"] # [ (_, t1_1), (_, t1_2), (_, t1_3), ... ]
d2_ttime = data[b][d2]["ttime"] # [ (_, t2_1), (_, t2_2), (_, t2_3), ... ]
# space/ttime may have different length of data
# so, pick the smallest one to avoid out-of-index error
_max_n = min(map(len, [d1_space, d2_space, d1_ttime, d2_ttime]))

# pick n random numbers between 0 to the size of the smallest data set
pop = range(_max_n)
try:
indices = random.sample(pop, n)
except ValueError: # sample larger than population
indices = list(chain.from_iterable(repeat(pop, n / _max_n))) + random.sample(pop, n % _max_n)
except TypeError: # single value
indices = repeat(_max_n, n)

# expected running time = t/p, where p = 1/search space
dist_d1 = [ d1_ttime[idx][1] * d1_space[idx] for idx in indices ]
dist_d2 = [ d2_ttime[idx][1] * d2_space[idx] for idx in indices ]
rank_sum, pvalue = wilcoxon(dist_d1, dist_d2)
return pvalue ```
Example 11
 Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_morestats.py    Apache License 2.0 6 votes
```def test_wilcoxon_tie():
# Regression test for gh-2391.
# Corresponding R code is:
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=FALSE)
#   > result\$p.value
#   [1] 0.001565402
#   > result = wilcox.test(rep(0.1, 10), exact=FALSE, correct=TRUE)
#   > result\$p.value
#   [1] 0.001904195
stat, p = stats.wilcoxon([0.1] * 10)
expected_p = 0.001565402
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6)

stat, p = stats.wilcoxon([0.1] * 10, correction=True)
expected_p = 0.001904195
assert_equal(stat, 0)
assert_allclose(p, expected_p, rtol=1e-6) ```
Example 12
 Project: stereo-magnification   Author: google   File: rank.py    Apache License 2.0 6 votes
```def main(_):
stats = FLAGS.stats.split(',')
root = FLAGS.root
model_names = FLAGS.model_names.split(',')

data = {}
for m in model_names:
d = load_data(root, m)
merge_into(data, d)

print '\nLOADED %d models, %d examples' % (len(data['models']),
len(data['examples']))

if 'mean' in stats:
compute_mean(data)
if 'rank' in stats:
compute_rank(data)
if 'diff' in stats:
compute_diff(data)
if 'wilcoxon' in stats:
compute_wilcoxon(data)
print ```
Example 13
 Project: InDepth-Analysis   Author: adiyoss   File: check_significance.py    MIT License 6 votes
```def calc_significance(path_1, path_2):

for i in range(len(x1)):
if x1[i] == 0.0:
x1[i] = 1.0
elif x1[i] == 1.0:
x1[i] = 0.0

if x2[i] == 0.0:
x2[i] = 1.0
elif x2[i] == 1.0:
x2[i] = 0.0
t, p = stats.wilcoxon(x1, x2)
# t, p = stats.ttest_rel(x1, x2)
# t, p = stats.ttest_ind(x1, x2, equal_var=False)
return t, p ```
Example 14
 Project: pathway-forte   Author: pathwayforte   File: distribution.py    Apache License 2.0 5 votes
```def get_equivalent_mapping_paired_test(
df: pd.DataFrame,
source_db: str,
target_db: str,
*,
database_column_name: str,
identifier_column_name: str,
pval_column_name: str,
equivalent_mappings_dict: Optional[EquivalenceMapping] = None,
test: str = 'wilcoxon',
) -> float:
"""Remap the p-values of the equivalent pathways to conduct paired test."""
remapped_df = remap_comparison_df(
df=df,
source_db=source_db,
target_db=target_db,
database_column_name=database_column_name,
identifier_column_name=identifier_column_name,
pval_column_name=pval_column_name,
equivalent_mappings_dict=equivalent_mappings_dict,
)
if 0 == len(remapped_df):
raise ValueError(f'No comparison for {source_db} and {target_db}')

if test == 'wilcoxon':
test = wilcoxon
elif test == 'ks':
test = partial(kstest, cdf='uniform')
else:
raise ValueError('invalid test type: {test}')

_, p_value = test(remapped_df['mlp_diff'].tolist())
return p_value ```
Example 15
 Project: LaserTOF   Author: kyleuckert   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_bad_arg():
# Raise ValueError when two args of different lengths are given or
# zero_method is unknown.
assert_raises(ValueError, stats.wilcoxon, [1], [1, 2])
assert_raises(ValueError, stats.wilcoxon, [1, 2], [1, 2], "dummy") ```
Example 16
 Project: LaserTOF   Author: kyleuckert   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_arg_type():
# Should be able to accept list as arguments.
# Address issue 6070.
arr = [1, 2, 3, 0, -1, 3, 1, 2, 1, 1, 2]

_ = stats.wilcoxon(arr, zero_method="pratt")
_ = stats.wilcoxon(arr, zero_method="zsplit")
_ = stats.wilcoxon(arr, zero_method="wilcox") ```
Example 17
 Project: LaserTOF   Author: kyleuckert   File: test_morestats.py    MIT License 5 votes
```def test_accuracy_wilcoxon():
freq = [1, 4, 16, 15, 8, 4, 5, 1, 2]
nums = range(-4, 5)
x = np.concatenate([[u] * v for u, v in zip(nums, freq)])
y = np.zeros(x.size)

T, p = stats.wilcoxon(x, y, "pratt")
assert_allclose(T, 423)
assert_allclose(p, 0.00197547303533107)

T, p = stats.wilcoxon(x, y, "zsplit")
assert_allclose(T, 441)
assert_allclose(p, 0.0032145343172473055)

T, p = stats.wilcoxon(x, y, "wilcox")
assert_allclose(T, 327)
assert_allclose(p, 0.00641346115861)

# Test the 'correction' option, using values computed in R with:
# > wilcox.test(x, y, paired=TRUE, exact=FALSE, correct={FALSE,TRUE})
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
T, p = stats.wilcoxon(x, y, correction=False)
assert_equal(T, 34)
assert_allclose(p, 0.6948866, rtol=1e-6)
T, p = stats.wilcoxon(x, y, correction=True)
assert_equal(T, 34)
assert_allclose(p, 0.7240817, rtol=1e-6) ```
Example 18
 Project: LaserTOF   Author: kyleuckert   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_result_attributes():
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
res = stats.wilcoxon(x, y, correction=False)
attributes = ('statistic', 'pvalue')
check_named_results(res, attributes) ```
Example 19
 Project: edge2vec   Author: RoyZhengGao   File: transition.py    BSD 3-Clause "New" or "Revised" License 5 votes
```def wilcoxon_test(v1,v2):# original metric: the smaller the more similar
result = stats.wilcoxon(v1, v2).statistic
if result != result:
result = 0
return 1/(math.sqrt(result)+1) ```
Example 20
 Project: edge2vec   Author: RoyZhengGao   File: transition.py    BSD 3-Clause "New" or "Revised" License 5 votes
```def entroy_test(v1,v2):#original metric: the smaller the more similar
result = stats.entropy(v1,v2)
result = stats.wilcoxon(v1, v2).statistic
if result != result:
result = 0
return result ```
Example 21
 Project: edge2vec   Author: RoyZhengGao   File: transition.py    BSD 3-Clause "New" or "Revised" License 5 votes
```def spearmanr_test(v1,v2):#original metric: the larger the more similar
result = stats.mstats.spearmanr(v1,v2).correlation
result = stats.wilcoxon(v1, v2).statistic
if result != result:
result = -1
return sigmoid(result) ```
Example 22
 Project: edge2vec   Author: RoyZhengGao   File: transition.py    BSD 3-Clause "New" or "Revised" License 5 votes
```def pearsonr_test(v1,v2):#original metric: the larger the more similar
result = stats.mstats.pearsonr(v1,v2)[0]
result = stats.wilcoxon(v1, v2).statistic
if result != result:
result = -1
return sigmoid(result) ```
Example 23
 Project: jr-tools   Author: kingjr   File: base.py    BSD 2-Clause "Simplified" License 5 votes
```def _loop_wilcoxon(X, zero_method, correction):
from scipy.stats import wilcoxon
p_val = np.ones(X.shape[1])
stats = np.ones(X.shape[1])
for ii, x in enumerate(X.T):
stats[ii], p_val[ii] = wilcoxon(x)
return stats, p_val ```
Example 24
 Project: jr-tools   Author: kingjr   File: gat_stats.py    BSD 2-Clause "Simplified" License 5 votes
```def _my_wilcoxon(X):
out = wilcoxon(X)
return out[1] ```
Example 25
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_morestats.py    GNU General Public License v3.0 5 votes
```def test_wilcoxon_bad_arg():
# Raise ValueError when two args of different lengths are given or
# zero_method is unknown.
assert_raises(ValueError, stats.wilcoxon, [1], [1,2])
assert_raises(ValueError, stats.wilcoxon, [1,2], [1,2], "dummy") ```
Example 26
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_morestats.py    GNU General Public License v3.0 5 votes
```def test_accuracy_wilcoxon():
freq = [1, 4, 16, 15, 8, 4, 5, 1, 2]
nums = range(-4, 5)
x = np.concatenate([[u] * v for u, v in zip(nums, freq)])
y = np.zeros(x.size)

T, p = stats.wilcoxon(x, y, "pratt")
assert_allclose(T, 423)
assert_allclose(p, 0.00197547303533107)

T, p = stats.wilcoxon(x, y, "zsplit")
assert_allclose(T, 441)
assert_allclose(p, 0.0032145343172473055)

T, p = stats.wilcoxon(x, y, "wilcox")
assert_allclose(T, 327)
assert_allclose(p, 0.00641346115861)

# Test the 'correction' option, using values computed in R with:
# > wilcox.test(x, y, paired=TRUE, exact=FALSE, correct={FALSE,TRUE})
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
T, p = stats.wilcoxon(x, y, correction=False)
assert_equal(T, 34)
assert_allclose(p, 0.6948866, rtol=1e-6)
T, p = stats.wilcoxon(x, y, correction=True)
assert_equal(T, 34)
assert_allclose(p, 0.7240817, rtol=1e-6) ```
Example 27
 Project: NeuralCR   Author: a-arbabi   File: t_test_eval.py    MIT License 5 votes
```def paired_test_per_document_fscore(label_dir, output_dir_a, output_dir_b, file_list, ont, column_a, column_b, is_mimic=False, snomed2icd=None):
dicts = {}
if not is_mimic:
dicts['model_a'] = get_matrix_dict(label_dir, output_dir_a, file_list, ont, column=column_a)
dicts['model_b'] = get_matrix_dict(label_dir, output_dir_b, file_list, ont, column=column_b)
else:
dicts['model_a'] = get_matrix_dict_mimic(label_dir, output_dir_a, file_list, ont, snomed2icd, column=column_a)
dicts['model_b'] = get_matrix_dict_mimic(label_dir, output_dir_b, file_list, ont, snomed2icd, column=column_b)
heading = [('ord', 'tp'),('ord', 'fp'),('ord', 'rp')]
f1_list = {'model_a':[],'model_b':[]}
for filename in sorted(file_list):
for mod in sorted(dicts.keys()):
tp = dicts[mod]['ord']['tp'][filename]
fp = dicts[mod]['ord']['fp'][filename]
rp = dicts[mod]['ord']['rp'][filename]
recall = tp/rp if rp!=0 else 1.0
precision = tp/(tp+fp) if tp+fp!=0 else 1.0
f1 = get_fmeasure(precision, recall)
f1_list[mod].append(f1)

return {'mean_a': np.mean(f1_list['model_a']),
'mean_b': np.mean(f1_list['model_b']),
't-test': stats.ttest_rel(
np.array(f1_list['model_a']), np.array(f1_list['model_b'])),
'wilcoxon': stats.wilcoxon(
np.array(f1_list['model_a']), np.array(f1_list['model_b'])),
'wilcoxon-pratt': stats.wilcoxon(
np.array(f1_list['model_a']), np.array(f1_list['model_b']),
zero_method='pratt')} ```
Example 28
 Project: ble5-nrf52-mac   Author: tomasero   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_bad_arg():
# Raise ValueError when two args of different lengths are given or
# zero_method is unknown.
assert_raises(ValueError, stats.wilcoxon, [1], [1, 2])
assert_raises(ValueError, stats.wilcoxon, [1, 2], [1, 2], "dummy") ```
Example 29
 Project: ble5-nrf52-mac   Author: tomasero   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_arg_type():
# Should be able to accept list as arguments.
# Address issue 6070.
arr = [1, 2, 3, 0, -1, 3, 1, 2, 1, 1, 2]

_ = stats.wilcoxon(arr, zero_method="pratt")
_ = stats.wilcoxon(arr, zero_method="zsplit")
_ = stats.wilcoxon(arr, zero_method="wilcox") ```
Example 30
 Project: ble5-nrf52-mac   Author: tomasero   File: test_morestats.py    MIT License 5 votes
```def test_accuracy_wilcoxon():
freq = [1, 4, 16, 15, 8, 4, 5, 1, 2]
nums = range(-4, 5)
x = np.concatenate([[u] * v for u, v in zip(nums, freq)])
y = np.zeros(x.size)

T, p = stats.wilcoxon(x, y, "pratt")
assert_allclose(T, 423)
assert_allclose(p, 0.00197547303533107)

T, p = stats.wilcoxon(x, y, "zsplit")
assert_allclose(T, 441)
assert_allclose(p, 0.0032145343172473055)

T, p = stats.wilcoxon(x, y, "wilcox")
assert_allclose(T, 327)
assert_allclose(p, 0.00641346115861)

# Test the 'correction' option, using values computed in R with:
# > wilcox.test(x, y, paired=TRUE, exact=FALSE, correct={FALSE,TRUE})
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
T, p = stats.wilcoxon(x, y, correction=False)
assert_equal(T, 34)
assert_allclose(p, 0.6948866, rtol=1e-6)
T, p = stats.wilcoxon(x, y, correction=True)
assert_equal(T, 34)
assert_allclose(p, 0.7240817, rtol=1e-6) ```
Example 31
 Project: ble5-nrf52-mac   Author: tomasero   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_result_attributes():
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
res = stats.wilcoxon(x, y, correction=False)
attributes = ('statistic', 'pvalue')
check_named_results(res, attributes) ```
Example 32
 Project: Computable   Author: ktraunmueller   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_bad_arg():
"""Raise ValueError when two args of different lengths are given or
zero_method is unknwon"""
assert_raises(ValueError, stats.wilcoxon, [1], [1,2])
assert_raises(ValueError, stats.wilcoxon, [1,2], [1,2], "dummy") ```
Example 33
 Project: Computable   Author: ktraunmueller   File: test_morestats.py    MIT License 5 votes
```def test_accuracy_wilcoxon():
freq = [1, 4, 16, 15, 8, 4, 5, 1, 2]
nums = range(-4, 5)
x = np.concatenate([[u] * v for u, v in zip(nums, freq)])
y = np.zeros(x.size)

T, p = stats.wilcoxon(x, y, "pratt")
assert_allclose(T, 423)
assert_allclose(p, 0.00197547303533107)

T, p = stats.wilcoxon(x, y, "zsplit")
assert_allclose(T, 441)
assert_allclose(p, 0.0032145343172473055)

T, p = stats.wilcoxon(x, y, "wilcox")
assert_allclose(T, 327)
assert_allclose(p, 0.00641346115861)

# Test the 'correction' option, using values computed in R with:
# > wilcox.test(x, y, paired=TRUE, exact=FALSE, correct={FALSE,TRUE})
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
T, p = stats.wilcoxon(x, y, correction=False)
assert_equal(T, 34)
assert_allclose(p, 0.6948866, rtol=1e-6)
T, p = stats.wilcoxon(x, y, correction=True)
assert_equal(T, 34)
assert_allclose(p, 0.7240817, rtol=1e-6) ```
Example 34
 Project: poker   Author: surgebiswas   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_bad_arg():
# Raise ValueError when two args of different lengths are given or
# zero_method is unknown.
assert_raises(ValueError, stats.wilcoxon, [1], [1,2])
assert_raises(ValueError, stats.wilcoxon, [1,2], [1,2], "dummy") ```
Example 35
 Project: poker   Author: surgebiswas   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_arg_type():
# Should be able to accept list as arguments.
# Address issue 6070.
arr = [1, 2, 3, 0, -1, 3, 1, 2, 1, 1, 2]

_ = stats.wilcoxon(arr, zero_method="pratt")
_ = stats.wilcoxon(arr, zero_method="zsplit")
_ = stats.wilcoxon(arr, zero_method="wilcox") ```
Example 36
 Project: poker   Author: surgebiswas   File: test_morestats.py    MIT License 5 votes
```def test_accuracy_wilcoxon():
freq = [1, 4, 16, 15, 8, 4, 5, 1, 2]
nums = range(-4, 5)
x = np.concatenate([[u] * v for u, v in zip(nums, freq)])
y = np.zeros(x.size)

T, p = stats.wilcoxon(x, y, "pratt")
assert_allclose(T, 423)
assert_allclose(p, 0.00197547303533107)

T, p = stats.wilcoxon(x, y, "zsplit")
assert_allclose(T, 441)
assert_allclose(p, 0.0032145343172473055)

T, p = stats.wilcoxon(x, y, "wilcox")
assert_allclose(T, 327)
assert_allclose(p, 0.00641346115861)

# Test the 'correction' option, using values computed in R with:
# > wilcox.test(x, y, paired=TRUE, exact=FALSE, correct={FALSE,TRUE})
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
T, p = stats.wilcoxon(x, y, correction=False)
assert_equal(T, 34)
assert_allclose(p, 0.6948866, rtol=1e-6)
T, p = stats.wilcoxon(x, y, correction=True)
assert_equal(T, 34)
assert_allclose(p, 0.7240817, rtol=1e-6) ```
Example 37
 Project: poker   Author: surgebiswas   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_result_attributes():
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
res = stats.wilcoxon(x, y, correction=False)
attributes = ('statistic', 'pvalue')
check_named_results(res, attributes) ```
Example 38
 Project: P3_image_processing   Author: latedude2   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_bad_arg(self):
# Raise ValueError when two args of different lengths are given or
# zero_method is unknown.
assert_raises(ValueError, stats.wilcoxon, [1], [1, 2])
assert_raises(ValueError, stats.wilcoxon, [1, 2], [1, 2], "dummy")
assert_raises(ValueError, stats.wilcoxon, [1, 2], [1, 2],
alternative="dummy") ```
Example 39
 Project: P3_image_processing   Author: latedude2   File: test_morestats.py    MIT License 5 votes
```def test_zero_diff(self):
x = np.arange(20)
# pratt and wilcox do not work if x - y == 0
assert_raises(ValueError, stats.wilcoxon, x, x, "wilcox")
assert_raises(ValueError, stats.wilcoxon, x, x, "pratt")
# ranksum is n*(n+1)/2, split in half if method == "zsplit"
assert_equal(stats.wilcoxon(x, x, "zsplit"), (20*21/4, 1.0)) ```
Example 40
 Project: P3_image_processing   Author: latedude2   File: test_morestats.py    MIT License 5 votes
```def test_pratt(self):
# regression test for gh-6805: p-value matches value from R package
# coin (wilcoxsign_test) reported in the issue
x = [1, 2, 3, 4]
y = [1, 2, 3, 5]
with suppress_warnings() as sup:
sup.filter(UserWarning, message="Sample size too small")
res = stats.wilcoxon(x, y, zero_method="pratt")
assert_allclose(res, (0.0, 0.31731050786291415)) ```
Example 41
 Project: P3_image_processing   Author: latedude2   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_arg_type(self):
# Should be able to accept list as arguments.
# Address issue 6070.
arr = [1, 2, 3, 0, -1, 3, 1, 2, 1, 1, 2]

_ = stats.wilcoxon(arr, zero_method="pratt")
_ = stats.wilcoxon(arr, zero_method="zsplit")
_ = stats.wilcoxon(arr, zero_method="wilcox") ```
Example 42
 Project: P3_image_processing   Author: latedude2   File: test_morestats.py    MIT License 5 votes
```def test_accuracy_wilcoxon(self):
freq = [1, 4, 16, 15, 8, 4, 5, 1, 2]
nums = range(-4, 5)
x = np.concatenate([[u] * v for u, v in zip(nums, freq)])
y = np.zeros(x.size)

T, p = stats.wilcoxon(x, y, "pratt")
assert_allclose(T, 423)
assert_allclose(p, 0.0031724568006762576)

T, p = stats.wilcoxon(x, y, "zsplit")
assert_allclose(T, 441)
assert_allclose(p, 0.0032145343172473055)

T, p = stats.wilcoxon(x, y, "wilcox")
assert_allclose(T, 327)
assert_allclose(p, 0.00641346115861)

# Test the 'correction' option, using values computed in R with:
# > wilcox.test(x, y, paired=TRUE, exact=FALSE, correct={FALSE,TRUE})
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
T, p = stats.wilcoxon(x, y, correction=False)
assert_equal(T, 34)
assert_allclose(p, 0.6948866, rtol=1e-6)
T, p = stats.wilcoxon(x, y, correction=True)
assert_equal(T, 34)
assert_allclose(p, 0.7240817, rtol=1e-6) ```
Example 43
 Project: P3_image_processing   Author: latedude2   File: test_morestats.py    MIT License 5 votes
```def test_onesided(self):
# tested against "R version 3.4.1 (2017-06-30)"
# x <- c(125, 115, 130, 140, 140, 115, 140, 125, 140, 135)
# y <- c(110, 122, 125, 120, 140, 124, 123, 137, 135, 145)
# cfg <- list(x = x, y = y, paired = TRUE, exact = FALSE)
# do.call(wilcox.test, c(cfg, list(alternative = "less", correct = FALSE)))
# do.call(wilcox.test, c(cfg, list(alternative = "less", correct = TRUE)))
# do.call(wilcox.test, c(cfg, list(alternative = "greater", correct = FALSE)))
# do.call(wilcox.test, c(cfg, list(alternative = "greater", correct = TRUE)))
x = [125, 115, 130, 140, 140, 115, 140, 125, 140, 135]
y = [110, 122, 125, 120, 140, 124, 123, 137, 135, 145]

with suppress_warnings() as sup:
sup.filter(UserWarning, message="Sample size too small")
w, p = stats.wilcoxon(x, y, alternative="less")
assert_equal(w, 27)
assert_almost_equal(p, 0.7031847, decimal=6)

with suppress_warnings() as sup:
sup.filter(UserWarning, message="Sample size too small")
w, p = stats.wilcoxon(x, y, alternative="less", correction=True)
assert_equal(w, 27)
assert_almost_equal(p, 0.7233656, decimal=6)

with suppress_warnings() as sup:
sup.filter(UserWarning, message="Sample size too small")
w, p = stats.wilcoxon(x, y, alternative="greater")
assert_equal(w, 27)
assert_almost_equal(p, 0.2968153, decimal=6)

with suppress_warnings() as sup:
sup.filter(UserWarning, message="Sample size too small")
w, p = stats.wilcoxon(x, y, alternative="greater", correction=True)
assert_equal(w, 27)
assert_almost_equal(p, 0.3176447, decimal=6) ```
Example 44
 Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_bad_arg():
# Raise ValueError when two args of different lengths are given or
# zero_method is unknown.
assert_raises(ValueError, stats.wilcoxon, [1], [1, 2])
assert_raises(ValueError, stats.wilcoxon, [1, 2], [1, 2], "dummy") ```
Example 45
 Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_arg_type():
# Should be able to accept list as arguments.
# Address issue 6070.
arr = [1, 2, 3, 0, -1, 3, 1, 2, 1, 1, 2]

_ = stats.wilcoxon(arr, zero_method="pratt")
_ = stats.wilcoxon(arr, zero_method="zsplit")
_ = stats.wilcoxon(arr, zero_method="wilcox") ```
Example 46
 Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_morestats.py    MIT License 5 votes
```def test_accuracy_wilcoxon():
freq = [1, 4, 16, 15, 8, 4, 5, 1, 2]
nums = range(-4, 5)
x = np.concatenate([[u] * v for u, v in zip(nums, freq)])
y = np.zeros(x.size)

T, p = stats.wilcoxon(x, y, "pratt")
assert_allclose(T, 423)
assert_allclose(p, 0.00197547303533107)

T, p = stats.wilcoxon(x, y, "zsplit")
assert_allclose(T, 441)
assert_allclose(p, 0.0032145343172473055)

T, p = stats.wilcoxon(x, y, "wilcox")
assert_allclose(T, 327)
assert_allclose(p, 0.00641346115861)

# Test the 'correction' option, using values computed in R with:
# > wilcox.test(x, y, paired=TRUE, exact=FALSE, correct={FALSE,TRUE})
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
T, p = stats.wilcoxon(x, y, correction=False)
assert_equal(T, 34)
assert_allclose(p, 0.6948866, rtol=1e-6)
T, p = stats.wilcoxon(x, y, correction=True)
assert_equal(T, 34)
assert_allclose(p, 0.7240817, rtol=1e-6) ```
Example 47
 Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_morestats.py    MIT License 5 votes
```def test_wilcoxon_result_attributes():
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
res = stats.wilcoxon(x, y, correction=False)
attributes = ('statistic', 'pvalue')
check_named_results(res, attributes) ```
Example 48
 Project: drifter_ml   Author: EricSchles   File: columnar_tests.py    MIT License 5 votes
```def wilcoxon_similar_distribution(self, column,
pvalue_threshold=0.05,
num_rounds=3):
p_value = permutation_test(
self.new_data[column],
self.historical_data[column],
method="approximate",
num_rounds=num_rounds,
func=lambda x, y: stats.wilcoxon(x, y).statistic,
seed=0)
if p_value < pvalue_threshold:
return False
return True ```
Example 49
 Project: ecg-detectors   Author: luishowell   File: show_stats_plots.py    GNU General Public License v3.0 5 votes
```def compare_det_test(results_df, detector_name1, detector_name2, experiment=None):
se1 = get_sensivities(results_df, detector_name1, experiment)
if len(se1) < 2:
return 0
se2 = get_sensivities(results_df, detector_name2, experiment)
if len(se2) < 2:
return 0
l = min(len(se1),len(se2))
#print("1:",se1[:l])
#print("2:",se2[:l])
try:
t,p = stats.wilcoxon(se1[:l],se2[:l])
return p
except:
return None ```
Example 50
 Project: ecg-detectors   Author: luishowell   File: show_stats_plots.py    GNU General Public License v3.0 5 votes
```def compare_cables(results_df1,results_df2,det1,experiment):
se1 = get_sensivities(results_df1, det1, experiment)
if len(se1) < 2:
return 0
se2 = get_sensivities(results_df2, det1, experiment)
if len(se2) < 2:
return 0
l = min(len(se1),len(se2))
try:
t,p = stats.wilcoxon(se1[:l],se2[:l])
return p
except:
return None ```
Example 51
 Project: ecg-detectors   Author: luishowell   File: show_stats_plots.py    GNU General Public License v3.0 5 votes
```def compare_experiments(results_df1,det1):
se1 = get_sensivities(results_df1, det1, 'sitting')
if len(se1) < 2:
return 0
se2 = get_sensivities(results_df1, det1, 'jogging')
if len(se2) < 2:
return 0
l = min(len(se1),len(se2))
try:
t,p = stats.wilcoxon(se1[:l],se2[:l])
return p
except:
return None ```
Example 52
 Project: grocsvs   Author: grocsvs   File: structuralvariants.py    MIT License 5 votes
```def score_event(nx, ny, ncommon, barcode_frequencies, resamples=100):
"""
perform a resampling test, based on the number of fragments in each region
and the barcode frequency distribution (the latter because some barcodes
have more DNA in them than others)
"""

samples = []
for _ in range(resamples):
s1 = numpy.random.choice(len(barcode_frequencies), nx, replace=False, p=barcode_frequencies)
s2 = numpy.random.choice(len(barcode_frequencies), ny, replace=False, p=barcode_frequencies)
common = len(set(s1).intersection(set(s2)))
samples.append(common)

# make a one-sided one-sample Wilcoxon test
statistic, pvalue = stats.wilcoxon(numpy.array(samples)-ncommon)
if numpy.mean(samples) > ncommon:
pvalue = 1 - pvalue/2.0
else:
pvalue = pvalue/2.0

# result = r["wilcox.test"](samples, mu=ncommon, alternative="less")
# pvalue2 = result.rx2("p.value")[0]

# print "::::::", nx, ny, ncommon, (numpy.array(samples)>ncommon).sum(), pvalue, pvalue2
return pvalue ```
Example 53
 Project: pyPTE   Author: patrk   File: stats.py    GNU General Public License v3.0 5 votes
```def matrix_wilcoxon(x_matrices, y_matrices, alpha = 0.05, bonferroni=True):
x = list()
y = list()
for data_frame in x_matrices:
x.append(data_frame.as_matrix())
for data_frame in y_matrices:
y.append(data_frame.as_matrix())

p_values = np.zeros_like(x[0])

m, n = p_values.shape

alpha_c = alpha
if bonferroni:
alpha_c = alpha*m**2

for i in range(0, m):
for j in range(0, m):
temp_x = list()
temp_y = list()
for matrix in x:
temp_x.append(matrix[i, j])
for matrix in y:
temp_y.append(matrix[i, j])
s, p = wilcoxon(temp_x, temp_y)

p_values[i, j] = p

if p < alpha_c:
p_mask[i, j] = False
else:
p_mask[i, j] = True

p_values_df = pd.DataFrame(p_values, index=x_matrices[0].index, columns=x_matrices[0].columns)

return p_values_df, p_mask_df ```
Example 54
 Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_morestats.py    Apache License 2.0 5 votes
```def test_wilcoxon_bad_arg():
# Raise ValueError when two args of different lengths are given or
# zero_method is unknown.
assert_raises(ValueError, stats.wilcoxon, [1], [1, 2])
assert_raises(ValueError, stats.wilcoxon, [1, 2], [1, 2], "dummy") ```
Example 55
 Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_morestats.py    Apache License 2.0 5 votes
```def test_wilcoxon_arg_type():
# Should be able to accept list as arguments.
# Address issue 6070.
arr = [1, 2, 3, 0, -1, 3, 1, 2, 1, 1, 2]

_ = stats.wilcoxon(arr, zero_method="pratt")
_ = stats.wilcoxon(arr, zero_method="zsplit")
_ = stats.wilcoxon(arr, zero_method="wilcox") ```
Example 56
 Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_morestats.py    Apache License 2.0 5 votes
```def test_accuracy_wilcoxon():
freq = [1, 4, 16, 15, 8, 4, 5, 1, 2]
nums = range(-4, 5)
x = np.concatenate([[u] * v for u, v in zip(nums, freq)])
y = np.zeros(x.size)

T, p = stats.wilcoxon(x, y, "pratt")
assert_allclose(T, 423)
assert_allclose(p, 0.00197547303533107)

T, p = stats.wilcoxon(x, y, "zsplit")
assert_allclose(T, 441)
assert_allclose(p, 0.0032145343172473055)

T, p = stats.wilcoxon(x, y, "wilcox")
assert_allclose(T, 327)
assert_allclose(p, 0.00641346115861)

# Test the 'correction' option, using values computed in R with:
# > wilcox.test(x, y, paired=TRUE, exact=FALSE, correct={FALSE,TRUE})
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
T, p = stats.wilcoxon(x, y, correction=False)
assert_equal(T, 34)
assert_allclose(p, 0.6948866, rtol=1e-6)
T, p = stats.wilcoxon(x, y, correction=True)
assert_equal(T, 34)
assert_allclose(p, 0.7240817, rtol=1e-6) ```
Example 57
 Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_morestats.py    Apache License 2.0 5 votes
```def test_wilcoxon_result_attributes():
x = np.array([120, 114, 181, 188, 180, 146, 121, 191, 132, 113, 127, 112])
y = np.array([133, 143, 119, 189, 112, 199, 198, 113, 115, 121, 142, 187])
res = stats.wilcoxon(x, y, correction=False)
attributes = ('statistic', 'pvalue')
check_named_results(res, attributes) ```
Example 58
 Project: NeuralCR   Author: ccmbioinfo   File: t_test_eval.py    MIT License 5 votes
```def paired_test_per_document_fscore(label_dir, output_dir_a, output_dir_b, file_list, ont, column_a, column_b, is_mimic=False, snomed2icd=None):
dicts = {}
if not is_mimic:
dicts['model_a'] = get_matrix_dict(label_dir, output_dir_a, file_list, ont, column=column_a)
dicts['model_b'] = get_matrix_dict(label_dir, output_dir_b, file_list, ont, column=column_b)
else:
dicts['model_a'] = get_matrix_dict_mimic(label_dir, output_dir_a, file_list, ont, snomed2icd, column=column_a)
dicts['model_b'] = get_matrix_dict_mimic(label_dir, output_dir_b, file_list, ont, snomed2icd, column=column_b)
heading = [('ord', 'tp'),('ord', 'fp'),('ord', 'rp')]
f1_list = {'model_a':[],'model_b':[]}
for filename in sorted(file_list):
for mod in sorted(dicts.keys()):
tp = dicts[mod]['ord']['tp'][filename]
fp = dicts[mod]['ord']['fp'][filename]
rp = dicts[mod]['ord']['rp'][filename]
recall = tp/rp if rp!=0 else 1.0
precision = tp/(tp+fp) if tp+fp!=0 else 1.0
f1 = get_fmeasure(precision, recall)
f1_list[mod].append(f1)

return {'mean_a': np.mean(f1_list['model_a']),
'mean_b': np.mean(f1_list['model_b']),
't-test': stats.ttest_rel(
np.array(f1_list['model_a']), np.array(f1_list['model_b'])),
'wilcoxon': stats.wilcoxon(
np.array(f1_list['model_a']), np.array(f1_list['model_b'])),
'wilcoxon-pratt': stats.wilcoxon(
np.array(f1_list['model_a']), np.array(f1_list['model_b']),
zero_method='pratt')} ```
Example 59
 Project: stereo-magnification   Author: google   File: rank.py    Apache License 2.0 5 votes
```def compute_wilcoxon(data):
print '\nWILCOXON SIGNED-RANK TEST\n'
# We take the first model as the basis for each comparison.
ssim = np.array(data['ssim'])
psnr = np.array(data['psnr'])
for i, m in enumerate(data['models']):
if i == 0:
print '    [differences from %s]' % m
continue
ssim_v, ssim_p = wilcoxon(ssim[:, i], ssim[:, 0])
psnr_v, psnr_p = wilcoxon(psnr[:, i], psnr[:, 0])
print '%30s    ssim %.3f, p %.1e    psnr %.2f, p %.1e' % (m, ssim_v, ssim_p,
psnr_v, psnr_p) ```
Example 60
 Project: csmri-refinement   Author: mseitzer   File: statistics.py    Apache License 2.0 5 votes
```def compute_wilcoxon(series1, series2):
return wilcoxon(series1, series2) ```
Example 61
 Project: csmri-refinement   Author: mseitzer   File: summarize_results.py    Apache License 2.0 5 votes
```def statistical_testing(args, metrics_by_input, groups_by_name):
test_fn = ttest_rel if args.stest_mode == 'ttest' else wilcoxon

# Get group averages
samples_by_name = {}
for name, group in groups_by_name.items():
gmeans = np.mean([metrics_by_input[inp] for inp in group], axis=0)
samples_by_name[name] = gmeans

perms = permutations(samples_by_name.items(), 2)

if args.sprint:
print('Performing {}'.format(args.stest_mode))
tested_names = set()
pvalues_by_name = {}
for (n1, s1), (n2, s2) in perms:
if n1 not in tested_names:
if args.sprint:
print('Testing {} against:'.format(n1))

assert len(s1) == len(s2)

test = test_fn(s1, s2)
pvalues_by_name.setdefault(n1, []).append(test.pvalue)
if args.sprint:
print('\t{}: {:.4f}'.format(n2, test.pvalue))

significantly_different_names = []
for name, pvalues in pvalues_by_name.items():
if all((p < args.slvl) for p in pvalues):
significantly_different_names.append(name)
if args.sprint:
print(('{} ({:.3f}) has p < {} '
'for all other inputs').format(name,
samples_by_name[name].mean(),
args.slvl))

return significantly_different_names ```
Example 62
 Project: GCIT   Author: alexisbellot   File: utils.py    MIT License 5 votes
```def wilcox(X,Y):

X = X.reshape((len(X)))
Y = Y.reshape((len(Y)))
return wilcoxon(X, Y)[0] ```
Example 63
 Project: senior-design   Author: james-tate   File: test_morestats.py    GNU General Public License v2.0 5 votes
```def test_wilcoxon_bad_arg():
"""Raise ValueError when two args of different lengths are given."""
assert_raises(ValueError, stats.wilcoxon, [1], [1,2]) ```
Example 64
 Project: sktime   Author: alan-turing-institute   File: evaluation.py    BSD 3-Clause "New" or "Revised" License 5 votes
```def wilcoxon_test(self, metric_name=None):
"""http://en.wikipedia.org/wiki/Wilcoxon_signed-rank_test
`Wilcoxon signed-rank test <https://en.wikipedia.org/wiki/Wilcoxon_signed-rank_test>`_.
Tests whether two  related paired samples come from the same distribution.
In particular, it tests whether the distribution of the differences x-y is symmetric about zero
"""
self._check_is_evaluated()
metric_name = self._validate_metric_name(metric_name)
metrics_per_estimator_dataset = self._get_metrics_per_estimator_dataset(metric_name)

wilcoxon_df = pd.DataFrame()
values = np.array([])
prod = itertools.product(metrics_per_estimator_dataset.keys(), repeat=2)
for p in prod:
estim_1 = p[0]
estim_2 = p[1]
w, p_val = stats.wilcoxon(metrics_per_estimator_dataset[p[0]],
metrics_per_estimator_dataset[p[1]])

w_test = {
"estimator_1": estim_1,
"estimator_2": estim_2,
"statistic": w,
"p_val": p_val
}

wilcoxon_df = wilcoxon_df.append(w_test, ignore_index=True)
values = np.append(values, w)
values = np.append(values, p_val)

index = wilcoxon_df["estimator_1"].unique()
values_names = ["statistic", "p_val"]
col_idx = pd.MultiIndex.from_product([index, values_names])
values_reshaped = values.reshape(len(index), len(values_names) * len(index))

values_df_multiindex = pd.DataFrame(values_reshaped, index=index, columns=col_idx)

return wilcoxon_df, values_df_multiindex ```
Example 65
 Project: diffxpy   Author: theislab   File: stats.py    BSD 3-Clause "New" or "Revised" License 5 votes
```def t_test_raw(
x0,
x1,
):
"""
Perform two-sided t-test allowing for unequal group variances (Welch's t-test) on raw data
along second axis (for each gene).

The t-test assumes normally distributed data. This function computes
the necessary statistics and calls t_test_moments().

:param x0: np.array (observations x genes)
Observations in first group by gene
:param x1:  np.array (observations x genes)
Observations in second group by gene.
"""
axis = 1
if x0.shape[1] != x1.shape[1]:
raise ValueError('stats.t_test_raw(): x0 and x1 have to contain the same number of genes')
# Reshape into 2D array if only one test is performed.
if np.ndim(x0) == 1:
x0 = x0.reshape([x0.shape[0], 1])
x1 = x1.reshape([x1.shape[0], 1])
if np.any(x0.shape[axis] != x1.shape[axis]):
raise ValueError(
'stats.wilcoxon(): the first axis (number of tests) is not allowed to differ between x0 and x1!')

mu0 = np.asarray(np.mean(x0, axis=0)).flatten()
var0 = np.asarray(np.var(x0, axis=0)).flatten()
mu1 = np.asarray(np.mean(x1, axis=0)).flatten()
var1 = np.asarray(np.var(x1, axis=0)).flatten()
n0 = x0.shape[0]
n1 = x1.shape[0]

pval = t_test_moments(mu0=mu0, mu1=mu1, var0=var0, var1=var1, n0=n0, n1=n1)
return pval ```
Example 66
 Project: pimkl   Author: PhosphorylatedRabbits   File: analysis.py    MIT License 5 votes
```def significant_pathways(df, alpha=1e-3):
"""significance test vs the average weight"""
avg = 1. / df.shape[1]
ordering = df.columns
wilcoxon_pvalues = pd.Series(
{
ws: wilcoxon(df[ws] - avg)[1] if df[ws].median() > avg else 1.
for ws in df
}
)
wilcoxon_pvalues = wilcoxon_pvalues[ordering]
# Multiple Testing Correction
reject_H0, pvals_corrected = fdrcorrection(wilcoxon_pvalues, alpha=alpha)
return pd.Series(reject_H0, index=ordering) ```
Example 67
 Project: DataComp   Author: Cojabi   File: stats.py    Apache License 2.0 4 votes
```def test_num_feats(zipper, feat_subset=None, method=None):
"""
Performs a hypothesis test to check if the value distributions of numerical features deviate signifcantly between
the datasets. Currently t-test as a parametric and U-test as a non-parametric test are supported.

:param zipper: Dictionary storing the feature values of the datasets in a list. Feature name is used as the key.
:param feat_subset: A list containing feature names. If given, analysis will only be performed for the contained \
features. If not given all features will be considered.
:param method: Specify which statistical test should be used. "u" for Mann-Whitney-U-test, "t" for t-test and \
"wilcoxon" for a Wilcoxon signed rank test.
:return: dictionary storing the p_values of the analysis. Feature names are used as keys.
"""

# if no method is specified used Mann-Whitney-U-test as standard
if method is None:
method = "u"

# initialize dictionary which stores the p_values
p_values = dict()

if feat_subset is None:
feat_subset = zipper.keys()

for feat in feat_subset:  # run through all variables

# initiate dict in dict for d1 vs d2, d2 vs d3 etc. per feature
p_values[feat] = dict()

for i in range(len(zipper[feat]) - 1):  # select dataset1
for j in range(i + 1, len(zipper[feat])):  # select dataset2

# handle the case that all values of current feature are equal across current datasets
if _test_if_all_vals_equal(zipper[feat][i], zipper[feat][j]):
warnings.warn(
"Values of \"{}\" are the identical across the two datasets. It will be skipped.".format(feat),
UserWarning)
# delete already created dict for i, j in p_values and continue with next feature
del p_values[feat]
continue

# only calculate score if there are values in each dataset
if zipper[feat][i] and zipper[feat][j]:
# calculate u-test and return p-value
if method == "u":
stat_test_result = mannwhitneyu(zipper[feat][i], zipper[feat][j], alternative="two-sided")
# calculate t-test and return p-value
elif method == "t":
stat_test_result = ttest_ind(zipper[feat][i], zipper[feat][j])
elif method == "wilcoxon":
stat_test_result = wilcoxon(zipper[feat][i], zipper[feat][j])

p_values[feat][i + 1, j + 1] = stat_test_result.pvalue

# if one or both sets are empty
else:
p_values[feat][i + 1, j + 1] = np.nan

return p_values ```
Example 68
 Project: DIVE-backend   Author: MacroConnections   File: numerical_comparison.py    GNU General Public License v3.0 4 votes
```def get_valid_tests(equal_var, independent, normal, num_samples):
'''
Get valid tests given number of samples and statistical characterization of
samples:

Equal variance
Indepenence
Normality
'''
if num_samples == 1:
valid_tests = {
'chisquare': stats.chisquare,
'power_divergence': stats.power_divergence,
'kstest': stats.kstest
}
if normal:
valid_tests['input']['one_sample_ttest'] = stats.ttest_1samp

elif num_samples == 2:
if independent:
valid_tests = {
'mannwhitneyu': stats.mannwhitneyu,
'kruskal': stats.kruskal,
'ks_2samp': stats.ks_2samp
}
if normal:
valid_tests['two_sample_ttest'] = stats.ttest_ind
if equal_var:
valid_tests['f_oneway'] = stats.f_oneway
else:
valid_tests = {
'two_sample_ks': stats.ks_2samp,
'wilcoxon': stats.wilcoxon
}
if normal:
valid_tests['two_sample_related_ttest'] = stats.ttest_rel

elif num_samples >= 3:
if independent:
valid_tests = {
'kruskal': stats.kruskal
}
if normal and equal_var:
valid_tests['f_oneway'] = stats.f_oneway

else:
valid_tests['friedmanchisquare'] = stats.friedmanchisquare

return valid_tests ```
Example 69
 Project: DrVAE   Author: rampasek   File: compare_pooled_results.py    GNU General Public License v3.0 4 votes
```def compute_pairwise_pvals(rlist, measures, tasks, models):
res = dict()
num = len(rlist)
for drug in rlist[0].keys():
if not np.all(np.array([drug in rl.keys() for rl in rlist])):
warnings.warn('Warning! ignoring ' + drug + ' as it is not in all input files')
continue

dv = dict()
for ref_model in models:
for key in rlist[0][drug].keys():
# ignore entries that are not performance stats
if '|' not in key: continue
if '->Y' not in key: continue

# compute statistical test between this classification result and our DGM
measure = key.split('|')[1]
if measure not in measures: continue
ref_key = ref_task + '|' + measure + '|' + ref_model
if ref_key not in rlist[0][drug].keys():
# print("skipping non existent reference " + ref_key)
continue
if ref_key == key:  # don't compare to self
continue

vals = list()
ref_vals = list()
# get list of results
for rl in rlist:
try:
vals.append(rl[drug][key][0] if isinstance(rl[drug][key], list) else rl[drug][key])
ref_vals.append(rl[drug][ref_key][0] if isinstance(rl[drug][ref_key], list) else rl[drug][ref_key])
except:
warnings.warn('Warning! missing entry for ' + drug + ' ' + key)
pass

vals = np.asarray(vals)

ref_vals = np.asarray(ref_vals)
## scipy implementation of *two-sided* Wilcoxon test
# dv[key] = stats.wilcoxon(ref_vals, vals)[1]
## call R implementation of *one-sided* Wilcoxon test
# dv[key] = wilcox_test_R(vals, ref_vals, alternative="less")
## calling R is too slow, run my reimplemented Wilcoxon test
# print(ref_key+';'+key, len(vals), len(ref_vals))
dv[ref_key+';'+key] = my_wilcoxon_test(vals, ref_vals, alternative="less")

res[drug] = dv
return res ```
Example 70
 Project: DrVAE   Author: rampasek   File: pool_results.py    GNU General Public License v3.0 4 votes
```def compute_pairwise_pvals(rlist, tasks, models):
res = dict()
num = len(rlist)
for drug in rlist[0].keys():
if not np.all(np.array([drug in rl.keys() for rl in rlist])):
warnings.warn('Warning! ignoring ' + drug + ' as it is not in all input files')
continue

dv = dict()
for ref_model in models:
for key in rlist[0][drug].keys():
# ignore entries that are not performance stats
if '|' not in key: continue
if '->Y' not in key: continue

# compute statistical test between this classification result and our DGM
measure = key.split('|')[1]
ref_key = ref_task + '|' + measure + '|' + ref_model
if ref_key not in rlist[0][drug].keys():
# print("skipping non existent reference " + ref_key)
continue
if ref_key == key:  # don't compare to self
continue

vals = list()
ref_vals = list()
# get list of results
for rl in rlist:
try:
vals.append(rl[drug][key][0] if isinstance(rl[drug][key], list) else rl[drug][key])
ref_vals.append(rl[drug][ref_key][0] if isinstance(rl[drug][ref_key], list) else rl[drug][ref_key])
except:
warnings.warn('Warning! missing entry for ' + drug + ' ' + key)
pass

vals = np.asarray(vals)

ref_vals = np.asarray(ref_vals)
## scipy implementation of *two-sided* Wilcoxon test
# dv[key] = stats.wilcoxon(ref_vals, vals)[1]
## call R implementation of *one-sided* Wilcoxon test
# dv[key] = wilcox_test_R(vals, ref_vals, alternative="less")
## calling R is too slow, run my reimplemented Wilcoxon test
# print(ref_key+';'+key, len(vals), len(ref_vals))
dv[ref_key+';'+key] = my_wilcoxon_test(vals, ref_vals, alternative="less")

res[drug] = dv
return res ```
Example 71
 Project: DrVAE   Author: rampasek   File: pool_results.py    GNU General Public License v3.0 4 votes
```def compute_pairwise_pvals(rlist, tasks, models):
res = dict()
num = len(rlist)
for drug in rlist[0].keys():
if not np.all(np.array([drug in rl.keys() for rl in rlist])):
warnings.warn('Warning! ignoring ' + drug + ' as it is not in all input files')
continue

dv = dict()
for ref_model in models:
for key in rlist[0][drug].keys():
# ignore entries that are not performance stats
if '|' not in key: continue
if '->Y' not in key: continue

# compute statistical test between this classification result and our DGM
measure = key.split('|')[1]
ref_key = ref_task + '|' + measure + '|' + ref_model
if ref_key not in rlist[0][drug].keys():
# print("skipping non existent reference " + ref_key)
continue
if ref_key == key:  # don't compare to self
continue

vals = list()
ref_vals = list()
# get list of results
for rl in rlist:
try:
vals.append(rl[drug][key][0] if isinstance(rl[drug][key], list) else rl[drug][key])
ref_vals.append(rl[drug][ref_key][0] if isinstance(rl[drug][ref_key], list) else rl[drug][ref_key])
except:
warnings.warn('Warning! missing entry for ' + drug + ' ' + key)
pass

vals = np.asarray(vals)

ref_vals = np.asarray(ref_vals)
## scipy implementation of *two-sided* Wilcoxon test
# dv[key] = stats.wilcoxon(ref_vals, vals)[1]
## call R implementation of *one-sided* Wilcoxon test
# dv[key] = wilcox_test_R(vals, ref_vals, alternative="less")
## calling R is too slow, run my reimplemented Wilcoxon test
# print(ref_key+';'+key, len(vals), len(ref_vals))
dv[ref_key+';'+key] = my_wilcoxon_test(vals, ref_vals, alternative="less")

res[drug] = dv
return res ```
Example 72
 Project: brainpipe   Author: EtienneCmb   File: basics_backup.py    GNU General Public License v3.0 4 votes
```def _evalstat(x, bsl, meth, n_perm, metric, maxstat, tail):
"""Statistical evaluation of features

[x] = [xn] = (nFce, npts, nTrials)
[bsl] = (nFce, nTrials)
"""
# Get shape of xF :
nf, npts, nt = x.shape
pvalues = np.ones((nf, npts))

# Permutations :
if meth == 'permutation':
perm = perm_swaparray(a, b, n_perm=200, axis=-1, rndstate=0)
from brainpipe.xPOO.stats import permutation
# Pre-define permutations :
pObj = permutation(n_perm)
perm = np.zeros((n_perm, nf, npts))
# For each permutation :
for p in range(n_perm):
# Get 1D iterations :
ite = product(range(nf), range(npts))
permT = np.random.permutation(2*nt)
for f, pts in ite:
bs, xs = bsl[f, :], x[f, pts, :]
# Reshape data :
subX = np.vstack((bsl[f, :], x[f, pts, :])).reshape(2*nt,)
# Shuffle data :
subX = subX[permT].reshape(nt, 2)
# Normalize data :
subX = normalize(subX[:, 0], subX[:, 1], norm=norm)
# Get mean of data :
perm[p, f, pts] = np.mean(subX)
# Get final pvalues :
pvalues = pObj.perm2p(np.mean(xn, 2), perm, tail=tail,
maxstat=maxstat)

# Wilcoxon test :
elif meth == 'wilcoxon':
from scipy.stats import wilcoxon
# Get iterations :
ite = product(range(nf), range(npts))
# Compute wilcoxon :
for k, i in ite:
_, pvalues[k, i] = wilcoxon(x[k, i, :], bsl[k, :])

# Kruskal-Wallis :
elif meth == 'kruskal':
from scipy.stats import kruskal
# Get iterations :
ite = product(range(nf), range(npts))
# Compute Kruskal-Wallis :
for k, i in ite:
_, pvalues[k, i] = kruskal(x[k, i, :], bsl[k, :])

return pvalues ```
Example 73
 Project: TranskribusDU   Author: Transkribus   File: TestReport.py    BSD 3-Clause "New" or "Revised" License 4 votes
```def compareReport(cls,r1,r2,bDisplay=False):
"""
compare two reports using
scipy.stats.wilcoxon : Calculate the Wilcoxon signed-rank test.

"""
from  scipy.stats import wilcoxon
from scipy.stats import  mannwhitneyu

lConfMat1 = r1.getConfusionMatrixByDocument()
nbClasses = len(lConfMat1[0])
print ('nb classes: %d'%nbClasses)
eps=1e-8
lP1=np.ndarray((len(lConfMat1),nbClasses),dtype=float)
lR1=np.ndarray((len(lConfMat1),nbClasses),dtype=float)
lF1=np.ndarray((len(lConfMat1),nbClasses),dtype=float)
for i,conf in enumerate(lConfMat1):
lP1[i]=np.diag(conf)/(eps+conf.sum(axis=0))
lR1[i]=np.diag(conf)/(eps+conf.sum(axis=1))
lF1[i]= 2*lP1[-1]*lR1[-1]/(eps+lP1[-1]+lR1[-1])

lConfMat2 = r2.getConfusionMatrixByDocument()
lP2=np.ndarray((len(lConfMat2),nbClasses),dtype=float)
lR2=np.ndarray((len(lConfMat2),nbClasses),dtype=float)
lF2=np.ndarray((len(lConfMat2),nbClasses),dtype=float)
for i,conf2 in enumerate(lConfMat2):
lP2[i]=np.diag(conf2)/(eps+conf2.sum(axis=0))
lR2[i]=np.diag(conf2)/(eps+conf2.sum(axis=1))
lF2[i]= 2*lP2[-1]*lR2[-1]/(eps+lP2[-1]+lR2[-1])

if bDisplay:
for cl in range(nbClasses):
print ('class %s'%cl)
r1 = lP1[:,cl]
r2 = lP2[:,cl]
print ('\tPrecision:')
print('\t',wilcoxon(r1,r2, zero_method="zsplit"))

r1 = lR1[:,cl]
r2 = lR2[:,cl]
print ('\tRecall:')
print('\t',wilcoxon(r1,r2, zero_method="zsplit"))
r1 = lF1[:,cl]
r2 = lF2[:,cl]
print ('\tF1:')
print('\t',wilcoxon(r1,r2, zero_method="zsplit")) ```