ABalytics 1.1.4__tar.gz → 1.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-1.2/PKG-INFO ADDED
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.1
2
+ Name: abalytics
3
+ Version: 1.2
4
+ Summary: Advanced A/B Testing Statistical Analytics
5
+ Author: Janis Berneker
6
+ License: LICENSE
7
+ Project-URL: Repository, https://github.com/BigBerny/abalytics
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: pandas>=1.5.2
12
+ Requires-Dist: scipy>=1.10.1
13
+ Requires-Dist: statsmodels>=0.14.1
14
+ Requires-Dist: scikit-posthocs>=0.8.1
15
+ Requires-Dist: pingouin>=0.5.4
16
+
17
+ # ABalytics: Advanced A/B Testing Statistical Analytics
18
+
19
+ ABalytics is a Python package designed for statistical analysis, particularly for assessing the significance of A/B testing results. Its goal is to provide high-quality analysis by selecting the appropriate statistical tests based on the type of variable being analyzed. It offers a suite of tools to perform various significance tests and posthoc analyses on experimental data.
20
+
21
+ ## Features
22
+
23
+ - **Boolean and Numeric Analysis**: Supports analysis of both boolean and numeric data types, ensuring the use of correct statistical methods for each.
24
+ - **Significance Tests**: Includes a variety of significance tests such as Chi-Square, Welch's ANOVA, and Kruskal-Wallis, to accurately determine the significance of results.
25
+ - **Posthoc Analysis**: Offers posthoc analysis methods like Tukey's HSD, Dunn's test, and Games-Howell, for detailed examination following significance tests.
26
+ - **Normality and Homogeneity Checks**: Performs checks for Gaussian distribution and homogeneity of variances using Levene's test, which are critical for selecting the right tests.
27
+ - **Pretty Text Output**: Generates a formatted text output with the results of the statistical tests, facilitating interpretation and reporting.
28
+
29
+ ## Installation
30
+
31
+ To install ABalytics, use pip:
32
+ ```bash
33
+ pip install abalytics
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ To use ABalytics, import it:
39
+ ```python
40
+ import abalytics
41
+ ```
42
+
43
+ ### Analyzing Results
44
+
45
+ To analyze your A/B testing results, you can use the `get_results` function. This function takes a pandas DataFrame, the name of the column containing the variable to analyze, the name of the column containing the grouping variable, and an optional p-value threshold (default is 0.05).
46
+
47
+ Here's an example of how to use `get_results`:
48
+ ```python
49
+ from abalytics.analysis import get_results
50
+ import pandas as pd
51
+
52
+ #Load your data into a pandas DataFrame
53
+ df = pd.read_csv('your_data.csv')
54
+
55
+ #Analyze the results
56
+ analysis_results = get_results(
57
+ df,
58
+ variable_to_analyze = "order_value",
59
+ group_column = "ab_test_group",
60
+ p_value_threshold=0.05,
61
+ min_sample_size=25,
62
+ )
63
+ ```
64
+ The `get_results` function will return an `AnalysisResults` object containing the following attributes:
65
+ - `significant_results`: A list of results of the statistical significance tests.
66
+ - `info`: A string containing information about the data if no results were found.
67
+ - `sample_size`: The sample size of the data.
68
+ - `dichotomous_flag`: A boolean flag indicating if the data is dichotomous (e.g. boolean).
69
+ - `levene_flag`: A boolean flag indicating if Levene's test for homogeneity of variances is significant.
70
+ - `gaussian_flag`: A boolean flag indicating if the data has a Gaussian distribution.
71
+
72
+ ### Generating Pretty Text Output
73
+
74
+ For a formatted text output of your results, you can use the `get_results_pretty_text` function. This function takes the same parameters as `get_results` and additionally allows for identifiers to be included in the output and whether to include a header.
75
+
76
+ Here's an example of how to use `get_results_pretty_text`:
77
+ ```python
78
+ from abalytics.analysis import get_results_pretty_text
79
+
80
+ # Assuming 'df' is your pandas DataFrame
81
+ pretty_text = get_results_pretty_text(
82
+ df,
83
+ variable_to_analyze = "order_value",
84
+ group_column = "ab_test_group",
85
+ p_value_threshold=0.05,
86
+ min_sample_size=25,
87
+ header=True,
88
+ identifiers=["A/B Test 1", "Mobile"],
89
+ )
90
+
91
+ print(pretty_text)
92
+ ```
93
+ Executing this code will output a neatly formatted table displaying the outcomes of the statistical significance tests. The table includes the sample size, indicators for Levene's test and Gaussian distribution, and the test results.
94
+
95
+ A further example of how to use ABalytics can be found in `examples/example.py`.
96
+
97
+ ## Contributing
98
+
99
+ Contributions to ABalytics are welcome. If you have suggestions for improvements or find any issues, please open an issue or submit a pull request.
@@ -0,0 +1,83 @@
1
+ # ABalytics: Advanced A/B Testing Statistical Analytics
2
+
3
+ ABalytics is a Python package designed for statistical analysis, particularly for assessing the significance of A/B testing results. Its goal is to provide high-quality analysis by selecting the appropriate statistical tests based on the type of variable being analyzed. It offers a suite of tools to perform various significance tests and posthoc analyses on experimental data.
4
+
5
+ ## Features
6
+
7
+ - **Boolean and Numeric Analysis**: Supports analysis of both boolean and numeric data types, ensuring the use of correct statistical methods for each.
8
+ - **Significance Tests**: Includes a variety of significance tests such as Chi-Square, Welch's ANOVA, and Kruskal-Wallis, to accurately determine the significance of results.
9
+ - **Posthoc Analysis**: Offers posthoc analysis methods like Tukey's HSD, Dunn's test, and Games-Howell, for detailed examination following significance tests.
10
+ - **Normality and Homogeneity Checks**: Performs checks for Gaussian distribution and homogeneity of variances using Levene's test, which are critical for selecting the right tests.
11
+ - **Pretty Text Output**: Generates a formatted text output with the results of the statistical tests, facilitating interpretation and reporting.
12
+
13
+ ## Installation
14
+
15
+ To install ABalytics, use pip:
16
+ ```bash
17
+ pip install abalytics
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ To use ABalytics, import it:
23
+ ```python
24
+ import abalytics
25
+ ```
26
+
27
+ ### Analyzing Results
28
+
29
+ To analyze your A/B testing results, you can use the `get_results` function. This function takes a pandas DataFrame, the name of the column containing the variable to analyze, the name of the column containing the grouping variable, and an optional p-value threshold (default is 0.05).
30
+
31
+ Here's an example of how to use `get_results`:
32
+ ```python
33
+ from abalytics.analysis import get_results
34
+ import pandas as pd
35
+
36
+ #Load your data into a pandas DataFrame
37
+ df = pd.read_csv('your_data.csv')
38
+
39
+ #Analyze the results
40
+ analysis_results = get_results(
41
+ df,
42
+ variable_to_analyze = "order_value",
43
+ group_column = "ab_test_group",
44
+ p_value_threshold=0.05,
45
+ min_sample_size=25,
46
+ )
47
+ ```
48
+ The `get_results` function will return an `AnalysisResults` object containing the following attributes:
49
+ - `significant_results`: A list of results of the statistical significance tests.
50
+ - `info`: A string containing information about the data if no results were found.
51
+ - `sample_size`: The sample size of the data.
52
+ - `dichotomous_flag`: A boolean flag indicating if the data is dichotomous (e.g. boolean).
53
+ - `levene_flag`: A boolean flag indicating if Levene's test for homogeneity of variances is significant.
54
+ - `gaussian_flag`: A boolean flag indicating if the data has a Gaussian distribution.
55
+
56
+ ### Generating Pretty Text Output
57
+
58
+ For a formatted text output of your results, you can use the `get_results_pretty_text` function. This function takes the same parameters as `get_results` and additionally allows for identifiers to be included in the output and whether to include a header.
59
+
60
+ Here's an example of how to use `get_results_pretty_text`:
61
+ ```python
62
+ from abalytics.analysis import get_results_pretty_text
63
+
64
+ # Assuming 'df' is your pandas DataFrame
65
+ pretty_text = get_results_pretty_text(
66
+ df,
67
+ variable_to_analyze = "order_value",
68
+ group_column = "ab_test_group",
69
+ p_value_threshold=0.05,
70
+ min_sample_size=25,
71
+ header=True,
72
+ identifiers=["A/B Test 1", "Mobile"],
73
+ )
74
+
75
+ print(pretty_text)
76
+ ```
77
+ Executing this code will output a neatly formatted table displaying the outcomes of the statistical significance tests. The table includes the sample size, indicators for Levene's test and Gaussian distribution, and the test results.
78
+
79
+ A further example of how to use ABalytics can be found in `examples/example.py`.
80
+
81
+ ## Contributing
82
+
83
+ Contributions to ABalytics are welcome. If you have suggestions for improvements or find any issues, please open an issue or submit a pull request.
@@ -1,6 +1,6 @@
1
1
  import pandas as pd
