Last active
June 10, 2019 14:28
-
-
Save debruine/527595b7f3b756d689e12c2e6f24af57 to your computer and use it in GitHub Desktop.
Simulate prosopagnosia data
This file contains 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
#devtools::install_github("debruine/faux") | |
library(faux) | |
library(afex) | |
library(tidyverse) | |
## Null data (no effect) | |
des_null <- check_design(list(task = c("test", "white", "asian")), | |
n = 400, | |
mu = c(100, 100, 90), | |
sd = c(10, 10, 10), | |
r = .6) | |
sim_null <- function() { | |
data <- sim_design(des_null, plot = FALSE) %>% | |
mutate(proso = test < mean(test) - 2*sd(test)) %>% | |
gather(face_eth, score, white, asian) | |
suppressMessages( | |
aov_ez(id = "id", between = "proso", within = "face_eth", | |
dv = "score", data = data, return = "aov") %>% | |
broom::tidy() | |
) | |
} | |
sim_dat_null <- map_df(1:100, ~sim_null()) | |
sim_dat_null %>% | |
group_by(term) %>% | |
summarise(power = mean(p.value < .05)) | |
## Experimental hypothesis (ixn between proso and face_eth) | |
within <- list(face_eth = c("white", "asian")) | |
between <- list(proso = c("proso", "control")) | |
des_exp <- check_design(within, between, n = list(proso = 15, control = 385), | |
mu = list(proso = c(70, 40), | |
control = c(100, 90)), | |
sd = 10, | |
r = .6, | |
dv = "score") | |
sim_exp <- function() { | |
data <- sim_design(des_exp, plot = FALSE, long = TRUE) | |
suppressMessages( | |
aov_ez(id = "id", between = "proso", within = "face_eth", | |
dv = "score", data = data, return = "aov") %>% | |
broom::tidy() | |
) | |
} | |
sim_dat_exp <- map_df(1:100, ~sim_null()) | |
sim_dat_exp %>% | |
group_by(term) %>% | |
summarise(power = mean(p.value < .05)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment