Zekun Wu commited on
Commit
015b1a2
1 Parent(s): f335959
Files changed (1) hide show
  1. util/evaluation.py +23 -9
util/evaluation.py CHANGED
@@ -3,23 +3,37 @@ import numpy as np
3
  from scipy import stats
4
  from scipy.stats import friedmanchisquare, kruskal, mannwhitneyu, wilcoxon, levene, ttest_ind, f_oneway
5
  from statsmodels.stats.multicomp import MultiComparison
6
-
7
  from scipy.stats import spearmanr, pearsonr, kendalltau, entropy
8
  from scipy.spatial.distance import jensenshannon
9
- from scipy.stats import ttest_ind, friedmanchisquare, rankdata
10
  from statsmodels.stats.multicomp import pairwise_tukeyhsd
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def bootstrap_t_test(data1, data2, num_bootstrap=1000):
13
- """Perform a bootstrapped t-test."""
14
- observed_t_stat, _ = ttest_ind(data1, data2)
15
- combined = np.concatenate([data1, data2])
16
  t_stats = []
17
 
18
  for _ in range(num_bootstrap):
19
- np.random.shuffle(combined)
20
- new_data1 = combined[:len(data1)]
21
- new_data2 = combined[len(data1):]
22
- t_stat, _ = ttest_ind(new_data1, new_data2)
23
  t_stats.append(t_stat)
24
 
25
  p_value = np.sum(np.abs(t_stats) >= np.abs(observed_t_stat)) / num_bootstrap
 
3
  from scipy import stats
4
  from scipy.stats import friedmanchisquare, kruskal, mannwhitneyu, wilcoxon, levene, ttest_ind, f_oneway
5
  from statsmodels.stats.multicomp import MultiComparison
 
6
  from scipy.stats import spearmanr, pearsonr, kendalltau, entropy
7
  from scipy.spatial.distance import jensenshannon
8
+ from scipy.stats import ttest_ind, friedmanchisquare, rankdata, ttest_rel
9
  from statsmodels.stats.multicomp import pairwise_tukeyhsd
10
 
11
+ # def bootstrap_t_test(data1, data2, num_bootstrap=1000):
12
+ # """Perform a bootstrapped t-test."""
13
+ # observed_t_stat, _ = ttest_ind(data1, data2)
14
+ # combined = np.concatenate([data1, data2])
15
+ # t_stats = []
16
+ #
17
+ # for _ in range(num_bootstrap):
18
+ # np.random.shuffle(combined)
19
+ # new_data1 = combined[:len(data1)]
20
+ # new_data2 = combined[len(data1):]
21
+ # t_stat, _ = ttest_ind(new_data1, new_data2)
22
+ # t_stats.append(t_stat)
23
+ #
24
+ # p_value = np.sum(np.abs(t_stats) >= np.abs(observed_t_stat)) / num_bootstrap
25
+ # return observed_t_stat, p_value
26
+
27
  def bootstrap_t_test(data1, data2, num_bootstrap=1000):
28
+ """Perform a bootstrapped paired t-test."""
29
+ observed_t_stat, _ = ttest_rel(data1, data2)
30
+ differences = data1 - data2
31
  t_stats = []
32
 
33
  for _ in range(num_bootstrap):
34
+ # Resample with replacement
35
+ resampled_diffs = np.random.choice(differences, size=len(differences), replace=True)
36
+ t_stat, _ = ttest_rel(resampled_diffs, np.zeros(len(resampled_diffs)))
 
37
  t_stats.append(t_stat)
38
 
39
  p_value = np.sum(np.abs(t_stats) >= np.abs(observed_t_stat)) / num_bootstrap