-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Simon Ho
committed
Mar 17, 2018
1 parent
767e34c
commit dc54c04
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Tools for calculating different types of statistics, such as effect size | ||
estimates. | ||
""" | ||
|
||
import numpy as np | ||
|
||
|
||
def cohens_d(g1_m, g1_sd, g1_n, g2_m, g2_sd, g2_n): | ||
""" | ||
Calculate Cohen's d for two independent samples. | ||
This calculation involves taking the mean difference between groups, and | ||
dividing it by the pooled standard deviation. | ||
Parameters | ||
---------- | ||
g1_m : float | ||
Mean value for group 1. | ||
g1_sd : float | ||
Standard deviation for group 1. | ||
g1_n : int | ||
Sample size of group 1. | ||
g2_m : float | ||
Mean value for group 2. | ||
g2_sd : float | ||
Standard deviation for group 2. | ||
g2_n : int | ||
Sample size of group 2. | ||
Returns | ||
------- | ||
d : float | ||
Standardized effect size (Cohen's d) for the group difference. | ||
""" | ||
|
||
mean_diff = g2_m - g1_m | ||
|
||
sd_num = ((g1_n - 1)*np.square(g1_sd)) + ((g2_n - 1)*np.square(g2_sd)) | ||
sd_denom = g1_n + g2_n - 2 | ||
|
||
sd_pooled = np.sqrt(sd_num / sd_denom) | ||
|
||
return mean_diff/sd_pooled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters