File Exchange

image thumbnail

computeCohen_d(x1, x2, varargin)

version (2.08 KB) by Ruggero G. Bettinardi
Compute Cohen's d effect size


Updated 15 May 2017

View License

call: d = computeCohen_d(x1, x2, varargin)

EFFECT SIZE of the difference between the two
means of two samples, x1 and x2 (that are vectors),
computed as "Cohen's d".

If x1 and x2 can be either two independent or paired
samples, and should be treated accordingly:

d = computeCohen_d(x1, x2, 'independent'); [default]
d = computeCohen_d(x1, x2, 'paired');

Note: according to Cohen and Sawilowsky:

d = 0.01 --> very small effect size
d = 0.20 --> small effect size
d = 0.50 --> medium effect size
d = 0.80 --> large effect size
d = 1.20 --> very large effect size
d = 2.00 --> huge effect size

Cite As

Ruggero G. Bettinardi (2021). computeCohen_d(x1, x2, varargin) (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

xueli chen

Effect size for paired t-test is equal to t/sqrt(N), but also equals to mean(x1-x2)/std(x1-x2)

Raymond MacNeil

I didn't even mean to rate, and I can't seem to cancel my rating. Looks good--my only quibble is that I don't see where you get the absolute mean difference in the code.

Tom Nguyen

Effect size for paired t-test should be = t/sqrt(N) where t is the test statistics, N is the sample size.

Alexandra Sobczak


manoj saranathan

Thanks. If you add a . to the divisions in
pooledSD = sqrt(numer ./ denom); % pooled Standard Deviation
d = meanDiff ./ s; % Cohen's d (for independent samples)
then it will work on multi dimensional data i.e. y variables in columns, each column being a different variable.

Yung-Hao Yang

Thank you for sharing this nice code!
I have one question when calculating Cohen d for paired samples (x1, x2),
the pool SD should be SD from each sample
but not the SD of the sample difference
nanstd(x1 - x2).
Is it correct? Thank you!

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!