Skip to content

Commit 0d37155

Browse files
committed
Delta-Delta Tests and Docs
1. added doc string to class DeltaDelta and corrected typos 2. changed delta-delta tests and utils.py to mutant-drug configuration 3. generated test images for delta-delta tests 4. added tutorial page deltadelta.rst to include calculations and example plots 5. modified index.rst to include deltadelta 6. modified api.rst to include deltadelta 7. updated tutorial images for deltadelta
1 parent 3faa92d commit 0d37155

24 files changed

+536
-36
lines changed

dabest/_classes.py

+61-3
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,65 @@ def _all_plot_groups(self):
857857

858858
class DeltaDelta(object):
859859
"""
860-
A class to compute and store the delta-delta statistics.
860+
A class to compute and store the delta-delta statistics. In a 2-by-2 arrangement where two independent variables, A and B, each have two categorical values, two primary deltas are first calculated with one independent variable and a delta-delta effect size is calculated as a difference between the two primary deltas.
861+
862+
.. math::
863+
864+
\\hat{\\theta}_{B1} = \\overline{X}_{A2, B1} - \\overline{X}_{A1, B1}
865+
866+
\\hat{\\theta}_{B2} = \\overline{X}_{A2, B2} - \\overline{X}_{A1, B2}
867+
868+
.. math::
869+
870+
\\hat{\\theta}_{\\theta} = \\hat{\\theta}_{B2} - \\hat{\\theta}_{B1}
871+
872+
and:
873+
874+
.. math::
875+
876+
s_{\\theta} = \\frac{(n_{A2, B1}-1)s_{A2, B1}^2+(n_{A1, B1}-1)s_{A1, B1}^2+(n_{A2, B2}-1)s_{A2, B2}^2+(n_{A1, B2}-1)s_{A1, B2}^2}{(n_{A2, B1} - 1) + (n_{A1, B1} - 1) + (n_{A2, B2} - 1) + (n_{A1, B2} - 1)}
877+
878+
Example
879+
-------
880+
>>> import numpy as np
881+
>>> import pandas as pd
882+
>>> from scipy.stats import norm # Used in generation of populations.
883+
>>> np.random.seed(9999) # Fix the seed so the results are replicable.
884+
>>> from scipy.stats import norm # Used in generation of populations.
885+
>>> N = 20
886+
>>> # Create samples
887+
>>> y = norm.rvs(loc=3, scale=0.4, size=N*4)
888+
>>> y[N:2*N] = y[N:2*N]+1
889+
>>> y[2*N:3*N] = y[2*N:3*N]-0.5
890+
>>> # Add drug column
891+
>>> t1 = np.repeat('Placebo', N*2).tolist()
892+
>>> t2 = np.repeat('Drug', N*2).tolist()
893+
>>> treatment = t1 + t2
894+
>>> # Add a `rep` column as the first variable for the 2 replicates of experiments done
895+
>>> rep = []
896+
>>> for i in range(N*2):
897+
>>> rep.append('Rep1')
898+
>>> rep.append('Rep2')
899+
>>> # Add a `genotype` column as the second variable
900+
>>> wt = np.repeat('W', N).tolist()
901+
>>> mt = np.repeat('M', N).tolist()
902+
>>> wt2 = np.repeat('W', N).tolist()
903+
>>> mt2 = np.repeat('M', N).tolist()
904+
>>> genotype = wt + mt + wt2 + mt2
905+
>>> # Add an `id` column for paired data plotting.
906+
>>> id = list(range(0, N*2))
907+
>>> id_col = id + id
908+
>>> # Combine all columns into a DataFrame.
909+
>>> df_delta2 = pd.DataFrame({'ID' : id_col,
910+
>>> 'Rep' : rep,
911+
>>> 'Genotype' : genotype,
912+
>>> 'Drug': treatment,
913+
>>> 'Y' : y
914+
>>> })
915+
916+
917+
918+
861919
"""
862920