2
2
  from .significance_tests import (
3
- is_boolean,
3
+ is_dichotomous,
4
4
  is_numeric,
5
5
  is_levene_significant,
6
6
  is_gaussian,
@@ -13,19 +13,36 @@ from .significance_tests import (
13
13
  get_tukeyhsd_posthoc_results,
14
14
  get_dunn_posthoc_results,
15
15
  )
16
+ from typing import Optional, List
16
17
 
17
18
 
18
19
  class AnalysisResults:
19
- def __init__(self, significant_results=None, info=None, sample_size=None, boolean_flag=None, levene_flag=None, gaussian_flag=None):
20
- self.significant_results = significant_results if significant_results is not None else []
20
+ def __init__(
21
+ self,
22
+ significant_results=None,
23
+ info=None,
24
+ sample_size=None,
25
+ dichotomous_flag=None,
26
+ levene_flag=None,
27
+ gaussian_flag=None,
28
+ ):
29
+ self.significant_results = (
30
+ significant_results if significant_results is not None else []
31
+ )
21
32
  self.info = info
22
33
  self.sample_size = sample_size
23
- self.boolean_flag = boolean_flag
34
+ self.dichotomous_flag = dichotomous_flag
24
35
  self.levene_flag = levene_flag
25
36
  self.gaussian_flag = gaussian_flag
26
37
 
27
38
 
28
- def get_results(df, variable_to_analyze, group_column, p_value_threshold=0.05):
39
+ def get_results(
40
+ df: pd.DataFrame,
41
+ variable_to_analyze: str,
42
+ group_column: str,
43
+ p_value_threshold: float = 0.05,
44
+ min_sample_size: int = 25,
45
+ ) -> Optional[AnalysisResults]:
29
46
  """
30
47
  Returns a text with the results of the statistical significance tests.
31
48
 
@@ -34,13 +51,14 @@ def get_results(df, variable_to_analyze, group_column, p_value_threshold=0.05):
34
51
  variable_to_analyze (str): The column name in df that is to be analyzed for statistical significance.
35
52
  group_column (str): The name of the column in df that contains the grouping variable.
36
53
  p_value_threshold (float, optional): The threshold for determining statistical significance. Defaults to 0.05.
54
+ min_sample_size (int, optional): The minimum sample size for the data. Defaults to 25.
37
55
 
38
56
  Returns:
39
57
  AnalysisResults: An instance of the AnalysisResults class containing the following attributes:
40
58
  - significant_results: A list of results of the statistical significance tests.
41
59
  - info: A string containing information about the data if no results were found.
42
60
  - sample_size: The sample size of the data.
43
- - boolean_flag: A boolean flag indicating if the variable is boolean.
61
+ - dichotomous_flag: A boolean flag indicating if the data is dichotomous (e.g. boolean).
44
62
  - levene_flag: A boolean flag indicating if Levene's test for homogeneity of variances is significant.
45
63
  - gaussian_flag: A boolean flag indicating if the data has a Gaussian distribution.
46
64
  """
@@ -49,18 +67,29 @@ def get_results(df, variable_to_analyze, group_column, p_value_threshold=0.05):
49
67
  "Warning: p_value_threshold is set to a value higher than the conventional alpha level of 0.05."
50
68
  )
