# How can I derive cohen's d from raw data

I hope someone can help me with this simple question:

I want to derive Cohen's d from raw data.

I know cohen's d is just the (mean1-mean2)/pooledSD. What I want to do is to derive it directly from raw data is such a way that I work in the standardised scale.

I have tried to calculate the pooled mean and pooled SD and then standardise each observation by (obs1-pooled mean)/pooledSD and do the same for all observations.

The Cohen's d and the difference calculated using the method above are very similar (almost the same) but not exactly the same.

Please can anyone confirm that cohen's d is mathematically the same as standardising the observations and calculating the mean difference of standardised observations between groups?

a}} calculating cohens'd from aggregated data grandmean 21.875 mean0 21 mean1 22.75 pooledsd 3.068953936

cohen's d -0.570226871

b}} calculating cohen'd from raw data using the field (mpg-grandmean)/pooledsd mean_1 -0.285113435 mean_2 0.285113435

diff 1 and 2 -0.570226871

I need to know whether approach a}} and approach b}} are equivalent mathematically.

• Can you show us the formula you've used? Is your groups paired or unpaired, and is it balanced or unbalanced because that can affect the formula you use Apr 18, 2019 at 12:51

EDIT: I’ve heavily edited my answer because I misinterpreted the question and then couldn’t do basic maths. OP wanted to standardize the data using the pooled SD then take the mean of each group and then subtract those means from each other. So,

$$\frac{1}{n}\sum_i\frac{ x_i-GRAND}{S_{pooled}}-\frac{1}{n} \sum_j\frac{ x_j-GRAND}{S_{pooled}}\\=\frac{1}{n s_{pooled}}\sum_i (x_i -GRAND) -\sum_j (x_j -GRAND)\\=\frac{1}{n s_{pooled}}\sum_i (x_i) -nGRAND -\sum_j (x_j) +nGRAND\\=\frac{\sum_i x_i - \sum_j x_j}{n S_{pooled}}\\=\frac{1}{n}(\sum_i x_i -\sum_j x_j) \frac{1}{S_{pooled}}\\=\frac{\frac{1}{n}\sum_ix_i-\frac{1}{n}\sum_jx_j}{S_{pooled}}$$

Which is the formula for Cohen's D.

Using the data provided in R:

    mpg<-
c(20,23,21,25,18,17,18,24,20,24,23,19,24,25,21,22,23,18,17,28,24,27,21,23)
treated<-as.factor(c(rep(0,12),rep(1,12)))

mean(mpg[c(1:12)]-mean(mpg))/
sqrt((11*var(mpg[c(1:12)])+11*var(mpg[c(13:24)]))/(22))-
mean(mpg[c(13:24)]-mean(mpg))/
sqrt((11*var(mpg[c(1:12)])+11*var(mpg[c(13:24)]))/(22))
[1] -0.5829654
library(effsize)
cohen.d.default(mpg, treated)
Cohen's d

d estimate: -0.5829654 (medium)
95 percent confidence interval:
lower      upper
-1.4474169  0.2814861

• No, I did not do that. what I did was 𝑥i−(1𝑛1∑𝑖𝑥𝑖+1𝑛1∑𝑗𝑥𝑗). This made all my values standardised. Then I took the mean of the standardised values in group 1 and the mean of the standardised values in group 2. My question is whether cohen's D is the same as calculating the difference in the mean of standardised values Apr 18, 2019 at 15:43
• OK fair enough, I will remove my answer, but can you maybe edit your question a little to show us what you've done? I can help but I'm going to need more information. It's not really clear what you've done at this stage. Apr 18, 2019 at 15:45
• No, I did not do that. what I did was 𝑥i−(1𝑛1∑𝑖𝑥𝑖+1𝑛1∑𝑗𝑥𝑗). This made all my values standardised. Then I took the mean of the standardised values in group 1 and the mean of the standardised values in group 2. My question is whether cohen's D is the same as calculating the difference in the mean of standardised values Apr 18, 2019 at 15:45
• Well, it took a while to type, but hope that helps. Apr 18, 2019 at 16:22
• I have edited my question with an example. Please could you look at it whether both approaches are equal. I simply do not know how I can use equations in here. Thanks in advance Apr 18, 2019 at 16:47