Created
December 15, 2022 14:41
-
-
Save martinmodrak/13c255d7fc72a32a5c2ad3a73ef657db to your computer and use it in GitHub Desktop.
Simulation showing how the same difference in means can lead to arbitrary Cohen's d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(effsize) | |
| set.seed(156226) | |
| N <- 50 | |
| groups <- rep(c("A","B"), each = N) | |
| means <- rep(c(20,18), each = N) | |
| noise <- rnorm(2*N, 0, 1) | |
| noise <- noise - mean(noise) | |
| df1 <- data.frame(group = groups, y = means + noise * 0.001) | |
| df1$cohend <- round(cohen.d(y ~ group, df1)$estimate) | |
| df2 <- data.frame(group = groups, y = means + noise) | |
| df2$cohend <- round(cohen.d(y ~ group, df2)$estimate, 2) | |
| df3 <- data.frame(group = groups, y = means + noise * 8) | |
| df3$cohend <- round(cohen.d(y ~ group, df3)$estimate, 2) | |
| ggplot(rbind(df1, df2, df3), | |
| aes(x = group, y = y)) + | |
| stat_summary(geom = "line", group = 1) + | |
| geom_point(position = position_jitter(width = 0.2), alpha = 0.4) + | |
| facet_wrap(~cohend, labeller = "label_both") + theme_minimal() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment