forked from glnmario/cwr4lsc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmantel.py
32 lines (24 loc) · 776 Bytes
/
mantel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pickle
from skbio.stats.distance import mantel
import numpy as np
with open('data/GradedMeaningAnnotation/usim_matrices.dict', 'rb') as f:
sim_matrices = pickle.load(f)
with open('data/GradedMeaningAnnotation/bert_base_matrices_sum.dict', 'rb') as f:
bert_sim_matrices = pickle.load(f)
coeffs = []
sig_coeffs = []
for w in sim_matrices:
coeff, p_value, n = mantel(
sim_matrices[w],
bert_sim_matrices[w],
method='spearman', # pearson
permutations=999,
alternative='two-sided' # greater, less
)
print(w)
print('spearman: {:.2f} p: {:.2f}'.format(coeff, p_value))
coeffs.append(coeff)
if p_value < 0.05:
sig_coeffs.append(coeff)
print(np.mean(coeffs))
print(np.mean(sig_coeffs))