Skip to content

Commit

Permalink
Add effect size calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Ho committed Mar 17, 2018
1 parent 767e34c commit dc54c04
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pyutils_sh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
Functions for aggregating different types of data from school exams (e.g. student grades)
gaze
Functions for analyzing gaze/eye-tracking data
stats
Tools for calculating different types of statistics
survey
Tools for aggregating and analyzing data from different surveys
utils
Expand All @@ -37,5 +39,6 @@

import pyutils_sh.exam
import pyutils_sh.gaze
import pyutils_sh.stats
import pyutils_sh.survey
import pyutils_sh.utils
44 changes: 44 additions & 0 deletions pyutils_sh/stats.py
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

setup(name='pyutils_sh',
version='1.1.0',
version='1.2.0',
description='Assortment of Python utilities for my personal projects',
url='https://github.com/sho-87/pyutils_sh',
author='Simon Ho',
Expand Down

0 comments on commit dc54c04

Please sign in to comment.