51
69
 
70
+ try:
71
+ df[variable_to_analyze]
72
+ df[group_column]
73
+ except KeyError as e:
74
+ print(f"Column not found in DataFrame: {e}")
75
+ return None
76
+
52
77
  df = df.dropna(subset=[variable_to_analyze])
53
78
  sample_size = len(df)
54
79
  pvalue = None
55
80
  info = None
56
- boolean_flag = False
81
+ dichotomous_flag = False
57
82
  levene_flag = False
58
83
  gaussian_flag = False
59
- # Check if there is enough data
60
- if len(df) < 25 * df[group_column].nunique():
84
+ # Check if any group has less than the minimum sample size
85
+ if (
86
+ df.groupby(group_column)[variable_to_analyze]
87
+ .apply(lambda x: len(x) < min_sample_size)
88
+ .any()
89
+ ):
61
90
  info = "not enough data"
62
91
  # Check if the variable is dichotomous (e.g. boolean)
63
- elif boolean_flag := is_boolean(df, variable_to_analyze):
92
+ elif dichotomous_flag := is_dichotomous(df, variable_to_analyze):
64
93
  # Perform chi-square test
65
94
  pvalue = get_chi_square_significance(df, group_column, variable_to_analyze)
66
95
  if pvalue < p_value_threshold:
@@ -97,24 +126,30 @@ def get_results(df, variable_to_analyze, group_column, p_value_threshold=0.05):
97
126
  df, group_column, variable_to_analyze, p_value_threshold
98
127
  )
99
128
  else:
100
- print("Variable has to be boolean or numeric")
129
+ print("Variable has to be dichotomous (e.g. boolean) or numeric")
130
+ info = "Variable has to be dichotomous (e.g. boolean) or numeric"
101
131
 
102
132
  # If no results were found, return a message
103
- if not 'results' in locals() or len(results.significant_results) == 0:
133
+ if not "results" in locals() or len(results.significant_results) == 0:
104
134
  if pvalue is not None:
105
135
  info = f"not significant (p={pvalue:.3f})"
106
136
  # If results were found, return them
107
- if 'results' in locals():
137
+ if "results" in locals():
108
138
  significant_results = results.significant_results
109
139
  else:
110
140
  significant_results = []
111
141
 
112
142
  return AnalysisResults(
113
- significant_results, info, sample_size, boolean_flag, levene_flag, gaussian_flag
143
+ significant_results,
144
+ info,
145
+ sample_size,
146
+ dichotomous_flag,
147
+ levene_flag,
148
+ gaussian_flag,
114
149
  )
115
150
 
116
151
 
117
- def get_results_pretty_text_header(identifiers=None):
152
+ def get_results_pretty_text_header(identifiers: Optional[List[str]] = None) -> str:
118
153
  """
119
154
  Returns a text with the results of the statistical significance tests.
120
155
 
@@ -131,20 +166,21 @@ def get_results_pretty_text_header(identifiers=None):
131
166
  identifier_string += " "
132
167
  identifier_string_empty = " ".join([""] * len(identifiers))
133
168
  identifier_string_empty += " "
134
- output_string = f"{'Identifier':<{len(identifier_string)}}{'n':>10} {'Boolean':<7} {'Levene':<6} {'Gaussian':<8} {'Result'}"
169
+ output_string = f"{'Identifier':<{len(identifier_string)}}{'n':>10} {'Levene':<6} {'Gaussian':<8} {'Result'}"
135
170
  else:
136
- output_string = f"{'n':>10} {'Boolean':<7} {'Levene':<6} {'Gaussian':<8} {'Result'}"
171
+ output_string = f"{'n':>10} {'Levene':<6} {'Gaussian':<8} {'Result'}"
137
172
 
138
173
  return output_string
139
174
 
140
175
 
141
176
  def get_results_pretty_text(
142
- df,
143
- variable_to_analyze,
144
- group_column,
145
- identifiers=None,
146
- p_value_threshold=0.05,
147
- header=True,
177
+ df: pd.DataFrame,
178
+ variable_to_analyze: str,
179
+ group_column: str,
180
+ p_value_threshold: float = 0.05,
181
+ min_sample_size: int = 25,
182
+ header: bool = True,
183
+ identifiers: Optional[List[str]] = None,
148
184
  ):
149
185
  """
150
186
  Returns a text with the results of the statistical significance tests.
