Skip to content

Commit 07ff91b

Browse files
committed
tests added & bugs fixed
1 parent 7617dfe commit 07ff91b

13 files changed

Lines changed: 79 additions & 31 deletions

dabest/_classes.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ def __init__(self, control, test, effect_size,
922922
self.__random_seed = random_seed
923923
self.__ci = ci
924924
self.__alpha = ci2g._compute_alpha_from_ci(ci)
925-
self.__delta2 = delta2
925+
self.__delta2 = delta2
926926

927927
self.__difference = es.two_group_difference(
928928
control, test, is_paired, effect_size)
@@ -1187,7 +1187,9 @@ def __repr__(self, show_resample_count=True, define_pval=True, sigfig=3):
11871187
# pval_rounded)
11881188

11891189

1190-
pvalue = "The p-value of the two-sided permutation t-test is {}. ".format(pval_rounded)
1190+
p1 = "The p-value of the two-sided permutation t-test is {}, ".format(pval_rounded)
1191+
p2 = "calculated for legacy purposes only. "
1192+
pvalue = p1 + p2
11911193

11921194
bs1 = "{} bootstrap samples were taken; ".format(self.__resamples)
11931195
bs2 = "the confidence interval is bias-corrected and accelerated."
@@ -1224,6 +1226,9 @@ def to_dict(self):
12241226
return out
12251227

12261228

1229+
@property
1230+
def delta2(self):
1231+
return self.__delta2
12271232

12281233

12291234
@property
@@ -1590,7 +1595,6 @@ def __pre_calc(self):
15901595
self.__permutation_count,
15911596
self.__random_seed)
15921597
r_dict = result.to_dict()
1593-
15941598
r_dict["control"] = cname
15951599
r_dict["test"] = tname
15961600
r_dict["control_N"] = int(len(control))
@@ -1606,7 +1610,7 @@ def __pre_calc(self):
16061610
else:
16071611
resamp_count = False
16081612
def_pval = False
1609-
1613+
16101614
text_repr = result.__repr__(show_resample_count=resamp_count,
16111615
define_pval=def_pval)
16121616

@@ -1710,6 +1714,7 @@ def __calc_lqrt(self):
17101714
dat = db_obj._plot_data
17111715
xvar = db_obj._xvar
17121716
yvar = db_obj._yvar
1717+
delta2 = self.__delta2
17131718

17141719

17151720
out = []
@@ -1757,7 +1762,18 @@ def __calc_lqrt(self):
17571762
"pvalue_lqrt_unequal_var" : lqrt_unequal_var_result.pvalue,
17581763
"statistic_lqrt_unequal_var" : lqrt_unequal_var_result.statistic,
17591764
})
1760-
1765+
if delta2:
1766+
lqrt_result = lqrt.lqrtest_rel(self.results["bootstraps"][0],
1767+
self.results["bootstraps"][1],
1768+
random_state=rnd_seed)
1769+
1770+
out.append({"control": self.__experiment_label[0],
1771+
"test": self.__experiment_label[1],
1772+
"control_N": self.__resamples,
1773+
"test_N": self.__resamples,
1774+
"pvalue_paired_lqrt": lqrt_result.pvalue,
1775+
"statistic_paired_lqrt": lqrt_result.statistic
1776+
})
17611777
self.__lqrt_results = pd.DataFrame(out)
17621778

17631779

@@ -1766,7 +1782,7 @@ def plot(self, color_col=None,
17661782
raw_marker_size=6, es_marker_size=9,
17671783

17681784
swarm_label=None, barchart_label=None, contrast_label=None, delta_label=None,
1769-
swarm_ylim=None, barchart_ylim=None, contrast_ylim=None, delta_ylim=None,
1785+
swarm_ylim=None, barchart_ylim=None, contrast_ylim=None,
17701786

17711787
custom_palette=None, swarm_desat=0.5, barchart_desat=0.5, halfviolin_desat=1,
17721788
halfviolin_alpha=0.8,
@@ -1809,7 +1825,7 @@ def plot(self, color_col=None,
18091825
`contrast_label` is not specified, it defaults to the effect size
18101826
being plotted. If `delta_label` is not specifed, it defaults to
18111827
"delta - delta"
1812-
swarm_ylim, contrast_ylim, delta_ylim : tuples, default None
1828+
swarm_ylim, contrast_ylim : tuples, default None
18131829
The desired y-limits of the raw data (swarmplot) axes, the
18141830
difference axes and the delta-delta axes respectively, as a tuple. These will be autoscaled
18151831
to sensible values if they are not specified.

dabest/plotter.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
1515
color_col=None
1616
raw_marker_size=6, es_marker_size=9,
1717
swarm_label=None, contrast_label=None, delta_label=None,
18-
swarm_ylim=None, contrast_ylim=None, delta_ylim=None,
18+
swarm_ylim=None, contrast_ylim=None,
1919
custom_palette=None, swarm_desat=0.5, halfviolin_desat=1,
2020
halfviolin_alpha=0.8,
2121
float_contrast=True,
@@ -781,30 +781,15 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
781781
if delta2:
782782
delta_axes.axhline(y=0, xmin = 0.25, xmax = 1.5, **reflines_kwargs)
783783

784-
785-
if delta2 and plot_kwargs['delta_ylim'] is not None:
786-
custom_delta_ylim = plot_kwargs['delta_ylim']
787-
788-
if len(custom_delta_ylim) != 2:
789-
err1 = "Please check `delta_ylim` consists of "
790-
err2 = "exactly two numbers."
791-
raise ValueError(err1 + err2)
792-
793-
if effect_size_type == "cliffs_delta":
794-
# Ensure the ylims for a cliffs_delta plot never exceed [-1, 1].
795-
l = plot_kwargs['delta_ylim'][0]
796-
h = plot_kwargs['delta_ylim'][1]
797-
low = -1 if l < -1 else l
798-
high = 1 if h > 1 else h
799-
delta_axes.set_ylim(low, high)
784+
if delta2:
785+
if plot_kwargs['contrast_ylim'] is None:
786+
ylim_contrast = contrast_axes.get_ylim()
787+
ylim_delta = delta_axes.get_ylim()
788+
ylim=(min(ylim_contrast[0], ylim_delta[0]), max(ylim_contrast[1], ylim_delta[1]))
789+
contrast_axes.set_ylim(ylim)
790+
delta_axes.set_ylim(ylim)
800791
else:
801-
delta_axes.set_ylim(custom_delta_ylim)
802-
if delta2 and plot_kwargs['delta_ylim'] is None and plot_kwargs['contrast_ylim'] is None:
803-
ylim_contrast = contrast_axes.get_ylim()
804-
ylim_delta = delta_axes.get_ylim()
805-
ylim=(min(ylim_contrast[0], ylim_delta[0]), max(ylim_contrast[1], ylim_delta[1]))
806-
contrast_axes.set_ylim(ylim)
807-
delta_axes.set_ylim(ylim)
792+
delta_axes.set_ylim(contrast_axes.get_ylim())
808793

809794
if is_paired == "baseline" and show_pairs == True:
810795
rightend_ticks_raw = np.array([len(i)-1 for i in temp_idx]) + np.array(ticks_to_skip)
52.3 KB
Loading
37.8 KB
Loading
37.8 KB
Loading
39.7 KB
Loading
37.9 KB
Loading
26.6 KB
Loading
37.8 KB
Loading
39.3 KB
Loading

0 commit comments

Comments
 (0)