863921
def __init__(self, effectsizedataframe, permutation_count,
@@ -1014,8 +1072,8 @@ def __repr__(self, header=True, sigfig=3):
10141072
bs2 = "the confidence interval is bias-corrected and accelerated."
10151073
bs = bs1 + bs2
10161074

1017-
pval_def1 = "Any p-value reported is the probability of observing the" + \
1018-
"effect size (or greater),\nassuming the null hypothesis of" + \
1075+
pval_def1 = "Any p-value reported is the probability of observing the " + \
1076+
"effect size (or greater),\nassuming the null hypothesis of " + \
10191077
"zero difference is true."
10201078
pval_def2 = "\nFor each p-value, 5000 reshuffles of the " + \
10211079
"control and test labels were performed."
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

dabest/tests/test_07_delta-delta_plots.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,26 @@
2222

2323
df = create_demo_dataset_delta()
2424

25-
unpaired = load(data = df, x = ["Light", "Genotype"], y = "Y", delta2 = True,
26-
experiment = "Experiment")
25+
unpaired = load(data = df, x = ["Genotype", "Genotype"], y = "Y", delta2 = True,
26+
experiment = "Treatment")
2727

28-
baseline = load(data = df, x = ["Light", "Genotype"], y = "Y", delta2 = True,
29-
experiment = "Experiment",
28+
unpaired_specified = load(data = df, x = ["Genotype", "Genotype"], y = "Y",
29+
delta2 = True, experiment = "Treatment",
30+
experiment_label = ["Drug", "Placebo"],
31+
x1_level = ["M", "W"])
32+
33+
baseline = load(data = df, x = ["Treatment", "Rep"], y = "Y", delta2 = True,
34+
experiment = "Genotype",
3035
paired="baseline", id_col="ID")
3136

32-
sequential = load(data = df, x = ["Light", "Genotype"], y = "Y", delta2 = True,
33-
experiment = "Experiment",
37+
sequential = load(data = df, x = ["Treatment", "Rep"], y = "Y", delta2 = True,
38+
experiment = "Genotype",
3439
paired="sequential", id_col="ID")
3540

3641

3742
@pytest.mark.mpl_image_compare(tolerance=10)
3843
def test_47_cummings_unpaired_delta_delta_meandiff():
39-
return unpaired.mean_diff.plot(fig_size=(12, 8), raw_marker_size=4);
44+
return unpaired.mean_diff.plot();
4045

4146

4247
@pytest.mark.mpl_image_compare(tolerance=10)
@@ -62,14 +67,13 @@ def test_51_delta_plot_change_palette_a():
6267

6368

6469
@pytest.mark.mpl_image_compare(tolerance=10)
65-
def test_52_delta_dot_sizes():
66-
return sequential.mean_diff.plot(show_pairs=False,raw_marker_size=3,
67-
es_marker_size=12);
70+
def test_52_delta_specified():
71+
return unpaired_specified.mean_diff.plot();
6872

6973

7074
@pytest.mark.mpl_image_compare(tolerance=10)
7175
def test_53_delta_change_ylims():
72-
return sequential.mean_diff.plot(swarm_ylim=(0, 5),
76+
return sequential.mean_diff.plot(swarm_ylim=(0, 9),
7377
contrast_ylim=(-2, 2),
7478
fig_size=(15,6));
7579

dabest/tests/utils.py

+25-22
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,42 @@ def create_demo_dataset_delta(seed=9999, N=20):
9898
from scipy.stats import norm # Used in generation of populations.
9999

100100
# Create samples
101-
y = norm.rvs(loc=3, scale=0.4, size=N*2)
101+
y = norm.rvs(loc=3, scale=0.4, size=N*4)
102+
y[N:2*N] = y[N:2*N]+1
103+
y[2*N:3*N] = y[2*N:3*N]-0.5
102104

103-
# Add experiment column
104-
e1 = np.repeat('Control', N).tolist()
105-
e2 = np.repeat('Test', N).tolist()
106-
experiment = e1 + e2
105+
# Add drug column
106+
t1 = np.repeat('Placebo', N*2).tolist()
107+
t2 = np.repeat('Drug', N*2).tolist()
108+
treatment = t1 + t2
107109

108-
# Add a `Light` column as the first variable
109-
light = []
110-
for i in range(N):
111-
light.append('L1')
112-
light.append('L2')
110+
# Add a `rep` column as the first variable for the 2 replicates of experiments done
111+
rep = []
112+
for i in range(N*2):
113+
rep.append('Rep1')
114+
rep.append('Rep2')
113115

114116
# Add a `genotype` column as the second variable
115-
g1 = np.repeat('G1', N/2).tolist()
116-
g2 = np.repeat('G2', N/2).tolist()
117-
g3 = np.repeat('G3', N).tolist()
118-
genotype = g1 + g2 + g3
117+
wt = np.repeat('W', N).tolist()
118+
mt = np.repeat('M', N).tolist()
119+
wt2 = np.repeat('W', N).tolist()
120+
mt2 = np.repeat('M', N).tolist()
121+
122+
123+
genotype = wt + mt + wt2 + mt2
119124

120125
# Add an `id` column for paired data plotting.
121-
id_col = []
122-
for i in range(N):
123-
id_col.append(i)
124-
id_col.append(i)
126+
id = list(range(0, N*2))
127+
id_col = id + id
125128

126-
# Combine samples and gender into a DataFrame.
129+
130+
# Combine all columns into a DataFrame.
127131
df = pd.DataFrame({'ID' : id_col,
128-
'Light' : light,
132+
'Rep' : rep,
129133
'Genotype' : genotype,
130-
'Experiment': experiment,
134+
'Treatment': treatment,
131135
'Y' : y
132136
})
133-
134137
return df
135138

136139

1.6 KB
Loading
4.22 KB
Loading
-4.1 KB
Loading
-20.7 KB
Loading
-18.8 KB
Loading

docs/source/api.rst

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Computing Effect Sizes
2424
.. autoclass:: dabest._classes.MiniMetaDelta
2525
:members: difference, bca_low, bca_high, bootstraps, to_dict
2626

27+
.. autoclass:: dabest._classes.DeltaDelta
28+
:members: difference, bca_low, bca_high, bootstraps, bootstraps_delta_delta, to_dict
2729

2830
Plotting Data
2931
-------------

0 commit comments

Comments
 (0)