@@ -153,20 +189,22 @@ def get_results_pretty_text(
153
189
  df (pandas.DataFrame): The dataframe containing the data to analyze.
154
190
  variable_to_analyze (str): The column name in df that is to be analyzed for statistical significance.
155
191
  group_column (str): The name of the column in df that contains the grouping variable.
156
- identifiers (list of str, optional): A list of strings that are to be used for identifying the data. Defaults to [].
157
192
  p_value_threshold (float, optional): The threshold for determining statistical significance. Defaults to 0.05.
193
+ min_sample_size (int, optional): The minimum sample size for the data. Defaults to 25.
194
+ header (bool, optional): A boolean flag indicating if the header of the pretty text table should be included. Defaults to True.
195
+ identifiers (list of str, optional): A list of strings that are to be used for identifying the data. Defaults to [].
158
196
 
159
197
  Returns:
160
198
  str: A formatted text string with the results of the statistical significance tests.
161
199
  """
162
200
 
163
201
  analysis_results = get_results(
164
- df, variable_to_analyze, group_column, p_value_threshold
202
+ df, variable_to_analyze, group_column, p_value_threshold, min_sample_size
165
203
  )
166
204
  significant_results = analysis_results.significant_results
167
205
  info = analysis_results.info
168
206
  sample_size = analysis_results.sample_size
169
- boolean_flag = analysis_results.boolean_flag
207
+ dichotomous_flag = analysis_results.dichotomous_flag
170
208
  levene_flag = analysis_results.levene_flag
171
209
  gaussian_flag = analysis_results.gaussian_flag
172
210
 
@@ -183,7 +221,6 @@ def get_results_pretty_text(
183
221
  output_string += get_results_pretty_text_header(identifiers)
184
222
  output_string += "\n"
185
223
 
186
- boolean_output = "X" if boolean_flag else ""
187
224
  levene_output = "X" if levene_flag else ""
188
225
  gaussian_output = "X" if gaussian_flag else ""
189
226
 
@@ -192,15 +229,15 @@ def get_results_pretty_text(
192
229
  for i, result in enumerate(significant_results):
193
230
  if i == 0:
194
231
  output_results.append(
195
- f"{identifier_string}{sample_size:>10} {boolean_output:<7} {levene_output:<6} {gaussian_output:<8} {result.result_pretty}"
232
+ f"{identifier_string}{sample_size:>10} {levene_output:<6} {gaussian_output:<8} {result.result_pretty_text}"
196
233
  )
197
234
  else:
198
235
  output_results.append(
199
- f"{identifier_string}{sample_size:>10} {boolean_output:<7} {levene_output:<6} {gaussian_output:<8} {result.result_pretty}"
236
+ f"{len(identifier_string) * ' '}{sample_size:>10} {levene_output:<6} {gaussian_output:<8} {result.result_pretty_text}"
200
237
  )
201
238
  else:
202
239
  output_results.append(
203
- f"{identifier_string}{sample_size:>10} {boolean_output:<7} {levene_output:<6} {gaussian_output:<8} {info}"
240
+ f"{identifier_string}{sample_size:>10} {levene_output:<6} {gaussian_output:<8} {info}"
204
241
  )
205
242
  output_string += "\n".join(output_results)
206
243
  return output_string
@@ -7,44 +7,57 @@ from statsmodels.stats.multicomp import pairwise_tukeyhsd
7
7
  from statsmodels.stats.proportion import proportions_ztest
8
8
  from pingouin import pairwise_gameshowell, welch_anova
9
9
  from itertools import combinations
10
+ from typing import List, Dict, Union, Any
10
11
 
11
12
 
12
13
  class PosthocResult:
13
- def __init__(self, result_pretty, p_value, groups):
14
- self.result_pretty = result_pretty
15
- self.p_value = p_value
16
- self.groups = groups
14
+ def __init__(
15
+ self, result_pretty_text: str, p_value: float, groups: List["GroupResult"]
16
+ ):
17
+ self.result_pretty_text: str = result_pretty_text
18
+ self.p_value: float = p_value
19
+ self.groups: List[GroupResult] = groups
17
20
 
18
21
 
19
22
  class GroupResult:
20
- def __init__(self, name, sample_size, mean, median=None):
21
- self.name = name
22
- self.sample_size = sample_size
23
- self.mean = mean
24
- self.median = median
23
+ def __init__(
24
+ self,
25
+ name: str,
26
+ sample_size: int,
27
+ mean: float,
28
+ median: Union[float, None] = None,
29
+ ):
30
+ self.name: str = name
31
+ self.sample_size: int = sample_size
32
+ self.mean: float = mean
33
+ self.median: Union[float, None] = median
25
34
 
26
35
 
27
36
  class PosthocResults:
28
37
  def __init__(self):
29
- self.significant_results = []
38
+ self.significant_results: List[PosthocResult] = []
30
39
 
31
- def add_result(self, result_pretty, p_value, groups_info):
32
- groups = [GroupResult(**group) for group in groups_info]
33
- result = PosthocResult(result_pretty, p_value, groups)
40
+ def add_result(
41
+ self, result_pretty_text: str, p_value: float, groups_info: List[Dict[str, Any]]
42
+ ):
43
+ groups: List[GroupResult] = [GroupResult(**group) for group in groups_info]
44
+ result: PosthocResult = PosthocResult(result_pretty_text, p_value, groups)
34
45
  self.significant_results.append(result)
35
46
 
36
47
 
37
- def is_boolean(df, variable):
38
- # Check if the variable is of boolean type
39
- return df[variable].dtype == bool
48
+ def is_dichotomous(df: pd.DataFrame, variable: str) -> bool:
49
+ # Check if the variable has only two unique values
50
+ return len(df[variable].unique()) == 2
40
51
 
41
52
 
42
- def is_numeric(df, variable):
53
+ def is_numeric(df: pd.DataFrame, variable: str) -> bool:
43
54
  # Check if the variable is of numeric type
44
55
  return df[variable].dtype in [float, int]
45
56
 
46
57
 
47
- def is_gaussian(df, group_column, variable, p_value_threshold):
58
+ def is_gaussian(
59
+ df: pd.DataFrame, group_column: str, variable: str, p_value_threshold: float
60
+ ) -> bool:
48
61
  # Iterate over each unique group in the specified column
49
62
  for group in df[group_column].unique():
50
63
  # Subset the dataframe for the current group and test for normality
@@ -59,13 +72,17 @@ def is_gaussian(df, group_column, variable, p_value_threshold):
59
72
  return True
60
73
 
61
74
 
62
- def get_chi_square_significance(df, group_column, variable):
75
+ def get_chi_square_significance(
76
+ df: pd.DataFrame, group_column: str, variable: str
77
+ ) -> float:
63
78
  contingency_table = pd.crosstab(df[group_column], df[variable])
64
79
  _, pvalue, _, _ = chi2_contingency(contingency_table)
65
80
  return pvalue
66
81
 
67
82
 
68
- def get_chi_square_posthoc_results(df, group_column, variable, p_value_threshold):
83
+ def get_chi_square_posthoc_results(
84
+ df: pd.DataFrame, group_column: str, variable: str, p_value_threshold: float
85
+ ) -> PosthocResults:
69
86
  posthoc_results = PosthocResults()
70
87
  contingency_table = pd.crosstab(df[group_column], df[variable])
71
88
  group_combinations = [
@@ -73,7 +90,7 @@ def get_chi_square_posthoc_results(df, group_column, variable, p_value_threshold
73
90
  for i, group_a in enumerate(contingency_table.index)
74
91
  for group_b in contingency_table.index[i + 1 :]
75
92
  ]
76
- p_values = []
93
+ p_values: List[float] = []
77
94
 
78
95
  for group_a, group_b in group_combinations:
79
96
  if 1 not in contingency_table.columns:
@@ -91,29 +108,33 @@ def get_chi_square_posthoc_results(df, group_column, variable, p_value_threshold
91
108
 
92
109
  groups_info = sorted(
93
110
  [
94
- {'name': group_a, 'sample_size': nobs[0], 'mean': rate_a},
95
- {'name': group_b, 'sample_size': nobs[1], 'mean': rate_b}
111
+ {"name": group_a, "sample_size": nobs[0], "mean": rate_a},
112
+ {"name": group_b, "sample_size": nobs[1], "mean": rate_b},
96
113
  ],
97
- key=lambda x: x['mean'],
98
- reverse=True
114
+ key=lambda x: x["mean"],
115
+ reverse=True,
99
116
  )
100
117
 
101
118
  if p_value < p_value_threshold:
102
- result_pretty = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.1f}%) vs {groups_info[1]['name']} ({groups_info[1]['mean']:.1f}%) (p={p_value:.3f})"
103
- posthoc_results.add_result(result_pretty, p_value, groups_info)
119
+ result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.1f}%) vs {groups_info[1]['name']} ({groups_info[1]['mean']:.1f}%) (p={p_value:.3f})"
120
+ posthoc_results.add_result(result_pretty_text, p_value, groups_info)
104
121
 
105
122
  if len(p_values) == 0:
106
123
  return posthoc_results
107
124
  # Apply Bonferroni correction
108
125
  corrected_alpha = p_value_threshold / len(p_values)
109
126
  posthoc_results.significant_results = [
110
- result for result in posthoc_results.significant_results if result.p_value < corrected_alpha
127
+ result
128
+ for result in posthoc_results.significant_results
129
+ if result.p_value < corrected_alpha
111
130
  ]
112
131
 
113
132
  return posthoc_results
114
133
 
115
134
 
116
- def is_levene_significant(df, group_column, variable, p_value_threshold):
135
+ def is_levene_significant(
136
+ df: pd.DataFrame, group_column: str, variable: str, p_value_threshold: float
137
+ ) -> bool:
117
138
  # Prepare data for homogeneity of variances test
118
139
  groups = df[group_column].unique()
119
140
  data_groups = [df[df[group_column] == group][variable] for group in groups]
@@ -125,16 +146,22 @@ def is_levene_significant(df, group_column, variable, p_value_threshold):
125
146
  return p_levene < p_value_threshold
126
147
 
127
148
 
128
- def get_welch_anova_significance(df, group_column, variable):
149
+ def get_welch_anova_significance(
150
+ df: pd.DataFrame, group_column: str, variable: str
151
+ ) -> float:
129
152
  # Perform Welch's ANOVA
130
153
  welch_anova_results = welch_anova(data=df, dv=variable, between=group_column)
131
154
  # Check if the p-value from Welch's ANOVA is significant
132
155
  return welch_anova_results.loc[0, "p-unc"]
133
156
 
134
157
 
135
- def get_games_howell_posthoc_results(df, group_column, variable, p_value_threshold):
158
+ def get_games_howell_posthoc_results(
159
+ df: pd.DataFrame, group_column: str, variable: str, p_value_threshold: float
160
+ ) -> PosthocResults:
136
161
  posthoc_results = PosthocResults()
137
- games_howell_results = pairwise_gameshowell(data=df, dv=variable, between=group_column)
162
+ games_howell_results = pairwise_gameshowell(
163
+ data=df, dv=variable, between=group_column
164
+ )
138
165
  group_means = df.groupby(group_column)[variable].mean()
139
166
  group_medians = df.groupby(group_column)[variable].median()
140
167
  group_sizes = df.groupby(group_column).size()
@@ -150,35 +177,30 @@ def get_games_howell_posthoc_results(df, group_column, variable, p_value_thresho
150
177
  # Order groups so the one with the higher mean is first
151
178
  groups_info = sorted(
152
179
  [
153
- {'name': group_a, 'sample_size': size_a, 'mean': mean_a, 'median': median_a},
154
- {'name': group_b, 'sample_size': size_b, 'mean': mean_b, 'median': median_b}
180
+ {
181
+ "name": group_a,
182
+ "sample_size": size_a,
183
+ "mean": mean_a,
184
+ "median": median_a,
185
+ },
186
+ {
187
+ "name": group_b,
188
+ "sample_size": size_b,
189
+ "mean": mean_b,
190
+ "median": median_b,
191
+ },
155
192
  ],
156
- key=lambda x: x['mean'],
157
- reverse=True
193
+ key=lambda x: x["mean"],
194
+ reverse=True,
158
195
  )
159
196
 
160
- result_pretty = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) vs {groups_info[1]['name']} ({groups_info[1]['mean']:.2f}) (p={p_value:.3f})"
161
- posthoc_results.add_result(result_pretty, p_value, groups_info)
197
+ result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) vs {groups_info[1]['name']} ({groups_info[1]['mean']:.2f}) (p={p_value:.3f})"
198
+ posthoc_results.add_result(result_pretty_text, p_value, groups_info)
162
199
 
163
200
  return posthoc_results
164
201
 
165
202
 
166
- def is_gaussian(df, group_column, variable, p_value_threshold):
167
- # Iterate over each unique group in the specified column
168
- for group in df[group_column].unique():
169
- # Subset the dataframe for the current group and test for normality
170
- group_data = df[df[group_column] == group][variable]
171
- _, p_value = normaltest(group_data)
172
-
173
- # If the p-value is less than the threshold, the data is not Gaussian
174
- if p_value < p_value_threshold:
175
- return False # Early return if any group is not Gaussian
176
-
177
- # If all groups passed the normality test, return True
178
- return True
179
-
180
-
181
- def get_anova_results(df, group_column, variable):
203
+ def get_anova_results(df: pd.DataFrame, group_column: str, variable: str) -> AnovaRM:
182
204
  # Perform one-way ANOVA
183
205
  anova_results = AnovaRM(
184
206
  data=df, depvar=variable, subject="session_id", within=[group_column]
@@ -186,7 +208,9 @@ def get_anova_results(df, group_column, variable):
186
208
  return anova_results
187
209
 
188
210
 
189
- def get_oneway_anova_significance(df, group_column, variable):
211
+ def get_oneway_anova_significance(
212
+ df: pd.DataFrame, group_column: str, variable: str
213
+ ) -> float:
190
214
  group_names = df[group_column].unique()
191
215
  # Perform one-way ANOVA
192
216
  group_data = [df[df[group_column] == group][variable] for group in group_names]
@@ -194,7 +218,9 @@ def get_oneway_anova_significance(df, group_column, variable):
194
218
  return pvalue
195
219
 
196
220
 
197
- def get_crushal_wallis_significance(df, group_column, variable):
221
+ def get_crushal_wallis_significance(
222
+ df: pd.DataFrame, group_column: str, variable: str
223
+ ) -> float:
198
224
  group_names = df[group_column].unique()
199
225
  # Perform Kruskal-Wallis test
200
226
  group_data = [df[df[group_column] == group][variable] for group in group_names]
@@ -202,7 +228,9 @@ def get_crushal_wallis_significance(df, group_column, variable):
202
228
  return pvalue
203
229
 
204
230
 
205
- def get_tukeyhsd_posthoc_results(df, group_column, variable, p_value_threshold):
231
+ def get_tukeyhsd_posthoc_results(
232
+ df: pd.DataFrame, group_column: str, variable: str, p_value_threshold: float
233
+ ) -> PosthocResults:
206
234
  posthoc_results = PosthocResults()
207
235
  # Perform Tukey's HSD test
208
236
  tukey = pairwise_tukeyhsd(
@@ -228,15 +256,25 @@ def get_tukeyhsd_posthoc_results(df, group_column, variable, p_value_threshold):
228
256
  # Order groups so the one with the higher mean is first
229
257
  groups_info = sorted(
230
258
  [
231
- {'name': group_a, 'sample_size': size_a, 'mean': mean_a, 'median': median_a},
232
- {'name': group_b, 'sample_size': size_b, 'mean': mean_b, 'median': median_b}
259
+ {
260
+ "name": group_a,
261
+ "sample_size": size_a,
262
+ "mean": mean_a,
263
+ "median": median_a,
264
+ },
265
+ {
266
+ "name": group_b,
267
+ "sample_size": size_b,
268
+ "mean": mean_b,
269
+ "median": median_b,
270
+ },
233
271
  ],
234
- key=lambda x: x['mean'],
235
- reverse=True
272
+ key=lambda x: x["mean"],
273
+ reverse=True,
236
274
  )
237
275
 
238
- result_pretty = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) vs {groups_info[1]['name']} ({groups_info[1]['mean']:.2f}) (p={p_value:.3f})"
239
- posthoc_results.add_result(result_pretty, p_value, groups_info)
276
+ result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) vs {groups_info[1]['name']} ({groups_info[1]['mean']:.2f}) (p={p_value:.3f})"
277
+ posthoc_results.add_result(result_pretty_text, p_value, groups_info)
240
278
 
241
279
  return posthoc_results
242
280
 
@@ -260,17 +298,27 @@ def get_dunn_posthoc_results(df, group_column, variable, p_value_threshold):
260
298
  mean_a, mean_b = group_means[group_a], group_means[group_b]
261
299
  median_a, median_b = group_medians[group_a], group_medians[group_b]
262
300
  size_a, size_b = group_sizes[group_a], group_sizes[group_b]
263
-
301
+
264
302
  # Order groups so the one with the higher mean is first
265
303
  groups_info = sorted(
266
304
  [
267
- {'name': group_a, 'sample_size': size_a, 'mean': mean_a, 'median': median_a},
268
- {'name': group_b, 'sample_size': size_b, 'mean': mean_b, 'median': median_b}
305
+ {
306
+ "name": group_a,
307
+ "sample_size": size_a,
308
+ "mean": mean_a,
309
+ "median": median_a,
310
+ },
311
+ {
312
+ "name": group_b,
313
+ "sample_size": size_b,
314
+ "mean": mean_b,
315
+ "median": median_b,
316
+ },
269
317
  ],
270
- key=lambda x: x['mean'],
271
- reverse=True
318
+ key=lambda x: x["mean"],
319
+ reverse=True,
272
320
  )
273
-
274
- result_pretty = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) vs {groups_info[1]['name']} ({groups_info[1]['mean']:.2f}) (p={p_value:.3f})"
275
- posthoc_results.add_result(result_pretty, p_value, groups_info)
321
+
322
+ result_pretty_text = f"{groups_info[0]['name']} ({groups_info[0]['mean']:.2f}) vs {groups_info[1]['name']} ({groups_info[1]['mean']:.2f}) (p={p_value:.3f})"
323
+ posthoc_results.add_result(result_pretty_text, p_value, groups_info)
276
324
  return posthoc_results
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.1
2
+ Name: abalytics
3
+ Version: 1.2
4
+ Summary: Advanced A/B Testing Statistical Analytics
5
+ Author: Janis Berneker
6
+ License: LICENSE
7
+ Project-URL: Repository, https://github.com/BigBerny/abalytics
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: pandas>=1.5.2
12
+ Requires-Dist: scipy>=1.10.1
13
+ Requires-Dist: statsmodels>=0.14.1
14
+ Requires-Dist: scikit-posthocs>=0.8.1
15
+ Requires-Dist: pingouin>=0.5.4
16
+
17
+ # ABalytics: Advanced A/B Testing Statistical Analytics
18
+
19
+ ABalytics is a Python package designed for statistical analysis, particularly for assessing the significance of A/B testing results. Its goal is to provide high-quality analysis by selecting the appropriate statistical tests based on the type of variable being analyzed. It offers a suite of tools to perform various significance tests and posthoc analyses on experimental data.
20
+
21
+ ## Features
22
+
23
+ - **Boolean and Numeric Analysis**: Supports analysis of both boolean and numeric data types, ensuring the use of correct statistical methods for each.
24
+ - **Significance Tests**: Includes a variety of significance tests such as Chi-Square, Welch's ANOVA, and Kruskal-Wallis, to accurately determine the significance of results.
25
+ - **Posthoc Analysis**: Offers posthoc analysis methods like Tukey's HSD, Dunn's test, and Games-Howell, for detailed examination following significance tests.
26
+ - **Normality and Homogeneity Checks**: Performs checks for Gaussian distribution and homogeneity of variances using Levene's test, which are critical for selecting the right tests.
27
+ - **Pretty Text Output**: Generates a formatted text output with the results of the statistical tests, facilitating interpretation and reporting.
28
+
29
+ ## Installation
30
+
31
+ To install ABalytics, use pip:
32
+ ```bash
33
+ pip install abalytics
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ To use ABalytics, import it:
39
+ ```python
40
+ import abalytics
41
+ ```
42
+
43
+ ### Analyzing Results
44
+
45
+ To analyze your A/B testing results, you can use the `get_results` function. This function takes a pandas DataFrame, the name of the column containing the variable to analyze, the name of the column containing the grouping variable, and an optional p-value threshold (default is 0.05).
46
+
47
+ Here's an example of how to use `get_results`:
48
+ ```python
49
+ from abalytics.analysis import get_results
50
+ import pandas as pd
51
+
52
+ #Load your data into a pandas DataFrame
53
+ df = pd.read_csv('your_data.csv')
54
+
55
+ #Analyze the results
56
+ analysis_results = get_results(
57
+ df,
58
+ variable_to_analyze = "order_value",
59
+ group_column = "ab_test_group",
60
+ p_value_threshold=0.05,
61
+ min_sample_size=25,
62
+ )
63
+ ```
64
+ The `get_results` function will return an `AnalysisResults` object containing the following attributes:
65
+ - `significant_results`: A list of results of the statistical significance tests.
66
+ - `info`: A string containing information about the data if no results were found.
67
+ - `sample_size`: The sample size of the data.
68
+ - `dichotomous_flag`: A boolean flag indicating if the data is dichotomous (e.g. boolean).
69
+ - `levene_flag`: A boolean flag indicating if Levene's test for homogeneity of variances is significant.
70
+ - `gaussian_flag`: A boolean flag indicating if the data has a Gaussian distribution.
71
+
72
+ ### Generating Pretty Text Output
73
+
74
+ For a formatted text output of your results, you can use the `get_results_pretty_text` function. This function takes the same parameters as `get_results` and additionally allows for identifiers to be included in the output and whether to include a header.
75
+
76
+ Here's an example of how to use `get_results_pretty_text`:
77
+ ```python
78
+ from abalytics.analysis import get_results_pretty_text
79
+
80
+ # Assuming 'df' is your pandas DataFrame
81
+ pretty_text = get_results_pretty_text(
82
+ df,
83
+ variable_to_analyze = "order_value",
84
+ group_column = "ab_test_group",
85
+ p_value_threshold=0.05,
86
+ min_sample_size=25,
87
+ header=True,
88
+ identifiers=["A/B Test 1", "Mobile"],
89
+ )
90
+
91
+ print(pretty_text)
92
+ ```
93
+ Executing this code will output a neatly formatted table displaying the outcomes of the statistical significance tests. The table includes the sample size, indicators for Levene's test and Gaussian distribution, and the test results.
94
+
95
+ A further example of how to use ABalytics can be found in `examples/example.py`.
96
+
97
+ ## Contributing
98
+
99
+ Contributions to ABalytics are welcome. If you have suggestions for improvements or find any issues, please open an issue or submit a pull request.
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='abalytics',
5
- version='1.1.4',
5
+ version='1.2',
6
6
  author='Janis Berneker',
7
7
  packages=find_packages(),
8
8
  license='LICENSE',
abalytics-1.1.4/PKG-INFO DELETED
@@ -1,43 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: abalytics
3
- Version: 1.1.4
4
- Summary: Advanced A/B Testing Statistical Analytics
5
- Author: Janis Berneker
6
- License: LICENSE
7
- Project-URL: Repository, https://github.com/BigBerny/abalytics
8
- Requires-Python: >=3.8
9
- Description-Content-Type: text/markdown
10
- License-File: LICENSE
11
- Requires-Dist: pandas>=1.5.2
12
- Requires-Dist: scipy>=1.10.1
13
- Requires-Dist: statsmodels>=0.14.1
14
- Requires-Dist: scikit-posthocs>=0.8.1
15
- Requires-Dist: pingouin>=0.5.4
16
-
17
- # ABalytics: Advanced A/B Testing Statistical Analytics
18
-
19
- ABalytics is a Python package designed for statistical analysis, particularly for assessing the significance of A/B testing results. Its goal is to provide high-quality analysis by selecting the appropriate statistical tests based on the type of variable being analyzed. It offers a suite of tools to perform various significance tests and posthoc analyses on experimental data.
20
-
21
- ## Features
22
-
23
- - **Boolean and Numeric Analysis**: Supports analysis of both boolean and numeric data types, ensuring the use of correct statistical methods for each.
24
- - **Significance Tests**: Includes a variety of significance tests such as Chi-Square, Welch's ANOVA, and Kruskal-Wallis, to accurately determine the significance of results.
25
- - **Posthoc Analysis**: Offers posthoc analysis methods like Tukey's HSD, Dunn's test, and Games-Howell, for detailed examination following significance tests.
26
- - **Normality and Homogeneity Checks**: Performs checks for Gaussian distribution and homogeneity of variances using Levene's test, which are critical for selecting the right tests.
27
- - **Pretty Text Output**: Generates a formatted text output with the results of the statistical tests, facilitating interpretation and reporting.
28
-
29
- ## Installation
30
-
31
- To install ABalytics, use pip:
32
- ```pip install abalytics```
33
-
34
- ## Usage
35
-
36
- To use ABalytics, import it:
37
- ```import abalytics```
38
-
39
- An example of how to use ABalytics can be found in `examples/example.py`.
40
-
41
- ## Contributing
42
-
43
- Contributions to ABalytics are welcome.
abalytics-1.1.4/README.md DELETED
@@ -1,27 +0,0 @@
1
- # ABalytics: Advanced A/B Testing Statistical Analytics
2
-
3
- ABalytics is a Python package designed for statistical analysis, particularly for assessing the significance of A/B testing results. Its goal is to provide high-quality analysis by selecting the appropriate statistical tests based on the type of variable being analyzed. It offers a suite of tools to perform various significance tests and posthoc analyses on experimental data.
4
-
5
- ## Features
6
-
7
- - **Boolean and Numeric Analysis**: Supports analysis of both boolean and numeric data types, ensuring the use of correct statistical methods for each.
8
- - **Significance Tests**: Includes a variety of significance tests such as Chi-Square, Welch's ANOVA, and Kruskal-Wallis, to accurately determine the significance of results.
9
- - **Posthoc Analysis**: Offers posthoc analysis methods like Tukey's HSD, Dunn's test, and Games-Howell, for detailed examination following significance tests.
10
- - **Normality and Homogeneity Checks**: Performs checks for Gaussian distribution and homogeneity of variances using Levene's test, which are critical for selecting the right tests.
11
- - **Pretty Text Output**: Generates a formatted text output with the results of the statistical tests, facilitating interpretation and reporting.
12
-
13
- ## Installation
14
-
15
- To install ABalytics, use pip:
16
- ```pip install abalytics```
17
-
18
- ## Usage
19
-
20
- To use ABalytics, import it:
21
- ```import abalytics```
22
-
23
- An example of how to use ABalytics can be found in `examples/example.py`.
24
-
25
- ## Contributing
26
-
27
- Contributions to ABalytics are welcome.
@@ -1,43 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: abalytics
3
- Version: 1.1.4
4
- Summary: Advanced A/B Testing Statistical Analytics
5
- Author: Janis Berneker
6
- License: LICENSE
7
- Project-URL: Repository, https://github.com/BigBerny/abalytics
8
- Requires-Python: >=3.8
9
- Description-Content-Type: text/markdown
10
- License-File: LICENSE
11
- Requires-Dist: pandas>=1.5.2
12
- Requires-Dist: scipy>=1.10.1
13
- Requires-Dist: statsmodels>=0.14.1
14
- Requires-Dist: scikit-posthocs>=0.8.1
15
- Requires-Dist: pingouin>=0.5.4
16
-
17
- # ABalytics: Advanced A/B Testing Statistical Analytics
18
-
19
- ABalytics is a Python package designed for statistical analysis, particularly for assessing the significance of A/B testing results. Its goal is to provide high-quality analysis by selecting the appropriate statistical tests based on the type of variable being analyzed. It offers a suite of tools to perform various significance tests and posthoc analyses on experimental data.
20
-
21
- ## Features
22
-
23
- - **Boolean and Numeric Analysis**: Supports analysis of both boolean and numeric data types, ensuring the use of correct statistical methods for each.
24
- - **Significance Tests**: Includes a variety of significance tests such as Chi-Square, Welch's ANOVA, and Kruskal-Wallis, to accurately determine the significance of results.
25
- - **Posthoc Analysis**: Offers posthoc analysis methods like Tukey's HSD, Dunn's test, and Games-Howell, for detailed examination following significance tests.
26
- - **Normality and Homogeneity Checks**: Performs checks for Gaussian distribution and homogeneity of variances using Levene's test, which are critical for selecting the right tests.
27
- - **Pretty Text Output**: Generates a formatted text output with the results of the statistical tests, facilitating interpretation and reporting.
28
-
29
- ## Installation
30
-
31
- To install ABalytics, use pip:
32
- ```pip install abalytics```
33
-
34
- ## Usage
35
-
36
- To use ABalytics, import it:
37
- ```import abalytics```
38
-
39
- An example of how to use ABalytics can be found in `examples/example.py`.
40
-
41
- ## Contributing
42
-
43
- Contributions to ABalytics are welcome.
File without changes
File without changes
File without changes