Skip to content

Commit c34638f

Browse files
committed
Merge branch 'sankey'
2 parents 2f6b5b2 + d322ba1 commit c34638f

4 files changed

Lines changed: 55 additions & 37 deletions

File tree

dabest/_bootstrap_tools.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class bootstrap:
1717
the two groups (x2-x1) is computed.
1818
NaNs are automatically discarded.
1919
20-
paired: boolean, default False
21-
Whether or not x1 and x2 are paired samples.
20+
paired : string, default None
21+
The type of the experiment under which the data are obtained
2222
2323
statfunction: callable, default np.mean
2424
The summary statistic called on data.
@@ -47,8 +47,8 @@ class bootstrap:
4747
Whether or not the summary is the difference between two groups.
4848
If False, only x1 was supplied.
4949
50-
is_paired: boolean
51-
Whether or not the difference reported is between 2 paired groups.
50+
is_paired : string, default None
51+
The type of the experiment under which the data are obtained
5252
5353
statistic: callable
5454
The function used to compute the summary.
@@ -85,19 +85,19 @@ class bootstrap:
8585
8686
pvalue_2samp_ind_ttest: float
8787
P-value obtained from scipy.stats.ttest_ind.
88-
If a single array was given (x1 only), or if `paired` is True,
88+
If a single array was given (x1 only), or if `paired` is not None,
8989
returns 'NIL'.
9090
See https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.stats.ttest_ind.html
9191
9292
pvalue_2samp_related_ttest: float
9393
P-value obtained from scipy.stats.ttest_rel.
94-
If a single array was given (x1 only), or if `paired` is False,
94+
If a single array was given (x1 only), or if `paired` is None,
9595
returns 'NIL'.
9696
See https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.stats.ttest_rel.html
9797
9898
pvalue_wilcoxon: float
9999
P-value obtained from scipy.stats.wilcoxon.
100-
If a single array was given (x1 only), or if `paired` is False,
100+
If a single array was given (x1 only), or if `paired` is None,
101101
returns 'NIL'.
102102
The Wilcoxons signed-rank test is a nonparametric paired test of
103103
the null hypothesis that the related samples x1 and x2 are from
@@ -113,7 +113,7 @@ class bootstrap:
113113
114114
'''
115115
def __init__(self, x1, x2=None,
116-
paired=False,
116+
paired=None,
117117
statfunction=None,
118118
smoothboot=False,
119119
alpha_level=0.05,
@@ -155,7 +155,7 @@ def __init__(self, x1, x2=None,
155155
if len(x1) != len(x2):
156156
raise ValueError('x1 and x2 are not the same length.')
157157

158-
if (x2 is None) or (paired is True) :
158+
if (x2 is None) or (paired is not None) :
159159

160160
if x2 is None:
161161
tx = x1
@@ -165,7 +165,7 @@ def __init__(self, x1, x2=None,
165165
ttest_2_paired = 'NIL'
166166
wilcoxonresult = 'NIL'
167167

168-
elif paired is True:
168+
elif paired is not None:
169169
diff = True
170170
tx = x2 - x1
171171
ttest_single = 'NIL'
@@ -188,7 +188,7 @@ def __init__(self, x1, x2=None,
188188
pct_low_high = np.nan_to_num(pct_low_high).astype('int')
189189

190190

191-
elif x2 is not None and paired is False:
191+
elif x2 is not None and paired is None:
192192
diff = True
193193
x2 = pd.Series(x2).dropna()
194194
# Generate statarrays for both arrays.
@@ -268,7 +268,7 @@ def __repr__(self):
268268
else:
269269
stat = self.statistic
270270

271-
diff_types = {True: 'paired', False: 'unpaired'}
271+
diff_types = {'sequential': 'paired', 'baseline': 'paired', None: 'unpaired'}
272272
if self.is_difference:
273273
a = 'The {} {} difference is {}.'.format(diff_types[self.is_paired],
274274
stat, self.summary)

dabest/_classes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,9 @@ def __pre_calc(self):
25482548
'proportional_difference'
25492549
]
25502550
self.__results = out_.reindex(columns=columns_in_order)
2551-
self.__results.dropna(axis="columns", how="all", inplace=True)
2551+
# The is_paired column could be NaNs, so we keep it.
2552+
subset_cols = columns_in_order.remove('is_paired')
2553+
self.__results.dropna(axis="columns", subset=subset_cols, how="all", inplace=True)
25522554

25532555
if self.__delta2 is True and self.__effect_size == "mean_diff":
25542556
self.__delta_delta = DeltaDelta(self,

dabest/_stats_tools/effsize.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""
1515

1616

17-
def two_group_difference(control, test, is_paired=False,
17+
def two_group_difference(control, test, is_paired=None,
1818
effect_size="mean_diff"):
1919
"""
2020
Computes the following metrics for control and test:
@@ -33,8 +33,8 @@ def two_group_difference(control, test, is_paired=False,
3333
control, test: list, tuple, or ndarray.
3434
Accepts lists, tuples, or numpy ndarrays of numeric types.
3535
36-
is_paired: boolean, default False.
37-
If True, returns the paired Cohen's d.
36+
is_paired: string, default None.
37+
If not None, returns the paired Cohen's d.
3838
3939
effect_size: string, default "mean_diff"
4040
Any one of the following effect sizes:
@@ -97,8 +97,8 @@ def two_group_difference(control, test, is_paired=False,
9797
return hedges_g(control, test, is_paired)
9898

9999
elif effect_size == "cliffs_delta":
100-
if is_paired is True:
101-
err1 = "`is_paired` is True; therefore Cliff's delta is not defined."
100+
if is_paired:
101+
err1 = "`is_paired` is not None; therefore Cliff's delta is not defined."
102102
raise ValueError(err1)
103103
else:
104104
return cliffs_delta(control, test)
@@ -116,9 +116,9 @@ def func_difference(control, test, func, is_paired):
116116
117117
func: summary function to apply.
118118
119-
is_paired: boolean.
120-
If True, computes func(test - control).
121-
If False, computes func(test) - func(control).
119+
is_paired: string.
120+
If not None, computes func(test - control).
121+
If None, computes func(test) - func(control).
122122
123123
Returns:
124124
--------
@@ -159,7 +159,7 @@ def func_difference(control, test, func, is_paired):
159159

160160

161161

162-
def cohens_d(control, test, is_paired=False):
162+
def cohens_d(control, test, is_paired=None):
163163
"""
164164
Computes Cohen's d for test v.s. control.
165165
See https://en.wikipedia.org/wiki/Effect_size#Cohen's_d
@@ -168,16 +168,15 @@ def cohens_d(control, test, is_paired=False):
168168
--------
169169
control, test: List, tuple, or array.
170170
171-
is_paired: boolean, default False
172-
If True, the paired Cohen's d is returned.
171+
is_paired: string, default None
172+
If not None, the paired Cohen's d is returned.
173173
174174
Returns
175175
-------
176176
d: float.
177-
If is_paired is False, this is equivalent to:
177+
If is_paired is None, this is equivalent to:
178178
(numpy.mean(test) - numpy.mean(control)) / pooled StDev
179-
180-
If is_paired is True, returns
179+
If is_paired is not None, returns
181180
(numpy.mean(test) - numpy.mean(control)) / average StDev
182181
183182
The pooled standard deviation is equal to:
@@ -290,7 +289,7 @@ def cohens_h(control, test):
290289

291290

292291

293-
def hedges_g(control, test, is_paired=False):
292+
def hedges_g(control, test, is_paired=None):
294293
"""
295294
Computes Hedges' g for for test v.s. control.
296295
It first computes Cohen's d, then calulates a correction factor based on

dabest/tests/test_10_proportion_plot.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@
1212

1313
two_groups_unpaired = load(df, idx=("Control 1", "Test 1"), proportional=True)
1414

15-
two_groups_paired = load(df, idx=("Control 1", "Test 1"),
16-
paired="baseline", id_col="ID",proportional=True)
17-
1815
multi_2group = load(df, idx=(("Control 1", "Test 1",),
1916
("Control 2", "Test 2")),
2017
proportional=True)
2118

22-
multi_2group_paired = load(df, idx=(("Control 1", "Test 1"),
23-
("Control 2", "Test 2")),
24-
paired="baseline", id_col="ID", proportional=True)
25-
2619
shared_control = load(df, idx=("Control 1", "Test 1",
2720
"Test 2", "Test 3",
2821
"Test 4", "Test 5", "Test 6"),
@@ -31,8 +24,32 @@
3124
multi_groups = load(df, idx=(("Control 1", "Test 1",),
3225
("Control 2", "Test 2","Test 3"),
3326
("Control 3", "Test 4","Test 5", "Test 6")
34-
),proportional=True
35-
)
27+
),proportional=True)
28+
29+
two_groups_paired = load(df, idx=("Control 1", "Test 1"),
30+
paired="baseline", id_col="ID",proportional=True)
31+
32+
multi_2group_paired = load(df, idx=(("Control 1", "Test 1"),
33+
("Control 2", "Test 2")),
34+
paired="baseline", id_col="ID", proportional=True)
35+
36+
multi_groups_paired = load(df, idx=(("Control 1", "Test 1",),
37+
("Control 2", "Test 2","Test 3"),
38+
("Control 3", "Test 4","Test 5", "Test 6")
39+
),paired="baseline", id_col="ID", proportional=True)
40+
41+
two_groups_sequential = load(df, idx=("Control 1", "Test 1"),
42+
paired="sequential", id_col="ID",proportional=True)
43+
44+
multi_2group_sequential = load(df, idx=(("Control 1", "Test 1"),
45+
("Control 2", "Test 2")),
46+
paired="sequential", id_col="ID", proportional=True)
47+
48+
multi_groups_sequential = load(df, idx=(("Control 1", "Test 1",),
49+
("Control 2", "Test 2","Test 3"),
50+
("Control 3", "Test 4","Test 5", "Test 6")
51+
),paired="sequential", id_col="ID", proportional=True)
52+
3653

3754
@pytest.mark.mpl_image_compare
3855
def test_101_gardner_altman_unpaired_propdiff():

0 commit comments

Comments
 (0)