ABalytics 2.1.2__tar.gz → 3.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {abalytics-2.1.2 → abalytics-3.0.2}/PKG-INFO +3 -2
- {abalytics-2.1.2 → abalytics-3.0.2}/README.md +1 -1
- {abalytics-2.1.2 → abalytics-3.0.2}/abalytics/analysis.py +23 -21
- {abalytics-2.1.2 → abalytics-3.0.2}/abalytics/significance_tests.py +70 -45
- abalytics-3.0.2/abalytics/utils.py +88 -0
- {abalytics-2.1.2 → abalytics-3.0.2}/abalytics.egg-info/PKG-INFO +3 -2
- {abalytics-2.1.2 → abalytics-3.0.2}/abalytics.egg-info/requires.txt +1 -0
- {abalytics-2.1.2 → abalytics-3.0.2}/setup.py +3 -2
- abalytics-2.1.2/abalytics/utils.py +0 -125
- {abalytics-2.1.2 → abalytics-3.0.2}/LICENSE +0 -0
- {abalytics-2.1.2 → abalytics-3.0.2}/abalytics/__init__.py +0 -0
- {abalytics-2.1.2 → abalytics-3.0.2}/abalytics.egg-info/SOURCES.txt +0 -0
- {abalytics-2.1.2 → abalytics-3.0.2}/abalytics.egg-info/dependency_links.txt +0 -0
- {abalytics-2.1.2 → abalytics-3.0.2}/abalytics.egg-info/top_level.txt +0 -0
- {abalytics-2.1.2 → abalytics-3.0.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: abalytics
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.2
|
|
4
4
|
Summary: Advanced A/B Testing Statistical Analytics
|
|
5
5
|
Author: Janis Berneker
|
|
6
6
|
License: LICENSE
|
|
@@ -13,6 +13,7 @@ Requires-Dist: scipy>=1.10.1
|
|
|
13
13
|
Requires-Dist: statsmodels>=0.14.1
|
|
14
14
|
Requires-Dist: scikit-posthocs>=0.8.1
|
|
15
15
|
Requires-Dist: pingouin>=0.5.4
|
|
16
|
+
Requires-Dist: tabulate>=0.9.0
|
|
16
17
|
|
|
17
18
|
# ABalytics: Advanced A/B Testing Statistical Analytics
|
|
18
19
|
|
|
@@ -120,7 +121,7 @@ analysis_results = analyze_independent_groups(
|
|
|
120
121
|
# Generate pretty text output
|
|
121
122
|
pretty_text = format_results_as_table(
|
|
122
123
|
abalytics_results=[analysis_results],
|
|
123
|
-
identifiers_list=[
|
|
124
|
+
identifiers_list=[{"Test name": "A/B Test 1", "Channel": "Mobile"}],
|
|
124
125
|
)
|
|
125
126
|
print(pretty_text)
|
|
126
127
|
```
|
|
@@ -104,7 +104,7 @@ analysis_results = analyze_independent_groups(
|
|
|
104
104
|
# Generate pretty text output
|
|
105
105
|
pretty_text = format_results_as_table(
|
|
106
106
|
abalytics_results=[analysis_results],
|
|
107
|
-
identifiers_list=[
|
|
107
|
+
identifiers_list=[{"Test name": "A/B Test 1", "Channel": "Mobile"}],
|
|
108
108
|
)
|
|
109
109
|
print(pretty_text)
|
|
110
110
|
```
|
|
@@ -12,7 +12,7 @@ from .significance_tests import (
|
|
|
12
12
|
get_chi_square_posthoc_results,
|
|
13
13
|
get_welch_anova_significance,
|
|
14
14
|
get_oneway_anova_significance,
|
|
15
|
-
|
|
15
|
+
get_kruskal_wallis_significance,
|
|
16
16
|
get_games_howell_posthoc_results,
|
|
17
17
|
get_tukeyhsd_posthoc_results,
|
|
18
18
|
get_dunn_posthoc_results,
|
|
@@ -34,6 +34,10 @@ class AnalysisResults(BaseModel):
|
|
|
34
34
|
default=None,
|
|
35
35
|
description="Additional information or notes regarding the analysis.",
|
|
36
36
|
)
|
|
37
|
+
a_priori_test: Optional[str] = Field(
|
|
38
|
+
default=None,
|
|
39
|
+
description="The name of the statistical test used in the analysis.",
|
|
40
|
+
)
|
|
37
41
|
sample_size: Optional[int] = Field(
|
|
38
42
|
default=None, description="The sample size used in the analysis."
|
|
39
43
|
)
|
|
@@ -72,6 +76,7 @@ def analyze_independent_groups(
|
|
|
72
76
|
AnalysisResults: An instance of the AnalysisResults class containing the following attributes:
|
|
73
77
|
- significant_results: A list of results of the statistical significance tests.
|
|
74
78
|
- info: A string containing information about the data if no results were found.
|
|
79
|
+
- a_priori_test: The name of the statistical test used in the analysis.
|
|
75
80
|
- sample_size: The sample size of the data.
|
|
76
81
|
- dichotomous_flag: A boolean flag indicating if the data is dichotomous (e.g. boolean).
|
|
77
82
|
- levene_flag: A boolean flag indicating if Levene's test for homogeneity of variances is significant.
|
|
@@ -92,9 +97,10 @@ def analyze_independent_groups(
|
|
|
92
97
|
sample_size = len(df)
|
|
93
98
|
pvalue = None
|
|
94
99
|
info = None
|
|
100
|
+
a_priori_test = None
|
|
95
101
|
dichotomous_flag = False
|
|
96
|
-
levene_flag =
|
|
97
|
-
gaussian_flag =
|
|
102
|
+
levene_flag = None
|
|
103
|
+
gaussian_flag = None
|
|
98
104
|
# Check if any group has less than the minimum sample size
|
|
99
105
|
if (
|
|
100
106
|
df.groupby(group_column)[variable_to_analyze]
|
|
@@ -105,9 +111,8 @@ def analyze_independent_groups(
|
|
|
105
111
|
# Check if the variable is dichotomous (e.g. boolean)
|
|
106
112
|
elif dichotomous_flag := is_dichotomous(df, variable_to_analyze):
|
|
107
113
|
# Perform chi-square test
|
|
108
|
-
pvalue = get_chi_square_significance(
|
|
109
|
-
|
|
110
|
-
)
|
|
114
|
+
pvalue = get_chi_square_significance(df, group_column, variable_to_analyze)
|
|
115
|
+
a_priori_test = f"Chi-square, p-value = {pvalue:.3f}"
|
|
111
116
|
if pvalue < p_value_threshold:
|
|
112
117
|
results = get_chi_square_posthoc_results(
|
|
113
118
|
df, group_column, variable_to_analyze, p_value_threshold
|
|
@@ -117,9 +122,8 @@ def analyze_independent_groups(
|
|
|
117
122
|
if levene_flag := is_levene_significant(
|
|
118
123
|
df, group_column, variable_to_analyze, p_value_threshold
|
|
119
124
|
):
|
|
120
|
-
pvalue = get_welch_anova_significance(
|
|
121
|
-
|
|
122
|
-
)
|
|
125
|
+
pvalue = get_welch_anova_significance(df, group_column, variable_to_analyze)
|
|
126
|
+
a_priori_test = f"Welch's ANOVA, p-value = {pvalue:.3f}"
|
|
123
127
|
if pvalue < p_value_threshold:
|
|
124
128
|
results = get_games_howell_posthoc_results(
|
|
125
129
|
df, group_column, variable_to_analyze, p_value_threshold
|
|
@@ -131,14 +135,16 @@ def analyze_independent_groups(
|
|
|
131
135
|
pvalue = get_oneway_anova_significance(
|
|
132
136
|
df, group_column, variable_to_analyze
|
|
133
137
|
)
|
|
138
|
+
a_priori_test = f"One-way ANOVA, p-value = {pvalue:.3f}"
|
|
134
139
|
if pvalue < p_value_threshold:
|
|
135
140
|
results = get_tukeyhsd_posthoc_results(
|
|
136
141
|
df, group_column, variable_to_analyze, p_value_threshold
|
|
137
142
|
)
|
|
138
143
|
else:
|
|
139
|
-
pvalue =
|
|
144
|
+
pvalue = get_kruskal_wallis_significance(
|
|
140
145
|
df, group_column, variable_to_analyze
|
|
141
146
|
)
|
|
147
|
+
a_priori_test = f"Kruskal-Wallis, p-value = {pvalue:.3f}"
|
|
142
148
|
if pvalue < p_value_threshold:
|
|
143
149
|
results = get_dunn_posthoc_results(
|
|
144
150
|
df, group_column, variable_to_analyze, p_value_threshold
|
|
@@ -150,7 +156,7 @@ def analyze_independent_groups(
|
|
|
150
156
|
# If no results were found, return a message
|
|
151
157
|
if not "results" in locals() or len(results.significant_results) == 0:
|
|
152
158
|
if pvalue is not None:
|
|
153
|
-
info = f"
|
|
159
|
+
info = f"n.s. (p={pvalue:.3f})"
|
|
154
160
|
# If results were found, return them
|
|
155
161
|
if "results" in locals():
|
|
156
162
|
significant_results = results.significant_results
|
|
@@ -160,6 +166,7 @@ def analyze_independent_groups(
|
|
|
160
166
|
return AnalysisResults(
|
|
161
167
|
significant_results=significant_results,
|
|
162
168
|
info=info,
|
|
169
|
+
a_priori_test=a_priori_test,
|
|
163
170
|
sample_size=sample_size,
|
|
164
171
|
dichotomous_flag=dichotomous_flag,
|
|
165
172
|
levene_flag=levene_flag,
|
|
@@ -197,9 +204,7 @@ def analyze_dependent_groups(
|
|
|
197
204
|
)
|
|
198
205
|
|
|
199
206
|
missing_columns = [
|
|
200
|
-
variable
|
|
201
|
-
for variable in variables_to_compare
|
|
202
|
-
if variable not in df.columns
|
|
207
|
+
variable for variable in variables_to_compare if variable not in df.columns
|
|
203
208
|
]
|
|
204
209
|
if missing_columns:
|
|
205
210
|
print(f"Columns not found in DataFrame: {', '.join(missing_columns)}")
|
|
@@ -215,10 +220,7 @@ def analyze_dependent_groups(
|
|
|
215
220
|
results = None
|
|
216
221
|
|
|
217
222
|
# Check if any variable has less than the minimum sample size
|
|
218
|
-
if any(
|
|
219
|
-
df[variable].count() < min_sample_size
|
|
220
|
-
for variable in variables_to_compare
|
|
221
|
-
):
|
|
223
|
+
if any(df[variable].count() < min_sample_size for variable in variables_to_compare):
|
|
222
224
|
info = "not enough data"
|
|
223
225
|
# Check if the variables are dichotomous (e.g. boolean)
|
|
224
226
|
elif all(is_dichotomous(df, variable) for variable in variables_to_compare):
|
|
@@ -233,10 +235,9 @@ def analyze_dependent_groups(
|
|
|
233
235
|
is_gaussian(df, variable, p_value_threshold)
|
|
234
236
|
for variable in variables_to_compare
|
|
235
237
|
):
|
|
236
|
-
pvalue = get_repeated_measures_anova_significance(
|
|
237
|
-
df, variables_to_compare
|
|
238
|
-
)
|
|
238
|
+
pvalue = get_repeated_measures_anova_significance(df, variables_to_compare)
|
|
239
239
|
if pvalue < p_value_threshold:
|
|
240
|
+
info = f"A priori test: Repeated measures ANOVA, p-value = {pvalue:.3f}"
|
|
240
241
|
results = get_repeated_measures_anova_posthoc_results(
|
|
241
242
|
df, variables_to_compare, p_value_threshold
|
|
242
243
|
)
|
|
@@ -247,6 +248,7 @@ def analyze_dependent_groups(
|
|
|
247
248
|
else:
|
|
248
249
|
pvalue = get_friedman_significance(df, variables_to_compare)
|
|
249
250
|
if pvalue < p_value_threshold:
|
|
251
|
+
info = f"A priori test: Friedman, p-value = {pvalue:.3f}"
|
|
250
252
|
results = get_nemenyi_results(
|
|
251
253
|
df, variables_to_compare, p_value_threshold
|
|
252
254
|
)
|
|
@@ -34,6 +34,7 @@ class GroupResult(BaseModel):
|
|
|
34
34
|
class PosthocResult(BaseModel):
|
|
35
35
|
"""Represents a single posthoc test result."""
|
|
36
36
|
|
|
37
|
+
analysis_method: str
|
|
37
38
|
result_pretty_text: str
|
|
38
39
|
p_value: float
|
|
39
40
|
groups: List[GroupResult]
|
|
@@ -45,10 +46,15 @@ class PosthocResults(BaseModel):
|
|
|
45
46
|
significant_results: List[PosthocResult] = []
|
|
46
47
|
|
|
47
48
|
def add_result(
|
|
48
|
-
self,
|
|
49
|
+
self,
|
|
50
|
+
analysis_method: str,
|
|
51
|
+
result_pretty_text: str,
|
|
52
|
+
p_value: float,
|
|
53
|
+
groups_info: List[dict],
|
|
49
54
|
):
|
|
50
55
|
groups = [GroupResult(**group) for group in groups_info]
|
|
51
56
|
result = PosthocResult(
|
|
57
|
+
analysis_method=analysis_method,
|
|
52
58
|
result_pretty_text=result_pretty_text,
|
|
53
59
|
p_value=p_value,
|
|
54
60
|
groups=groups,
|
|
@@ -126,8 +132,10 @@ def get_chi_square_posthoc_results(
|
|
|
126
132
|
key=lambda x: x["mean"],
|
|
127
133
|
reverse=True,
|
|
128
134
|
)
|
|
129
|
-
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.1f}%) > {groups_info[1]['name']} ({groups_info[1]['mean']:.1f}%)
|
|
130
|
-
posthoc_results.add_result(
|
|
135
|
+
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.1f}%) > {groups_info[1]['name']} ({groups_info[1]['mean']:.1f}%)"
|
|
136
|
+
posthoc_results.add_result(
|
|
137
|
+
"Chi-square", result_pretty_text, p_value, groups_info
|
|
138
|
+
)
|
|
131
139
|
|
|
132
140
|
# Apply Bonferroni correction if there are any p-values to correct
|
|
133
141
|
if p_values:
|
|
@@ -234,8 +242,10 @@ def get_games_howell_posthoc_results(
|
|
|
234
242
|
key=lambda x: x["mean"],
|
|
235
243
|
reverse=True,
|
|
236
244
|
)
|
|
237
|
-
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})
|
|
238
|
-
posthoc_results.add_result(
|
|
245
|
+
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})"
|
|
246
|
+
posthoc_results.add_result(
|
|
247
|
+
"Games-Howell", result_pretty_text, row["pval"], groups_info
|
|
248
|
+
)
|
|
239
249
|
|
|
240
250
|
return posthoc_results
|
|
241
251
|
|
|
@@ -261,7 +271,7 @@ def get_oneway_anova_significance(
|
|
|
261
271
|
return p_value
|
|
262
272
|
|
|
263
273
|
|
|
264
|
-
def
|
|
274
|
+
def get_kruskal_wallis_significance(
|
|
265
275
|
df: pd.DataFrame, group_column: str, variable: str
|
|
266
276
|
) -> float:
|
|
267
277
|
"""
|
|
@@ -328,8 +338,10 @@ def get_tukeyhsd_posthoc_results(
|
|
|
328
338
|
key=lambda x: x["mean"],
|
|
329
339
|
reverse=True,
|
|
330
340
|
)
|
|
331
|
-
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})
|
|
332
|
-
posthoc_results.add_result(
|
|
341
|
+
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})"
|
|
342
|
+
posthoc_results.add_result(
|
|
343
|
+
"Tukey HSD", result_pretty_text, row["p-adj"], groups_info
|
|
344
|
+
)
|
|
333
345
|
|
|
334
346
|
return posthoc_results
|
|
335
347
|
|
|
@@ -357,35 +369,39 @@ def get_dunn_posthoc_results(
|
|
|
357
369
|
df.groupby(group_column)[variable].agg(["mean", "median", "size"]).reset_index()
|
|
358
370
|
)
|
|
359
371
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
372
|
+
# Iterate only over the upper triangle of the matrix, excluding the diagonal
|
|
373
|
+
for i in range(dunn_results.shape[0]):
|
|
374
|
+
for j in range(i + 1, dunn_results.shape[1]):
|
|
375
|
+
p_value = dunn_results.iloc[i, j]
|
|
376
|
+
if p_value < p_value_threshold:
|
|
377
|
+
group_a_name = group_stats.iloc[i][group_column]
|
|
378
|
+
group_b_name = group_stats.iloc[j][group_column]
|
|
379
|
+
group_a_stats = group_stats.iloc[i]
|
|
380
|
+
group_b_stats = group_stats.iloc[j]
|
|
381
|
+
|
|
382
|
+
groups_info = sorted(
|
|
383
|
+
[
|
|
384
|
+
{
|
|
385
|
+
"name": group_a_name,
|
|
386
|
+
"sample_size": group_a_stats["size"],
|
|
387
|
+
"mean": group_a_stats["mean"],
|
|
388
|
+
"median": group_a_stats["median"],
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
"name": group_b_name,
|
|
392
|
+
"sample_size": group_b_stats["size"],
|
|
393
|
+
"mean": group_b_stats["mean"],
|
|
394
|
+
"median": group_b_stats["median"],
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
key=lambda x: x["mean"],
|
|
398
|
+
reverse=True,
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})"
|
|
402
|
+
posthoc_results.add_result(
|
|
403
|
+
"Dunn", result_pretty_text, p_value, groups_info
|
|
404
|
+
)
|
|
389
405
|
|
|
390
406
|
return posthoc_results
|
|
391
407
|
|
|
@@ -429,9 +445,11 @@ def get_mcnemar_results(
|
|
|
429
445
|
# Sort groups by mean for consistent presentation
|
|
430
446
|
groups_info.sort(key=lambda x: x["mean"], reverse=True)
|
|
431
447
|
# Format the result text
|
|
432
|
-
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})
|
|
448
|
+
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})"
|
|
433
449
|
# Add the result to posthoc results
|
|
434
|
-
posthoc_results.add_result(
|
|
450
|
+
posthoc_results.add_result(
|
|
451
|
+
"McNemar", result_pretty_text, p_value, groups_info
|
|
452
|
+
)
|
|
435
453
|
|
|
436
454
|
return posthoc_results
|
|
437
455
|
|
|
@@ -510,8 +528,13 @@ def get_repeated_measures_anova_posthoc_results(
|
|
|
510
528
|
]
|
|
511
529
|
# Sort groups by mean for consistent presentation
|
|
512
530
|
groups_info.sort(key=lambda x: x["mean"], reverse=True)
|
|
513
|
-
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})
|
|
514
|
-
posthoc_results.add_result(
|
|
531
|
+
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})"
|
|
532
|
+
posthoc_results.add_result(
|
|
533
|
+
"Repeated Measures ANOVA",
|
|
534
|
+
result_pretty_text,
|
|
535
|
+
p_val_corrected,
|
|
536
|
+
groups_info,
|
|
537
|
+
)
|
|
515
538
|
|
|
516
539
|
return posthoc_results
|
|
517
540
|
|
|
@@ -553,8 +576,8 @@ def get_wilcoxon_results(
|
|
|
553
576
|
]
|
|
554
577
|
groups_info.sort(key=lambda x: x["mean"], reverse=True)
|
|
555
578
|
|
|
556
|
-
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})
|
|
557
|
-
posthoc_results.add_result(result_pretty_text, p_value, groups_info)
|
|
579
|
+
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})"
|
|
580
|
+
posthoc_results.add_result("Wilcoxon", result_pretty_text, p_value, groups_info)
|
|
558
581
|
|
|
559
582
|
return p_value, posthoc_results
|
|
560
583
|
|
|
@@ -610,7 +633,9 @@ def get_nemenyi_results(
|
|
|
610
633
|
]
|
|
611
634
|
groups_info.sort(key=lambda x: x["mean"], reverse=True)
|
|
612
635
|
|
|
613
|
-
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})
|
|
614
|
-
posthoc_results.add_result(
|
|
636
|
+
result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) > {groups_info[1]['name']} ({groups_info[1]['mean']:.2f})"
|
|
637
|
+
posthoc_results.add_result(
|
|
638
|
+
"Nemenyi", result_pretty_text, posthoc_p_value, groups_info
|
|
639
|
+
)
|
|
615
640
|
|
|
616
641
|
return posthoc_results
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from .significance_tests import PosthocResults
|
|
2
|
+
from typing import Optional, List
|
|
3
|
+
import pandas as pd
|
|
4
|
+
from tabulate import tabulate
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_table_header(max_identifier_length: int) -> str:
|
|
8
|
+
"""
|
|
9
|
+
Returns a text with the results of the statistical significance tests.
|
|
10
|
+
|
|
11
|
+
Parameters:
|
|
12
|
+
max_identifier_length (int): The length of the longest identifier string.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
str: A formatted text string with the header of the pretty text table.
|
|
16
|
+
"""
|
|
17
|
+
if max_identifier_length > 0:
|
|
18
|
+
return f"{'Identifier':<{max_identifier_length}}{'n':>10} {'Result'}"
|
|
19
|
+
return f"{'n':>10} {'Result'}"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def format_results_as_table(
|
|
23
|
+
abalytics_results: List[PosthocResults],
|
|
24
|
+
header: bool = True,
|
|
25
|
+
identifiers_list: Optional[List[dict]] = None,
|
|
26
|
+
show_only_significant_results: bool = False,
|
|
27
|
+
show_details: bool = False,
|
|
28
|
+
output_format: str = "simple",
|
|
29
|
+
) -> str:
|
|
30
|
+
"""
|
|
31
|
+
Returns a text with the results of the statistical significance tests.
|
|
32
|
+
|
|
33
|
+
Parameters:
|
|
34
|
+
abalytics_results (list of PosthocResults): A list of PosthocResults objects.
|
|
35
|
+
header (bool, optional): A boolean flag indicating if the header of the pretty text table should be included. Defaults to True.
|
|
36
|
+
identifiers (list of str, optional): A list of strings that are to be used for identifying the data. Defaults to [].
|
|
37
|
+
show_only_significant_results (bool, optional): A boolean flag indicating if only significant results should be shown. Defaults to False.
|
|
38
|
+
show_details (bool, optional): A boolean flag indicating if the details of the statistical tests should be shown. Defaults to False.
|
|
39
|
+
output_format (str, optional): A string indicating the format of the output. Defaults to "simple". Checl the tabulate documentation: https://github.com/astanin/python-tabulate#table-format
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
str: A formatted text string with the results of the statistical significance tests.
|
|
43
|
+
"""
|
|
44
|
+
if identifiers_list:
|
|
45
|
+
assert len(identifiers_list) == len(
|
|
46
|
+
abalytics_results
|
|
47
|
+
), "The number of identifiers must match the number of results."
|
|
48
|
+
else:
|
|
49
|
+
identifiers_list = [{} for _ in range(len(abalytics_results))]
|
|
50
|
+
|
|
51
|
+
output_results = []
|
|
52
|
+
|
|
53
|
+
for idx, abalytics_result in enumerate(abalytics_results):
|
|
54
|
+
significant_results = abalytics_result.significant_results
|
|
55
|
+
info = abalytics_result.info
|
|
56
|
+
a_priori_test = abalytics_result.a_priori_test
|
|
57
|
+
sample_size = abalytics_result.sample_size
|
|
58
|
+
levene_flag = abalytics_result.levene_flag
|
|
59
|
+
gaussian_flag = abalytics_result.gaussian_flag
|
|
60
|
+
|
|
61
|
+
if show_only_significant_results and len(significant_results) == 0:
|
|
62
|
+
continue
|
|
63
|
+
if len(significant_results) > 0:
|
|
64
|
+
for result in significant_results:
|
|
65
|
+
row = identifiers_list[idx].copy()
|
|
66
|
+
row["n"] = sample_size
|
|
67
|
+
row["Result"] = result.result_pretty_text
|
|
68
|
+
row["p-value"] = result.p_value # round(result.p_value,3)
|
|
69
|
+
if show_details:
|
|
70
|
+
row["Analysis method"] = result.analysis_method
|
|
71
|
+
if info:
|
|
72
|
+
row["info"] = info
|
|
73
|
+
row["Gaussian"] = gaussian_flag
|
|
74
|
+
row["Levene"] = levene_flag
|
|
75
|
+
row["A priori test"] = a_priori_test
|
|
76
|
+
output_results.append(row)
|
|
77
|
+
elif info:
|
|
78
|
+
row = identifiers_list[idx]
|
|
79
|
+
row["n"] = sample_size
|
|
80
|
+
row["Result"] = None
|
|
81
|
+
row["p-value"] = None
|
|
82
|
+
row["info"] = info
|
|
83
|
+
if show_details and a_priori_test:
|
|
84
|
+
row["A priori test"] = a_priori_test
|
|
85
|
+
output_results.append(row)
|
|
86
|
+
|
|
87
|
+
table = tabulate(output_results, headers="keys", floatfmt=".3f", tablefmt=output_format)
|
|
88
|
+
return table
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: abalytics
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.2
|
|
4
4
|
Summary: Advanced A/B Testing Statistical Analytics
|
|
5
5
|
Author: Janis Berneker
|
|
6
6
|
License: LICENSE
|
|
@@ -13,6 +13,7 @@ Requires-Dist: scipy>=1.10.1
|
|
|
13
13
|
Requires-Dist: statsmodels>=0.14.1
|
|
14
14
|
Requires-Dist: scikit-posthocs>=0.8.1
|
|
15
15
|
Requires-Dist: pingouin>=0.5.4
|
|
16
|
+
Requires-Dist: tabulate>=0.9.0
|
|
16
17
|
|
|
17
18
|
# ABalytics: Advanced A/B Testing Statistical Analytics
|
|
18
19
|
|
|
@@ -120,7 +121,7 @@ analysis_results = analyze_independent_groups(
|
|
|
120
121
|
# Generate pretty text output
|
|
121
122
|
pretty_text = format_results_as_table(
|
|
122
123
|
abalytics_results=[analysis_results],
|
|
123
|
-
identifiers_list=[
|
|
124
|
+
identifiers_list=[{"Test name": "A/B Test 1", "Channel": "Mobile"}],
|
|
124
125
|
)
|
|
125
126
|
print(pretty_text)
|
|
126
127
|
```
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='abalytics',
|
|
5
|
-
version='
|
|
5
|
+
version='3.0.2',
|
|
6
6
|
author='Janis Berneker',
|
|
7
7
|
packages=find_packages(),
|
|
8
8
|
license='LICENSE',
|
|
@@ -14,7 +14,8 @@ setup(
|
|
|
14
14
|
'scipy>=1.10.1',
|
|
15
15
|
'statsmodels>=0.14.1',
|
|
16
16
|
'scikit-posthocs>=0.8.1',
|
|
17
|
-
'pingouin>=0.5.4'
|
|
17
|
+
'pingouin>=0.5.4',
|
|
18
|
+
'tabulate>=0.9.0'
|
|
18
19
|
],
|
|
19
20
|
python_requires='>=3.8',
|
|
20
21
|
project_urls={
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
from .significance_tests import PosthocResults
|
|
2
|
-
from typing import Optional, List
|
|
3
|
-
import pandas as pd
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def get_table_header(max_identifier_length: int) -> str:
|
|
7
|
-
"""
|
|
8
|
-
Returns a text with the results of the statistical significance tests.
|
|
9
|
-
|
|
10
|
-
Parameters:
|
|
11
|
-
max_identifier_length (int): The length of the longest identifier string.
|
|
12
|
-
|
|
13
|
-
Returns:
|
|
14
|
-
str: A formatted text string with the header of the pretty text table.
|
|
15
|
-
"""
|
|
16
|
-
if max_identifier_length > 0:
|
|
17
|
-
return f"{'Identifier':<{max_identifier_length}}{'n':>10} {'Levene':<6} {'Gaussian':<8} {'Result'}"
|
|
18
|
-
return f"{'n':>10} {'Levene':<6} {'Gaussian':<8} {'Result'}"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def format_results_as_table(
|
|
22
|
-
abalytics_results: List[PosthocResults],
|
|
23
|
-
header: bool = True,
|
|
24
|
-
identifiers_list: Optional[List[List[str]]] = None,
|
|
25
|
-
show_only_significant_results: bool = False,
|
|
26
|
-
) -> str:
|
|
27
|
-
"""
|
|
28
|
-
Returns a text with the results of the statistical significance tests.
|
|
29
|
-
|
|
30
|
-
Parameters:
|
|
31
|
-
abalytics_results (list of PosthocResults): A list of PosthocResults objects.
|
|
32
|
-
header (bool, optional): A boolean flag indicating if the header of the pretty text table should be included. Defaults to True.
|
|
33
|
-
identifiers (list of str, optional): A list of strings that are to be used for identifying the data. Defaults to [].
|
|
34
|
-
show_only_significant_results (bool, optional): A boolean flag indicating if only significant results should be shown. Defaults to False.
|
|
35
|
-
|
|
36
|
-
Returns:
|
|
37
|
-
str: A formatted text string with the results of the statistical significance tests.
|
|
38
|
-
"""
|
|
39
|
-
if identifiers_list:
|
|
40
|
-
assert len(identifiers_list) == len(
|
|
41
|
-
abalytics_results
|
|
42
|
-
), "The number of identifiers must match the number of results."
|
|
43
|
-
|
|
44
|
-
identifier_string_list = []
|
|
45
|
-
for identifiers in identifiers_list:
|
|
46
|
-
identifier_string = ""
|
|
47
|
-
if identifiers:
|
|
48
|
-
identifier_string = " ".join(identifiers)
|
|
49
|
-
identifier_string += " "
|
|
50
|
-
identifier_string_list.append(identifier_string)
|
|
51
|
-
else:
|
|
52
|
-
identifier_string_list = [""] * len(abalytics_results)
|
|
53
|
-
|
|
54
|
-
# Pad the identifier strings to the same length
|
|
55
|
-
max_identifier_length = max(
|
|
56
|
-
[len(identifier_string) for identifier_string in identifier_string_list]
|
|
57
|
-
)
|
|
58
|
-
identifier_string_list = [
|
|
59
|
-
s.ljust(max_identifier_length) for s in identifier_string_list
|
|
60
|
-
]
|
|
61
|
-
|
|
62
|
-
if header:
|
|
63
|
-
output_string += get_table_header(max_identifier_length)
|
|
64
|
-
output_string += "\n"
|
|
65
|
-
output_results = []
|
|
66
|
-
|
|
67
|
-
for idx, abalytics_result in enumerate(abalytics_results):
|
|
68
|
-
identifier_string = (
|
|
69
|
-
identifier_string_list[idx] if identifier_string_list else ""
|
|
70
|
-
)
|
|
71
|
-
significant_results = abalytics_result.significant_results
|
|
72
|
-
info = abalytics_result.info
|
|
73
|
-
sample_size = abalytics_result.sample_size
|
|
74
|
-
levene_flag = abalytics_result.levene_flag
|
|
75
|
-
gaussian_flag = abalytics_result.gaussian_flag
|
|
76
|
-
|
|
77
|
-
levene_output = "X" if levene_flag else ""
|
|
78
|
-
gaussian_output = "X" if gaussian_flag else ""
|
|
79
|
-
|
|
80
|
-
if show_only_significant_results and len(significant_results) == 0:
|
|
81
|
-
continue
|
|
82
|
-
if len(significant_results) > 0:
|
|
83
|
-
for i, result in enumerate(significant_results):
|
|
84
|
-
if i == 0:
|
|
85
|
-
output_results.append(
|
|
86
|
-
f"{identifier_string}{sample_size:>10} {levene_output:<6} {gaussian_output:<8} {result.result_pretty_text}"
|
|
87
|
-
)
|
|
88
|
-
else:
|
|
89
|
-
output_results.append(
|
|
90
|
-
f"{len(identifier_string) * ' '}{sample_size:>10} {levene_output:<6} {gaussian_output:<8} {result.result_pretty_text}"
|
|
91
|
-
)
|
|
92
|
-
else:
|
|
93
|
-
output_results.append(
|
|
94
|
-
f"{identifier_string}{sample_size:>10} {levene_output:<6} {gaussian_output:<8} {info}"
|
|
95
|
-
)
|
|
96
|
-
output_string = "\n".join(output_results)
|
|
97
|
-
return output_string
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def convert_long_to_wide(
|
|
101
|
-
df: pd.DataFrame, index_col: str, columns_col: str, flatten_columns: bool = True
|
|
102
|
-
) -> pd.DataFrame:
|
|
103
|
-
"""
|
|
104
|
-
Converts a DataFrame from long format to wide format, turning all columns into 'column_group' format.
|
|
105
|
-
Optionally flattens multi-level columns into single-level.
|
|
106
|
-
|
|
107
|
-
Parameters:
|
|
108
|
-
df (pd.DataFrame): The DataFrame in long format.
|
|
109
|
-
index_col (str): The name of the column to use as the identifier (index) in the wide format.
|
|
110
|
-
columns_col (str): The name of the column that contains the group names in the long format.
|
|
111
|
-
flatten_columns (bool, optional): Whether to flatten multi-level columns into single-level. Defaults to True.
|
|
112
|
-
|
|
113
|
-
Returns:
|
|
114
|
-
pd.DataFrame: The DataFrame converted to wide format, with optional column flattening.
|
|
115
|
-
"""
|
|
116
|
-
# Create a pivot table with multi-level columns
|
|
117
|
-
wide_df = df.pivot_table(index=index_col, columns=columns_col, aggfunc="first")
|
|
118
|
-
|
|
119
|
-
if flatten_columns:
|
|
120
|
-
# Flatten the multi-level columns and create combined column names
|
|
121
|
-
wide_df.columns = [
|
|
122
|
-
"{}_{}".format(col[0], col[1]) for col in wide_df.columns.values
|
|
123
|
-
]
|
|
124
|
-
|
|
125
|
-
return wide_df.reset_index()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|