Skip to content

Commit

Permalink
ENH test: add Cohen's d to t-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbrodbeck committed Oct 17, 2021
1 parent e86542f commit aa3a89c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions eelbrain/_stats/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,15 @@ def ttest(y, x=None, against=0, match=None, sub=None, corr='Hochberg',
class TTest:
_statistic = 't'

def __init__(self, difference, t, df, tail):
def __init__(self, difference, t, df, tail, std=None):
self._difference = difference
self.t = t
self.df = df
self.p = stats.ttest_p(self.t, self.df, tail)
self.tail = tail
# effect-size
if std is not None:
self.d = difference / std

@property
def stars(self):
Expand Down Expand Up @@ -608,6 +611,8 @@ class TTestOneSample(TTest):
Tailedness of the p value.
df : int
Degrees of freedom.
d : float
Cohen's *d*.
full : FMText
Full description of the test result.
"""
Expand All @@ -633,7 +638,7 @@ def __init__(
if popmean:
v = v - popmean
t = stats.t_1samp(v)[0]
TTest.__init__(self, v.mean(), t, n - 1, tail)
TTest.__init__(self, v.mean(), t, n - 1, tail, ct.y.std())

def __repr__(self):
cmp = '=><'[self.tail]
Expand Down Expand Up @@ -898,6 +903,8 @@ class TTestRelated(TTest):
Mean of condition ``c1``.
c0_mean : float
Mean of condition ``c0``.
d : float
Cohen's *d*.
full : FMText
Full description of the test result.
Expand Down Expand Up @@ -929,7 +936,7 @@ def __init__(
self.c0_mean = y0.mean()
self.difference = y1 - y0
t = stats.t_1samp(self.difference.x[:, None])[0]
TTest.__init__(self, self.difference.x.mean(), t, n - 1, tail)
TTest.__init__(self, self.difference.x.mean(), t, n - 1, tail, self.difference.std())
self._match = dataobj_repr(match, True)

def __repr__(self):
Expand Down

0 comments on commit aa3a89c

Please sign in to comment.