AutoStatLib 0.2.12__py3-none-any.whl → 0.2.13__py3-none-any.whl

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.

Potentially problematic release.


This version of AutoStatLib might be problematic. Click here for more details.

@@ -2,6 +2,7 @@ from AutoStatLib.statistical_tests import StatisticalTests
2
2
  from AutoStatLib.normality_tests import NormalityTests
3
3
  from AutoStatLib.helpers import Helpers
4
4
  from AutoStatLib.text_formatting import TextFormatting
5
+ from AutoStatLib._version import __version__
5
6
 
6
7
 
7
8
  class StatisticalAnalysis(StatisticalTests, NormalityTests, TextFormatting, Helpers):
@@ -16,7 +17,7 @@ class StatisticalAnalysis(StatisticalTests, NormalityTests, TextFormatting, Help
16
17
  paired=False,
17
18
  tails=2,
18
19
  popmean=None,
19
- posthoc=True,
20
+ posthoc=False,
20
21
  verbose=True):
21
22
  self.results = None
22
23
  self.error = False
@@ -28,7 +29,7 @@ class StatisticalAnalysis(StatisticalTests, NormalityTests, TextFormatting, Help
28
29
  self.verbose = verbose
29
30
  self.n_groups = len(self.groups_list)
30
31
  self.warning_flag_non_numeric_data = False
31
- self.summary = ''
32
+ self.summary = 'AutoStatLib v{}'.format(__version__)
32
33
 
33
34
  # test IDs classification:
34
35
  self.test_ids_all = [ # in aplhabetical order
@@ -86,13 +87,13 @@ class StatisticalAnalysis(StatisticalTests, NormalityTests, TextFormatting, Help
86
87
  self.error = False
87
88
  self.warnings = []
88
89
  self.normals = []
89
- self.test_name = None
90
+ self.test_name = ''
90
91
  self.test_id = None
91
92
  self.test_stat = None
92
93
  self.p_value = None
93
94
  self.posthoc_matrix_df = None
94
95
  self.posthoc_matrix = []
95
- self.posthoc_name = None
96
+ self.posthoc_name = ''
96
97
 
97
98
  self.log('\n' + '-'*67)
98
99
  self.log('Statistical analysis initiated for data in {} groups\n'.format(
AutoStatLib/StatPlots.py CHANGED
@@ -74,28 +74,34 @@ class BaseStatPlot(Helpers):
74
74
 
75
75
  def __init__(self,
76
76
  data_groups,
77
- p=None,
78
- testname='',
79
- dependent=False,
77
+ p_value_exact=None,
78
+ Test_Name='',
79
+ Paired_Test_Applied=False,
80
80
  plot_title='',
81
81
  x_label='',
82
82
  y_label='',
83
83
  print_x_labels=True,
84
84
  x_manual_tick_labels=None,
85
- posthoc_matrix=[],
85
+ Posthoc_Matrix=[],
86
+ Posthoc_Tests_Name='',
86
87
  colormap=None,
88
+ print_p_label=True,
89
+ print_stars=True,
87
90
  **kwargs):
88
91
  self.data_groups = [group if group else [0, 0, 0, 0]
89
92
  for group in data_groups]
90
93
  self.n_groups = len(self.data_groups)
91
- self.p = p
92
- self.testname = testname
93
- self.posthoc_matrix = posthoc_matrix
94
+ self.p = p_value_exact
95
+ self.testname = Test_Name
96
+ self.posthoc_name = Posthoc_Tests_Name
97
+ self.posthoc_matrix = Posthoc_Matrix
94
98
  self.n_significance_bars = 1
95
- self.dependent = dependent
99
+ self.dependent = Paired_Test_Applied
96
100
  self.plot_title = plot_title
97
101
  self.x_label = x_label
98
102
  self.y_label = y_label
103
+ self.print_p_label = print_p_label
104
+ self.print_stars = print_stars
99
105
  self.print_x_labels = print_x_labels
100
106
 
101
107
  # sd sem mean and median calculation if they are not provided
@@ -396,9 +402,7 @@ class BaseStatPlot(Helpers):
396
402
  def add_significance_bars(self, ax,
397
403
  linewidth=2,
398
404
  capsize=0.01,
399
- col='k',
400
- label=''):
401
- '''label can be "p", "s", "both"'''
405
+ col='k'):
402
406
 
403
407
  # # Estimate how many bars needed
404
408
  # self.n_significance_bars = comb(
@@ -409,25 +413,28 @@ class BaseStatPlot(Helpers):
409
413
  posthoc_matrix_stars = [[self.make_stars_printed(self.make_stars(element)) for element in row]
410
414
  for row in self.posthoc_matrix] if self.posthoc_matrix else []
411
415
 
412
- def draw_bar(p, stars, order=0, x1=0, x2=self.n_groups-1, capsize=capsize, linewidth=linewidth, col=col, label=label):
413
- if label == 'p':
414
- vspace = capsize+0.03
415
- label = '{}'.format(p)
416
- elif label == 's':
417
- vspace = capsize+0.03
418
- label = '{}'.format(stars)
419
- else:
420
- vspace = capsize+0.06
421
- label = '{}\n{}'.format(p, stars)
422
-
423
- # Draw significance bar connecting x1 and x2 coords
424
- y, h = ((1.05 + (order*vspace)) *
425
- self.y_max), capsize * self.y_max
426
- ax.plot([x1, x1, x2, x2], [y, y + h, y + h, y],
427
- lw=linewidth, c=col)
428
-
429
- ax.text((x1 + x2) * 0.5, y + h, label,
430
- ha='center', va='bottom', color=col, fontweight='bold', fontsize=8)
416
+ def draw_bar(p, stars, order=0, x1=0, x2=self.n_groups-1, capsize=capsize, linewidth=linewidth, col=col):
417
+
418
+ match (self.print_p_label, self.print_stars):
419
+ case (True, True):
420
+ vspace = capsize+0.06
421
+ label = '{}\n{}'.format(p, stars)
422
+ case (True, False):
423
+ vspace = capsize+0.03
424
+ label = '{}'.format(p)
425
+ case (False, True):
426
+ vspace = capsize+0.03
427
+ label = '{}'.format(stars)
428
+
429
+ if self.print_p_label or self.print_stars:
430
+ # Draw significance bar connecting x1 and x2 coords
431
+ y, h = ((1.05 + (order*vspace)) *
432
+ self.y_max), capsize * self.y_max
433
+ ax.plot([x1, x1, x2, x2], [y, y + h, y + h, y],
434
+ lw=linewidth, c=col)
435
+
436
+ ax.text((x1 + x2) * 0.5, y + h, label,
437
+ ha='center', va='bottom', color=col, fontweight='bold', fontsize=8)
431
438
 
432
439
  def draw_bar_from_posthoc_matrix(x1, x2, o):
433
440
  draw_bar(
@@ -524,8 +531,8 @@ class BaseStatPlot(Helpers):
524
531
  if self.y_label:
525
532
  ax.set_ylabel(self.y_label, fontsize=10, fontweight='bold')
526
533
  fig.text(0.95, 0.0,
527
- '{}\nn={}'.format(self.testname,
528
- str(self.n)[1:-1] if not self.dependent else str(self.n[0])),
534
+ '{}, {}\nn={}'.format(self.testname, self.posthoc_name,
535
+ str(self.n)[1:-1] if not self.dependent else str(self.n[0])),
529
536
  ha='right', va='bottom', fontsize=8, fontweight='regular')
530
537
 
531
538
  def show(self):
AutoStatLib/_version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  # AutoStatLib package version:
2
- __version__ = "0.2.12"
2
+ __version__ = "0.2.13"
AutoStatLib/helpers.py CHANGED
@@ -41,7 +41,7 @@ class Helpers():
41
41
  self.stars_str = self.make_stars_printed(self.stars_int)
42
42
 
43
43
  return {
44
- 'p-value': self.make_p_value_printed(self.p_value.item()),
44
+ 'p_value': self.make_p_value_printed(self.p_value.item()),
45
45
  'Significance(p<0.05)': True if self.p_value.item() < 0.05 else False,
46
46
  'Stars_Printed': self.stars_str,
47
47
  'Test_Name': self.test_name,
@@ -51,7 +51,7 @@ class Helpers():
51
51
  'Parametric_Test_Applied': True if self.test_id in self.test_ids_parametric else False,
52
52
  'Paired_Test_Applied': self.paired,
53
53
  'Tails': self.tails,
54
- 'p-value_exact': self.p_value.item(),
54
+ 'p_value_exact': self.p_value.item(),
55
55
  'Stars': self.stars_int,
56
56
  # 'Stat_Value': self.test_stat.item(),
57
57
  'Warnings': self.warnings,
@@ -1,7 +1,9 @@
1
1
  import numpy as np
2
+ import itertools
2
3
  import scikit_posthocs as sp
3
4
  from statsmodels.stats.anova import AnovaRM
4
5
  from statsmodels.stats.multicomp import pairwise_tukeyhsd
6
+ from statsmodels.stats.multitest import multipletests
5
7
  from scipy.stats import ttest_rel, ttest_ind, ttest_1samp, wilcoxon, mannwhitneyu, f_oneway, kruskal, friedmanchisquare
6
8
 
7
9
 
@@ -90,14 +92,19 @@ class StatisticalTests():
90
92
  # if self.tails == 1:
91
93
  # p_value /= 2
92
94
 
93
- # if p_value < 0.05 and self.posthoc:
94
- # data_flat = np.concatenate(self.data)
95
- # self.posthoc_name = 'Tukey`s multiple comparisons'
96
- # group_labels = np.concatenate(
97
- # [[f"Group_{i+1}"] * len(group) for i, group in enumerate(self.data)])
98
- # # Tukey's multiple comparisons
99
- # tukey_result = pairwise_tukeyhsd(data_flat, group_labels)
100
- # print(tukey_result)
95
+ if self.posthoc: # and p_value < 0.05:
96
+ data_flat = np.concatenate(self.data)
97
+ self.posthoc_name = 'Tukey`s posthoc'
98
+ group_labels = np.concatenate(
99
+ [[f"Group_{i+1}"] * len(group) for i, group in enumerate(self.data)])
100
+ # Tukey's multiple comparisons
101
+ tukey_result = pairwise_tukeyhsd(data_flat, group_labels)
102
+ p = tukey_result.pvalues.tolist()
103
+ self.posthoc_matrix = [
104
+ [p[2], p[0], p[1]],
105
+ [p[0], p[2], p[2]],
106
+ [p[1], p[2], p[2]],
107
+ ]
101
108
  return stat, p_value
102
109
 
103
110
  def anova_1w_rm(self):
@@ -110,8 +117,25 @@ class StatisticalTests():
110
117
 
111
118
  df = self.matrix_to_dataframe(self.data)
112
119
  res = AnovaRM(df, 'Value', 'Row', within=['Col']).fit()
113
- stat = res.anova_table['F Value'][0]
114
- p_value = res.anova_table['Pr > F'][0]
120
+ print(res)
121
+ stat = res.anova_table.iloc[0][0]
122
+ p_value = res.anova_table.iloc[0][3]
123
+
124
+ # # --- Posthocs: paired t-tests ---
125
+ # wide = df.pivot(index='Row', columns='Col', values='Value')
126
+ # conds = wide.columns
127
+ # pairs = list(itertools.combinations(conds, 2))
128
+
129
+ # pvals, stats = [], []
130
+ # for a, b in pairs:
131
+ # t, p = ttest_rel(wide[a], wide[b])
132
+ # stats.append(t)
133
+ # pvals.append(p)
134
+
135
+ # # Adjust p-values
136
+ # rej, p_corr, _, _ = multipletests(pvals, method='bonferroni')
137
+
138
+ # print(p_corr)
115
139
 
116
140
  self.tails = 2
117
141
  return stat, p_value
@@ -125,10 +149,11 @@ class StatisticalTests():
125
149
  stat, p_value = kruskal(*self.data)
126
150
 
127
151
  # Perform Dunn's multiple comparisons if Kruskal-Wallis is significant
128
- if p_value < 0.05 and self.posthoc:
152
+ if self.posthoc: # and p_value < 0.05:
129
153
  self.posthoc_matrix = sp.posthoc_dunn(
130
154
  self.data, p_adjust='bonferroni').values.tolist()
131
- self.posthoc_name = 'Dunn`s multiple comparisons'
155
+ self.posthoc_name = 'Dunn`s posthoc'
156
+ self.tails = 2
132
157
  return stat, p_value
133
158
 
134
159
  def mann_whitney(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AutoStatLib
3
- Version: 0.2.12
3
+ Version: 0.2.13
4
4
  Summary: AutoStatLib - a simple statistical analysis tool
5
5
  Author: Stemonitis, SciWare LLC
6
6
  Author-email: konung-yaropolk <yaropolk1995@gmail.com>
@@ -537,7 +537,7 @@ Requires-Dist: scikit-posthocs
537
537
  Requires-Dist: pandas
538
538
  Dynamic: license-file
539
539
 
540
- # AutoStatLib - python library for automated statistical analysis
540
+ # AutoStatLib - python library for automated statistical analysis
541
541
 
542
542
  [![pypi_version](https://img.shields.io/pypi/v/AutoStatLib?label=PyPI&color=green)](https://pypi.org/project/AutoStatLib)
543
543
  [![GitHub Release](https://img.shields.io/github/v/release/konung-yaropolk/AutoStatLib?label=GitHub&color=green&link=https%3A%2F%2Fgithub.com%2Fkonung-yaropolk%2FAutoStatLib)](https://github.com/konung-yaropolk/AutoStatLib)
@@ -545,17 +545,16 @@ Dynamic: license-file
545
545
  [![Python](https://img.shields.io/badge/Python-v3.10%5E-green?logo=python)](https://pypi.org/project/AutoStatLib)
546
546
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/AutoStatLib?label=PyPI%20stats&color=blue)](https://pypi.org/project/AutoStatLib)
547
547
 
548
-
549
548
  ### To install run the command:
549
+
550
550
  ```bash
551
551
  pip install autostatlib
552
552
  ```
553
553
 
554
-
555
554
  ### Example use case:
556
- See the /demo directory on Git repo or
557
- use the following example:
558
555
 
556
+ See the /demo directory on Git repo or
557
+ use the following example:
559
558
 
560
559
  ```python
561
560
  import numpy as np
@@ -584,11 +583,13 @@ analysis = AutoStatLib.StatisticalAnalysis(
584
583
  ```
585
584
 
586
585
  now you can preform automated statistical test selection:
586
+
587
587
  ```python
588
588
  analysis.RunAuto()
589
589
  ```
590
590
 
591
591
  or you can choose specific tests:
592
+
592
593
  ```python
593
594
  # 2 groups independent:
594
595
  analysis.RunTtest()
@@ -615,15 +616,18 @@ Test summary will be printed to the console.
615
616
  You can also get it as a python string via *GetSummary()* method.
616
617
 
617
618
  ---
619
+
618
620
  Test results are accessible as a dictionary via *GetResult()* method:
621
+
619
622
  ```python
620
623
  results = analysis.GetResult()
621
624
  ```
622
625
 
623
626
  The results dictionary keys with representing value types:
627
+
624
628
  ```
625
629
  {
626
- 'p-value' : String
630
+ 'p_value' : String
627
631
  'Significance(p<0.05)' : Boolean
628
632
  'Stars_Printed' : String
629
633
  'Test_Name' : String
@@ -633,7 +637,7 @@ The results dictionary keys with representing value types:
633
637
  'Parametric_Test_Applied' : Boolean
634
638
  'Paired_Test_Applied' : Boolean
635
639
  'Tails' : Integer (taken from the input)
636
- 'p-value_exact' : Float
640
+ 'p_value_exact' : Float
637
641
  'Stars' : Integer
638
642
  'Warnings' : String
639
643
  'Groups_N' : List of integers
@@ -649,50 +653,44 @@ The results dictionary keys with representing value types:
649
653
  'Posthoc_Matrix_stars': 2D List of String
650
654
  }
651
655
  ```
652
- If errors occured, *GetResult()* returns an empty dictionary
653
-
654
656
 
657
+ If errors occured, *GetResult()* returns an empty dictionary
655
658
 
659
+ ---
656
660
 
661
+ ## Pre-Alpha dev status.
657
662
 
663
+ ### TODO:
658
664
 
659
- ---
660
- ## Pre-Alpha dev status.
661
-
662
- ### TODO:
663
-
664
- -- Anova: posthocs
665
- -- Anova: add 2-way anova and 3-way anova
666
- -- onevay Anova: add repeated measures (for normal dependent values) with and without Gaisser-Greenhouse correction
667
- -- onevay Anova: add Brown-Forsithe and Welch (for normal independent values with unequal SDs between groups)
668
- -- paired T-test: add ratio-paired t-test (ratios of paired values are consistent)
665
+ -- Anova: posthocs
666
+ -- Anova: add 2-way anova and 3-way anova
667
+ -- onevay Anova: add repeated measures (for normal dependent values) with and without Gaisser-Greenhouse correction
668
+ -- onevay Anova: add Brown-Forsithe and Welch (for normal independent values with unequal SDs between groups)
669
+ -- paired T-test: add ratio-paired t-test (ratios of paired values are consistent)
669
670
  -- add Welch test (for norm data unequal variances)
670
- -- add Kolmogorov-smirnov test (unpaired nonparametric 2 sample, compare cumulative distributions)
671
- -- add independent t-test with Welch correction (do not assume equal SDs in groups)
672
- -- add correlation test, correlation diagram
673
- -- add linear regression, regression diagram
671
+ -- add Kolmogorov-smirnov test (unpaired nonparametric 2 sample, compare cumulative distributions)
672
+ -- add independent t-test with Welch correction (do not assume equal SDs in groups)
673
+ -- add correlation test, correlation diagram
674
+ -- add linear regression, regression diagram
674
675
  -- add QQ plot
675
676
  -- n-sample tests: add onetail option
676
-
677
- ✅ done -- detailed normality test results
678
- ✅ done -- added posthoc: Kruskal-Wallis Dunn's multiple comparisons
679
-
680
-
681
- tests check:
682
- 1-sample:
683
- --Wilcoxon 2,1 tails - ok
684
- --t-tests 2,1 tails -ok
685
-
686
- 2-sample:
687
- --Wilcoxon 2,1 tails - ok
688
- --Mann-whitney 2,1 tails - ok
689
- --t-tests 2,1 tails -ok
690
-
691
- n-sample:
692
- --Kruskal-Wallis 2 tail - ok
693
- --Dunn's multiple comparisons - ??
694
- --Friedman 2 tail - ok
695
- --one-way ANOWA 2 tail - ok
696
-
697
-
698
677
 
678
+ ✅ done -- detailed normality test results
679
+ ✅ done -- added posthoc: Kruskal-Wallis Dunn's multiple comparisons
680
+
681
+ tests check:
682
+ 1-sample:
683
+ --Wilcoxon 2,1 tails - ✅ok
684
+ --t-tests 2,1 tails -✅ok
685
+
686
+ 2-sample:
687
+ --Wilcoxon 2,1 tails - ✅ok
688
+ --Mann-whitney 2,1 tails - ✅ok
689
+ --t-tests 2,1 tails -✅ok
690
+
691
+ n-sample:
692
+ --Kruskal-Wallis 2 tail - ✅ok
693
+ --Dunn's multiple comparisons - ✅ok
694
+ --Friedman 2 tail - ✅ok
695
+ --one-way ANOWA 2 tail - ✅ok
696
+ --Tukey`s multiple comparisons - ✅ok
@@ -0,0 +1,14 @@
1
+ AutoStatLib/AutoStatLib.py,sha256=5kiJInUvaa3kB8YfWEeWSpHyUZiHPlDU0fbvxeLdzRM,9750
2
+ AutoStatLib/StatPlots.py,sha256=YOfacQM7HKs4istcVJzt1FUrjXzSl_Ebk01iaR-AcFc,24340
3
+ AutoStatLib/__init__.py,sha256=r7VdcL7F4UCRxEFh8WFBd9y61KavX_qt7fFbKjtjfjo,137
4
+ AutoStatLib/__main__.py,sha256=0OIv5sqFNI-diyHFtYL6HPcYrOWdLiqYYOO_nxrHuTk,283
5
+ AutoStatLib/_version.py,sha256=O3YpbOpmXJZMCHlKDn67yUpAqB2IkWeieWNU_JA526g,54
6
+ AutoStatLib/helpers.py,sha256=Bxe9TkFe5Rtg_F5tBbZKgnbJ0dKDKgsAHq91-o7Nfj4,3646
7
+ AutoStatLib/normality_tests.py,sha256=TYeKpfpJRzOHvDZucObuZhPktjiZpSZwh381eJ8ENC4,2381
8
+ AutoStatLib/statistical_tests.py,sha256=OYU4_PqHBxXv8RyodNqu2YIMn6T-SXKtBrI4tc9LqOA,7313
9
+ AutoStatLib/text_formatting.py,sha256=rWDsrlZdquook7lUg8t2mb3az8nR12BDprxfy_NwE2o,3576
10
+ autostatlib-0.2.13.dist-info/licenses/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
11
+ autostatlib-0.2.13.dist-info/METADATA,sha256=xlfCX8VWNHQPxTDcy3959pDPUFxf7zZhyqqLQIxYxT8,36920
12
+ autostatlib-0.2.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ autostatlib-0.2.13.dist-info/top_level.txt,sha256=BuHzVyE2andc7RwD_UPmDjLl9CUAyBH6WHZGjaIReUI,12
14
+ autostatlib-0.2.13.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- AutoStatLib/AutoStatLib.py,sha256=06kmj2v2lANxYmgKHxPjAeQo1O0JOsMPY5RIwivE6zU,9673
2
- AutoStatLib/StatPlots.py,sha256=OreCVScPiq2vWGJl5THnH8l2bXTjJC_BWFwXu2GQeRE,23928
3
- AutoStatLib/__init__.py,sha256=r7VdcL7F4UCRxEFh8WFBd9y61KavX_qt7fFbKjtjfjo,137
4
- AutoStatLib/__main__.py,sha256=0OIv5sqFNI-diyHFtYL6HPcYrOWdLiqYYOO_nxrHuTk,283
5
- AutoStatLib/_version.py,sha256=ojZL1T-rA9chDRCrw8Goa-X_WQ6SOxgKkHMoQgnz04Q,54
6
- AutoStatLib/helpers.py,sha256=d8P6_q706rjuc6N4WBbdOqNQFuAIjCHfmrhgJABFxqE,3646
7
- AutoStatLib/normality_tests.py,sha256=TYeKpfpJRzOHvDZucObuZhPktjiZpSZwh381eJ8ENC4,2381
8
- AutoStatLib/statistical_tests.py,sha256=xfHdTtN5Es_qoVMUwX8VFsl-FLpF3zd56S9ya7dPXVo,6566
9
- AutoStatLib/text_formatting.py,sha256=rWDsrlZdquook7lUg8t2mb3az8nR12BDprxfy_NwE2o,3576
10
- autostatlib-0.2.12.dist-info/licenses/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
11
- autostatlib-0.2.12.dist-info/METADATA,sha256=PkYfW6cbvMlShm65pOAYUuuUzohmVlHNP0zsQ8y_bxw,36921
12
- autostatlib-0.2.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- autostatlib-0.2.12.dist-info/top_level.txt,sha256=BuHzVyE2andc7RwD_UPmDjLl9CUAyBH6WHZGjaIReUI,12
14
- autostatlib-0.2.12.dist-info/RECORD,,