Skip to content

Instantly share code, notes, and snippets.

@rubenarslan
Created August 16, 2023 09:33
Show Gist options
  • Save rubenarslan/7416e80e7ef26dce770fb83d28671aad to your computer and use it in GitHub Desktop.
Save rubenarslan/7416e80e7ef26dce770fb83d28671aad to your computer and use it in GitHub Desktop.
misspecified estimand explains result
library(dplyr)
N = 10000
people <- tibble(
male = sample(0:1, N, TRUE),
trait = rnorm(N) + male)
true_means <- people %>%
group_by(male) %>%
summarise(sex_mean = mean(trait))
people <- people %>% left_join(true_means) %>%
left_join(true_means %>% rename(opposite_sex_mean = sex_mean) %>% mutate(male = 1-male)) %>%
mutate(unspecified = trait,
same_sex = trait - sex_mean,
opposite_sex = trait - opposite_sex_mean)
effsize::cohen.d(unspecified ~ male, people)
#> Cohen's d
#>
#> d estimate: -1.043947 (large)
effsize::cohen.d(opposite_sex ~ male, people)
#> Cohen's d
#>
#> d estimate: -2.087894 (large)
effsize::cohen.d(same_sex ~ male, people)
#> Cohen's d
#>
#> d estimate: -9.587134e-17 (negligible)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment