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)**strong text**
sd2 <- sd(Meaningfulness[df$age>=22],na.rm=TRUE)
d <- (mean1-mean2)/(c(sd1,sd2))
Interestingly I get 2 outputs then? And my second confusion is - when I compare the results to an online "cohen's d calculator" with one set of data my calculated Cohen's d matches with the one from the online calculator with another set of data it doesn't.
Any suggestions on what might be wrong with my code? Every help is appreciated!! :)
c(sd1,sd2)is not doing what you think it's doing. You'll need to calculate the pooled standard deviation and divide by that instead. (Or, divide by the standard deviation of the "control group", depending on the particular interpretation of cohen's d you want.) – David Thiessen Aug 31 '21 at 15:24sd1andsd2in a vector instead of e.g. taking their weighted mean? – B.Liu Aug 31 '21 at 15:24I only get 1 output now and it seems reasonable. Still it differs from the online calculator. Should I worry?
– Newby_101 Aug 31 '21 at 16:30NAvalues inMeaningfulnessyou should also remove them from the calculation ofn1andn2. – David Thiessen Aug 31 '21 at 16:53