py2ls 0.1.9.2__py3-none-any.whl → 0.1.9.3__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.
py2ls/plot.py
CHANGED
@@ -467,6 +467,9 @@ def catplot(data, *args, **kwargs):
|
|
467
467
|
# custom_order = ['s', 'bx', 'e']
|
468
468
|
# full_order = sort_catplot_layers(custom_order)
|
469
469
|
|
470
|
+
ax = kwargs.get("ax", None)
|
471
|
+
if "ax" not in locals() or ax is None:
|
472
|
+
ax = plt.gca()
|
470
473
|
col = kwargs.get("col", None)
|
471
474
|
if not col:
|
472
475
|
# figsets
|
@@ -496,8 +499,9 @@ def catplot(data, *args, **kwargs):
|
|
496
499
|
# ! stats info
|
497
500
|
stats_param = kwargs.get("stats", False)
|
498
501
|
res = pd.DataFrame() # Initialize an empty DataFrame to store results
|
502
|
+
ihue = 1
|
499
503
|
for i in df[x].unique().tolist():
|
500
|
-
print(i)
|
504
|
+
print(i) # to indicate which 'x'
|
501
505
|
if hue and stats_param:
|
502
506
|
if isinstance(stats_param, dict):
|
503
507
|
if "factor" in stats_param.keys():
|
@@ -511,11 +515,18 @@ def catplot(data, *args, **kwargs):
|
|
511
515
|
else:
|
512
516
|
res_tmp = "did not work properly"
|
513
517
|
display_output(res_tmp)
|
514
|
-
|
518
|
+
xloc_curr = hue_len * (ihue - 1)
|
519
|
+
# add_asterisks(ax,res_tmp,xticks[xloc_curr:xloc_curr+hue_len],legend_hue)
|
520
|
+
# res_tmp = [{"x": i, **res_tmp}]
|
521
|
+
# print("here")
|
522
|
+
# df_=pd.DataFrame([res_tmp])
|
523
|
+
# display(df_['pval'][0].tolist()[0])
|
515
524
|
res = pd.concat(
|
516
525
|
[res, pd.DataFrame([res_tmp])], ignore_index=True
|
517
526
|
)
|
527
|
+
ihue += 1
|
518
528
|
display_output(res)
|
529
|
+
|
519
530
|
else:
|
520
531
|
# ! stats info
|
521
532
|
stats_param = kwargs.get("stats", False)
|
@@ -580,9 +591,7 @@ def catplot(data, *args, **kwargs):
|
|
580
591
|
opt.update(style_load)
|
581
592
|
except:
|
582
593
|
print(f"cannot find the style'{style_name}'")
|
583
|
-
|
584
|
-
if "ax" not in locals() or ax is None:
|
585
|
-
ax = plt.gca()
|
594
|
+
|
586
595
|
opt.setdefault("c", default_colors)
|
587
596
|
# if len(opt["c"]) < data.shape[1]:
|
588
597
|
# additional_colors = plt.cm.winter(
|
@@ -771,6 +780,34 @@ def catplot(data, *args, **kwargs):
|
|
771
780
|
if show_legend:
|
772
781
|
ax.legend()
|
773
782
|
|
783
|
+
# ! add asterisks in the plot
|
784
|
+
if stats_param:
|
785
|
+
if hue is None:
|
786
|
+
display(res)
|
787
|
+
add_asterisks(ax, res, xticks_x_loc, xticklabels)
|
788
|
+
else: # hue is not None
|
789
|
+
ihue = 1
|
790
|
+
for i in df[x].unique().tolist():
|
791
|
+
if hue and stats_param:
|
792
|
+
if isinstance(stats_param, dict):
|
793
|
+
if "factor" in stats_param.keys():
|
794
|
+
res_tmp = FuncMultiCmpt(data=df, dv=y, **stats_param)
|
795
|
+
else:
|
796
|
+
res_tmp = FuncMultiCmpt(
|
797
|
+
data=df[df[x] == i], dv=y, factor=hue, **stats_param
|
798
|
+
)
|
799
|
+
elif bool(stats_param):
|
800
|
+
res_tmp = FuncMultiCmpt(data=df, dv=y, factor=hue)
|
801
|
+
else:
|
802
|
+
res_tmp = "did not work properly"
|
803
|
+
xloc_curr = hue_len * (ihue - 1)
|
804
|
+
add_asterisks(
|
805
|
+
ax,
|
806
|
+
res_tmp,
|
807
|
+
xticks[xloc_curr : xloc_curr + hue_len],
|
808
|
+
legend_hue,
|
809
|
+
)
|
810
|
+
ihue += 1
|
774
811
|
style_export = kwargs.get("style_export", None)
|
775
812
|
if style_export and (style_export != style_use):
|
776
813
|
dir_curr_script = os.path.dirname(os.path.abspath(__file__))
|
@@ -1620,3 +1657,33 @@ def remove_colors_in_dict(
|
|
1620
1657
|
if "loc" in data:
|
1621
1658
|
del data["loc"]
|
1622
1659
|
return data
|
1660
|
+
|
1661
|
+
|
1662
|
+
def add_asterisks(ax, res, xticks_x_loc, xticklabels, **kwargs_funcstars):
|
1663
|
+
pval_groups = res["res_tab"]["PR(>F)"].tolist()[0]
|
1664
|
+
# print(f"p=:{pval_groups}")
|
1665
|
+
# print(f"xticks:{xticks}")
|
1666
|
+
# print(f"xticks_x_loc:{xticks_x_loc}")
|
1667
|
+
if pval_groups <= 0.05:
|
1668
|
+
A_list = res["res_posthoc"]["A"].tolist()
|
1669
|
+
B_list = res["res_posthoc"]["B"].tolist()
|
1670
|
+
xticklabels_array = np.array(xticklabels)
|
1671
|
+
yscal_ = 0.99
|
1672
|
+
for A, B, P in zip(
|
1673
|
+
res["res_posthoc"]["A"].tolist(),
|
1674
|
+
res["res_posthoc"]["B"].tolist(),
|
1675
|
+
res["res_posthoc"]["p-unc"].tolist(),
|
1676
|
+
):
|
1677
|
+
index_A = np.where(xticklabels_array == A)[0][0]
|
1678
|
+
index_B = np.where(xticklabels_array == B)[0][0]
|
1679
|
+
print(index_A, A, index_B, B, P)
|
1680
|
+
FuncStars(
|
1681
|
+
ax=ax,
|
1682
|
+
x1=xticks_x_loc[index_A],
|
1683
|
+
x2=xticks_x_loc[index_B],
|
1684
|
+
pval=P,
|
1685
|
+
yscale=yscal_,
|
1686
|
+
**kwargs_funcstars,
|
1687
|
+
)
|
1688
|
+
if P <= 0.05:
|
1689
|
+
yscal_ -= 0.1
|
py2ls/stats.py
CHANGED
@@ -18,6 +18,7 @@ def FuncStars(
|
|
18
18
|
xlim=None,
|
19
19
|
symbol="*",
|
20
20
|
yscale=0.95,
|
21
|
+
y_loc=None,
|
21
22
|
x1=0,
|
22
23
|
x2=1,
|
23
24
|
alpha=0.05,
|
@@ -48,7 +49,8 @@ def FuncStars(
|
|
48
49
|
if report_scale > 0:
|
49
50
|
report_scale = -np.abs(report_scale)
|
50
51
|
yscale = np.float64(yscale)
|
51
|
-
y_loc
|
52
|
+
if y_loc is None:
|
53
|
+
y_loc = np.min(ylim) + yscale * (np.max(ylim) - np.min(ylim))
|
52
54
|
xcenter = np.mean([x1, x2])
|
53
55
|
# ns / *
|
54
56
|
if alpha < pval:
|
@@ -101,11 +103,9 @@ def FuncStars(
|
|
101
103
|
color=symbolcolor,
|
102
104
|
)
|
103
105
|
# lines indicators
|
104
|
-
if linego
|
105
|
-
print(pval)
|
106
|
-
print(linego)
|
106
|
+
if linego and 0 < pval <= 0.05:
|
107
107
|
# horizontal line
|
108
|
-
if yscale
|
108
|
+
if yscale <= 0.99:
|
109
109
|
plt.plot(
|
110
110
|
[x1 + np.abs(np.diff(xlim)) * 0.01, x2 - np.abs(np.diff(xlim)) * 0.01],
|
111
111
|
[
|
@@ -211,45 +211,45 @@ def FuncCmpt(x1, x2, pmc="auto", pair="unpaired", verbose=True):
|
|
211
211
|
|
212
212
|
# pmc correction: 'parametric'/'non-parametric'/'auto'
|
213
213
|
# meawhile get the opposite setting (to compare the results)
|
214
|
-
def corr_pmc(pmc):
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
def corr_pair(pair):
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
def check_normality(data, verbose=True):
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
214
|
+
# def corr_pmc(pmc):
|
215
|
+
# cfg_pmc = None
|
216
|
+
# if pmc.lower() in {"pmc", "parametric"} and pmc.lower() not in {
|
217
|
+
# "npmc",
|
218
|
+
# "nonparametric",
|
219
|
+
# "non-parametric",
|
220
|
+
# }:
|
221
|
+
# cfg_pmc = "parametric"
|
222
|
+
# elif pmc.lower() in {
|
223
|
+
# "npmc",
|
224
|
+
# "nonparametric",
|
225
|
+
# "non-parametric",
|
226
|
+
# } and pmc.lower() not in {"pmc", "parametric"}:
|
227
|
+
# cfg_pmc = "non-parametric"
|
228
|
+
# else:
|
229
|
+
# cfg_pmc = "auto"
|
230
|
+
# return cfg_pmc
|
231
|
+
|
232
|
+
# def corr_pair(pair):
|
233
|
+
# cfg_pair = None
|
234
|
+
# if "pa" in pair.lower() and "np" not in pair.lower():
|
235
|
+
# cfg_pair = "paired"
|
236
|
+
# elif "np" in pair.lower():
|
237
|
+
# cfg_pair = "unpaired"
|
238
|
+
# return cfg_pair
|
239
|
+
|
240
|
+
# def check_normality(data, verbose=True):
|
241
|
+
# stat_shapiro, pval_shapiro = stats.shapiro(data)
|
242
|
+
# if pval_shapiro > 0.05:
|
243
|
+
# Normality = True
|
244
|
+
# else:
|
245
|
+
# Normality = False
|
246
|
+
# if verbose:
|
247
|
+
# (
|
248
|
+
# print(f"\n normally distributed\n")
|
249
|
+
# if Normality
|
250
|
+
# else print(f"\n NOT normally distributed\n")
|
251
|
+
# )
|
252
|
+
# return Normality
|
253
253
|
|
254
254
|
def sub_cmpt_2group(x1, x2, cfg_pmc="pmc", pair="unpaired", verbose=True):
|
255
255
|
output = {}
|
@@ -261,7 +261,7 @@ def FuncCmpt(x1, x2, pmc="auto", pair="unpaired", verbose=True):
|
|
261
261
|
x1, x2, center="median", proportiontocut=0.05
|
262
262
|
)
|
263
263
|
VarType = True if pval_lev > 0.05 and nX1 == nX2 else False
|
264
|
-
|
264
|
+
print(pair)
|
265
265
|
if "np" in pair: # 'unpaired'
|
266
266
|
if VarType and Normality:
|
267
267
|
# The independent t-test requires that the dependent variable is approximately normally
|
@@ -647,17 +647,18 @@ def corr_pair(pair):
|
|
647
647
|
return cfg_pair
|
648
648
|
|
649
649
|
|
650
|
-
def check_normality(data):
|
650
|
+
def check_normality(data, verbose=True):
|
651
651
|
stat_shapiro, pval_shapiro = stats.shapiro(data)
|
652
652
|
if pval_shapiro > 0.05:
|
653
653
|
Normality = True
|
654
654
|
else:
|
655
655
|
Normality = False
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
656
|
+
if verbose:
|
657
|
+
(
|
658
|
+
print(f"\n normally distributed\n")
|
659
|
+
if Normality
|
660
|
+
else print(f"\n NOT normally distributed\n")
|
661
|
+
)
|
661
662
|
return Normality
|
662
663
|
|
663
664
|
|
@@ -142,12 +142,12 @@ py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,
|
|
142
142
|
py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
|
143
143
|
py2ls/ips.py,sha256=N7MdOCgJXDQu73YkJQTtDN3RSntzXX7V0MOJ1NYBLEk,100572
|
144
144
|
py2ls/netfinder.py,sha256=OMStrwMAASf1ajlyEfseoaEygo7G5WKBAFRE0LY15Lw,49477
|
145
|
-
py2ls/plot.py,sha256=
|
145
|
+
py2ls/plot.py,sha256=Z8Sd9sjOJrdYW84CLmVDactHSQY_9qJ0Dje3hKMybC4,66229
|
146
146
|
py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
|
147
147
|
py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
|
148
|
-
py2ls/stats.py,sha256=
|
148
|
+
py2ls/stats.py,sha256=sR0exykzzT_NXkQr7YIazKhJg6AKmLS0N6jtzy07Lm0,47366
|
149
149
|
py2ls/translator.py,sha256=bc5FB-wqC4TtQz9gyCP1mE38HqNRJ_pmuRIgKnAlMzM,30581
|
150
150
|
py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
|
151
|
-
py2ls-0.1.9.
|
152
|
-
py2ls-0.1.9.
|
153
|
-
py2ls-0.1.9.
|
151
|
+
py2ls-0.1.9.3.dist-info/METADATA,sha256=YkiP0cRJZqlWq9frWtnKdXQTePQy98rr7tqy3Gd706Y,20017
|
152
|
+
py2ls-0.1.9.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
153
|
+
py2ls-0.1.9.3.dist-info/RECORD,,
|
File without changes
|