forked from MartinHeroux/ScientificallySound_files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cohen_overlap.py
37 lines (30 loc) · 1.13 KB
/
cohen_overlap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm
ctl_mean = 50
sd = 15
cohen_d = [0.2, 0.5, 0.8]
ctl_x = np.linspace(0, 100, 500)
ctl_y = norm.pdf(ctl_x, loc=50, scale=sd)
f, axes = plt.subplots(3, figsize=(8,10))
for i, d in enumerate(cohen_d):
Rx_mean = ctl_mean + d*sd
Rx_x = np.linspace(Rx_mean-50, Rx_mean+50, 500)
Rx_y = norm.pdf(Rx_x, loc=Rx_mean, scale=sd)
axes[i].fill(ctl_x, ctl_y, 'r', alpha=0.5)
label = "Cohen's d = {}".format(str(d))
axes[i].fill(Rx_x, Rx_y, 'b', alpha=0.5,label=label)
x_vals = [ctl_mean,Rx_mean]
y_vals = [np.max(ctl_y)+.002, np.max(Rx_y)+.002]
axes[i].plot(x_vals, y_vals,'k',linewidth=4)
axes[i].legend(frameon=False)
axes[i].set_xlim(0, 120)
axes[i].set_xticks(np.arange(0,130,10))
axes[i].set_ylim(0, 0.035)
axes[i].spines['top'].set_visible(False)
axes[i].spines['right'].set_visible(False)
axes[i].spines['left'].set_visible(False)
axes[i].tick_params(axis='x', top='off')
axes[i].tick_params(axis='y', right='off',
left='off',labelleft='off')
plt.savefig('cohen_example.png')