dgromer / apa

Format output of statistical tests in R according to APA guidelines
GNU General Public License v3.0
28 stars 2 forks source link

Different cohens d for t.test and t_test #11

Closed stefanleach closed 4 years ago

stefanleach commented 4 years ago

Hi there,

Just a quick query/comment. I seem to be getting different effect size estimates when piping the results of a t.test vs. t_test to the apa() function. This is happening with an independent samples test and when requesting Cohens d.

For example, I receive one estimate for Cohens d when running a script equivalent to the following, with the "t_test" function:

data %>%
  summarize(result = t_test(x, y, paired = FALSE, var.equal = TRUE) %>% apa(es = "cohens_d"))

...but a different estimate for Cohens d when running a script equivalent to the following, , with the "t.test" function:

data %>%
  summarize(result = t.test(x, y, paired = FALSE, var.equal = TRUE) %>% apa(es = "cohens_d"))

Any input would be helpful.

Cheers,

Stefan

stefanleach commented 4 years ago

Doing a few more tests on this, I can't seem to replicate this issue. The following code produces the same Cohens d estimates for seed 1-10.

library(tidyverse)
library(apa)

set.seed(6)

test <- 
  data.frame(x = rnorm(50),
             y = rnorm(50))

test %>%
  summarize(result = t_test(x, y, paired = FALSE, var.equal = TRUE) %>% apa(es = "cohens_d"))

test %>%
  summarize(result = t.test(x, y, paired = FALSE, var.equal = TRUE) %>% apa(es = "cohens_d"))
dgromer commented 4 years ago

If you pass the result of t_test to cohens_d (via apa), Cohen's d is calculated from the raw data via the following formula:

If you pass the result of t.test, cohens_d can't calculate Cohens'd from the raw data, because the data is not included in the list returned by t.test. For this reason, cohens_d uses the following formula:

(both formulas from Lakens, 2013)

If your sample sizes are not equal, then the two formulas might not produce the same results.

stefanleach commented 4 years ago

Ah, that makes sense. Good to know! 👍

Thanks for the speedy response!