9999) # Fix the seed so the results are replicable.
np.random.seed(= 20
N # Create samples
= norm.rvs(loc=3, scale=0.4, size=N*4)
y 2*N] = y[N:2*N]+1
y[N:2*N:3*N] = y[2*N:3*N]-0.5
y[# Add a `Treatment` column
= np.repeat('Placebo', N*2).tolist()
t1 = np.repeat('Drug', N*2).tolist()
t2 = t1 + t2
treatment # Add a `Rep` column as the first variable for the 2 replicates of experiments done
= []
rep for i in range(N*2):
'Rep1')
rep.append('Rep2')
rep.append(# Add a `Genotype` column as the second variable
= np.repeat('W', N).tolist()
wt = np.repeat('M', N).tolist()
mt = np.repeat('W', N).tolist()
wt2 = np.repeat('M', N).tolist()
mt2 = wt + mt + wt2 + mt2
genotype # Add an `id` column for paired data plotting.
id = list(range(0, N*2))
= id + id
id_col # Combine all columns into a DataFrame.
= pd.DataFrame({'ID' : id_col,
df_delta2 'Rep' : rep,
'Genotype' : genotype,
'Treatment': treatment,
'Y' : y
})= dabest.load(data = df_delta2, x = ["Genotype", "Genotype"], y = "Y", delta2 = True, experiment = "Treatment")
unpaired_delta2 ; unpaired_delta2.mean_diff.plot()
Delta objects
DeltaDelta
DeltaDelta (effectsizedataframe, permutation_count, bootstraps_delta_delta, ci=95)
A class to compute and store the delta-delta statistics for experiments with a 2-by-2 arrangement where two independent variables, A and B, each have two categorical values, 1 and 2. The data is divided into two pairs of two groups, and a primary delta is first calculated as the mean difference between each of the pairs:
\[\Delta_{1} = \overline{X}_{A_{2}, B_{1}} - \overline{X}_{A_{1}, B_{1}}\]
\[\Delta_{2} = \overline{X}_{A_{2}, B_{2}} - \overline{X}_{A_{1}, B_{2}}\]
where \(\overline{X}_{A_{i}, B_{j}}\) is the mean of the sample with A = i and B = j, \(\Delta\) is the mean difference between two samples.
A delta-delta value is then calculated as the mean difference between the two primary deltas:
\[\Delta_{\Delta} = \Delta_{2} - \Delta_{1}\]
and a deltas’ g value is calculated as the mean difference between the two primary deltas divided by the standard deviation of the delta-delta value, which is calculated from a pooled variance of the 4 samples:
\[\Delta_{g} = rac{\Delta_{\Delta}}{s_{\Delta_{\Delta}}}\]
\[s_{\Delta_{\Delta}} = \sqrt{rac{(n_{A_{2}, B_{1}}-1)s_{A_{2}, B_{1}}^2+(n_{A_{1}, B_{1}}-1)s_{A_{1}, B_{1}}^2+(n_{A_{2}, B_{2}}-1)s_{A_{2}, B_{2}}^2+(n_{A_{1}, B_{2}}-1)s_{A_{1}, B_{2}}^2}{(n_{A_{2}, B_{1}} - 1) + (n_{A_{1}, B_{1}} - 1) + (n_{A_{2}, B_{2}} - 1) + (n_{A_{1}, B_{2}} - 1)}}\]
where \(s\) is the standard deviation and \(n\) is the sample size.
and the standard deviation of the delta-delta value is calculated from a pooled variance of the 4 samples:
\[s_{\Delta_{\Delta}} = \sqrt{\frac{(n_{A_{2}, B_{1}}-1)s_{A_{2}, B_{1}}^2+(n_{A_{1}, B_{1}}-1)s_{A_{1}, B_{1}}^2+(n_{A_{2}, B_{2}}-1)s_{A_{2}, B_{2}}^2+(n_{A_{1}, B_{2}}-1)s_{A_{1}, B_{2}}^2}{(n_{A_{2}, B_{1}} - 1) + (n_{A_{1}, B_{1}} - 1) + (n_{A_{2}, B_{2}} - 1) + (n_{A_{1}, B_{2}} - 1)}}\]
where \(s\) is the standard deviation and \(n\) is the sample size.
Example: delta-delta
MiniMetaDelta
MiniMetaDelta (effectsizedataframe, permutation_count, ci=95)
A class to compute and store the weighted delta. A weighted delta is calculated if the argument mini_meta=True
is passed during dabest.load()
.
The weighted delta is calcuated as follows:
\[\theta_{\text{weighted}} = \frac{\Sigma\hat{\theta_{i}}w_{i}}{{\Sigma}w_{i}}\]
where:
\[\hat{\theta_{i}} = \text{Mean difference for replicate }i\]
\[w_{i} = \text{Weight for replicate }i = \frac{1}{s_{i}^2} \]
\[s_{i}^2 = \text{Pooled variance for replicate }i = \frac{(n_{test}-1)s_{test}^2+(n_{control}-1)s_{control}^2}{n_{test}+n_{control}-2}\]
\[n = \text{sample size and }s^2 = \text{variance for control/test.}\]
Example: mini-meta-delta
= 20
Ns = norm.rvs(loc=3, scale=0.4, size=Ns)
c1 = norm.rvs(loc=3.5, scale=0.75, size=Ns)
c2 = norm.rvs(loc=3.25, scale=0.4, size=Ns)
c3 = norm.rvs(loc=3.5, scale=0.5, size=Ns)
t1 = norm.rvs(loc=2.5, scale=0.6, size=Ns)
t2 = norm.rvs(loc=3, scale=0.75, size=Ns)
t3 = pd.DataFrame({'Control 1' : c1, 'Test 1' : t1,
my_df 'Control 2' : c2, 'Test 2' : t2,
'Control 3' : c3, 'Test 3' : t3})
= dabest.load(my_df, idx=(("Control 1", "Test 1"), ("Control 2", "Test 2"), ("Control 3", "Test 3")), mini_meta=True)
my_dabest_object my_dabest_object.mean_diff.mini_meta_delta
DABEST v2024.03.29
==================
Good afternoon!
The current time is Tue Mar 19 15:34:33 2024.
The weighted-average unpaired mean differences is 0.0336 [95%CI -0.137, 0.228].
The p-value of the two-sided permutation t-test is 0.736, calculated for legacy purposes only.
5000 bootstrap samples were taken; the confidence interval is bias-corrected and accelerated.
Any p-value reported is the probability of observing theeffect size (or greater),
assuming the null hypothesis of zero difference is true.
For each p-value, 5000 reshuffles of the control and test labels were performed.
As of version 2023.02.14, weighted delta can only be calculated for mean difference, and not for standardized measures such as Cohen’s d.
Details about the calculated weighted delta are accessed as attributes of the mini_meta_delta
class. See the minimetadelta
for details on usage.
Refer to Chapter 10 of the Cochrane handbook for further information on meta-analysis: https://training.cochrane.org/handbook/current/chapter-10