Skip to content

Instantly share code, notes, and snippets.

@debruine
Created August 15, 2019 14:18
Show Gist options
  • Save debruine/2565b469dcfa3a4c3c2ea004de711002 to your computer and use it in GitHub Desktop.
Save debruine/2565b469dcfa3a4c3c2ea004de711002 to your computer and use it in GitHub Desktop.
library(faux)
library(tidyverse)
sub_sd <- 1 # subject intercept SD
stim_sd <- 1 # stimulus intercept SD
err_sd <- 2 # residual error SD
grand.i <- 600 # grand interecpt (mean RT)
ord_eff <- 0.5 # coefficient of order effect
sch_eff <- 0.5 # coefficient of schizotypy effect
ord_sch_ixn <- 0.5 # coefficient of order*schizotypy interaction
sub <- sim_design(
within = list(var = c("schizotypy", "sub.i")),
id = "sub_id",
n = 20,
mu = c(10, 0),
sd = c(5, sub_sd)
)
stim <- sim_design(
id = "stim_id",
dv = "stim.i",
n = 9,
mu = 0,
sd = stim_sd
)
trials <- crossing(
sub_id = sub$sub_id,
stim_id = stim$stim_id
) %>%
left_join(sub, by = "sub_id") %>%
left_join(stim, by = "stim_id") %>%
group_by(sub_id) %>%
mutate(stim_order = sample(1:9)) %>%
ungroup() %>%
mutate(err = rnorm(nrow(.), 0, err_sd),
RT = grand.i + sub.i + stim.i +
ord_eff*stim_order +
sch_eff*schizotypy +
ord_sch_ixn*stim_order*schizotypy + err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment