0

I've just tried to calculate Cohen's d in R with the following formula:

mean1 <- mean(Meaningfulness[df$age<=22],na.rm=TRUE)
mean2 <- mean(Meaningfulness[df age>=22],na.rm=TRUE)
sd1 <- sd(Meaningfulness[df$age<=22],na.rm=TRUE)
sd2 <- sd(Meaningfulness[df$age>=22],na.rm=TRUE)

pooled <- sqrt((sd1^2 + sd2^2) / 2


d <- (mean1-mean2)/(pooled)

Just to be sure I have compared 2 outputs with an online "cohen's d calculator". The Cohen's ds I've calculated differs by 0.04 and.003 from the online calculator. Any suggestions on what might be wrong with my code? Every help is appreciated!! :)

Newby
  • 1
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Please provide a reference to the particular online calculator you used as well. – MrFlick Aug 31 '21 at 17:03
  • 1
    Rounding? I also notice that observations with `df$age == 22` will contribute to both groups. That's almost certainly not correct. I think you have a typo in line 2 of your code. – Limey Aug 31 '21 at 17:06
  • Is it `mean2` - `mean1`? – SNR Aug 31 '21 at 17:08
  • Wow! Thanks for all your answers already. @MrFlick the online calculator I used was this one: https://statistikguru.de/rechner/cohens-d.html When I compare my results Mean 1 = 4.979567; sd1 = 0,7342572 Mean 2 = 5,147837; sd2 = 0,7683255 The difference is worse when I feed the online calculator with the output of my t-test (t = -2.6052, df = 393); could this be because I remove the n.a. in the manual calculation of Cohen's d, but not in the t-test?If so - is there actually a possibility to remove the n.a. in the t-test? I just noticed I also get different means for group 1 in the ttest – Newby Aug 31 '21 at 17:36
  • @Limey oh your right! I see the typo. Thankfully the typo just happened when I edited my question - in Rstudio I got it right ;) Actually it is not df$age==22 but df$age<= and df$age>= so that shouldn't be the problem... – Newby Aug 31 '21 at 17:37
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 31 '21 at 21:22

0 Answers0