Spaces:
Sleeping
Sleeping
Zekun Wu
commited on
Commit
•
6e7dc3c
1
Parent(s):
f921051
update
Browse files- util/evaluation.py +29 -24
util/evaluation.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import pandas as pd
|
2 |
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
|
@@ -48,29 +49,29 @@ from scipy.stats import ttest_1samp
|
|
48 |
# p_value = np.sum(np.abs(t_stats) >= np.abs(observed_t_stat)) / num_bootstrap
|
49 |
# return observed_t_stat, p_value
|
50 |
|
51 |
-
def posthoc_friedman(data, variables, rank_suffix='_Rank'):
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
|
75 |
def statistical_tests(data):
|
76 |
"""Perform various statistical tests to evaluate potential biases."""
|
@@ -114,7 +115,11 @@ def statistical_tests(data):
|
|
114 |
|
115 |
# Friedman test
|
116 |
friedman_stat, friedman_p = friedmanchisquare(*rank_data)
|
117 |
-
|
|
|
|
|
|
|
|
|
118 |
|
119 |
results = {
|
120 |
"Average Ranks": average_ranks.to_dict(),
|
|
|
1 |
import pandas as pd
|
2 |
import numpy as np
|
3 |
+
from scikit_posthocs import posthoc_nemenyi
|
4 |
from scipy import stats
|
5 |
from scipy.stats import friedmanchisquare, kruskal, mannwhitneyu, wilcoxon, levene, ttest_ind, f_oneway
|
6 |
from statsmodels.stats.multicomp import MultiComparison
|
|
|
49 |
# p_value = np.sum(np.abs(t_stats) >= np.abs(observed_t_stat)) / num_bootstrap
|
50 |
# return observed_t_stat, p_value
|
51 |
|
52 |
+
# def posthoc_friedman(data, variables, rank_suffix='_Rank'):
|
53 |
+
# """Perform a post-hoc analysis for the Friedman test using pairwise comparisons."""
|
54 |
+
# ranked_data = data[[v + rank_suffix for v in variables]].to_numpy()
|
55 |
+
# num_subjects = ranked_data.shape[0]
|
56 |
+
# num_conditions = ranked_data.shape[1]
|
57 |
+
# comparisons = []
|
58 |
+
#
|
59 |
+
# for i in range(num_conditions):
|
60 |
+
# for j in range(i + 1, num_conditions):
|
61 |
+
# diff = ranked_data[:, i] - ranked_data[:, j]
|
62 |
+
# abs_diff = np.abs(diff)
|
63 |
+
# avg_diff = np.mean(diff)
|
64 |
+
# se_diff = np.std(diff, ddof=1) / np.sqrt(num_subjects)
|
65 |
+
# z_value = avg_diff / se_diff
|
66 |
+
# p_value = 2 * (1 - stats.norm.cdf(np.abs(z_value)))
|
67 |
+
# comparisons.append({
|
68 |
+
# "Group1": variables[i],
|
69 |
+
# "Group2": variables[j],
|
70 |
+
# "Z": z_value,
|
71 |
+
# "p-value": p_value
|
72 |
+
# })
|
73 |
+
#
|
74 |
+
# return comparisons
|
75 |
|
76 |
def statistical_tests(data):
|
77 |
"""Perform various statistical tests to evaluate potential biases."""
|
|
|
115 |
|
116 |
# Friedman test
|
117 |
friedman_stat, friedman_p = friedmanchisquare(*rank_data)
|
118 |
+
|
119 |
+
rank_matrix = data[rank_columns].values
|
120 |
+
rank_matrix_transposed = np.transpose(rank_matrix)
|
121 |
+
posthoc_results = posthoc_nemenyi(rank_matrix_transposed)
|
122 |
+
#posthoc_results = posthoc_friedman(data, variables, rank_suffix)
|
123 |
|
124 |
results = {
|
125 |
"Average Ranks": average_ranks.to_dict(),
|