forked from mibognar/cse_simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcse_simul.Rmd
More file actions
49 lines (42 loc) · 1.35 KB
/
Copy pathcse_simul.Rmd
File metadata and controls
49 lines (42 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
title: "simulrt"
author: "Miklos Bognar"
date: "2024-02-09"
output: html_document
---
```{r}
library(dplyr)
library(tidyverse)
library(papaja)
subject_number = 200
trials = 1:200
tau_0 = rnorm(subject_number,0,100)
subject_data = data.frame(subject_id = seq_len(subject_number), tau_0)
trial_df = expand.grid(subject_id = subject_data$subject_id, trial_id = trials)
raw_data = trial_df %>%
left_join(subject_data, by="subject_id") %>%
mutate(congruent = sample(c(0,1),size=n(), replace=T),
prev_congruent = sample(c(0,1),size=n(), replace=T),
beta_0 = rexgaussian(n=n(), mu=700, sigma=100, beta = 180),
beta_1 = rnorm(n=n(), mean=50, sd = 10),
beta_2 = rnorm(n=n(), mean=25, sd = 5)) %>%
mutate(RT = tau_0 +
beta_0+
ifelse(congruent,beta_1*-.5,beta_1*.5)+
ifelse(prev_congruent,0,ifelse(congruent,beta_2*.5,beta_2*-.5)))
summary = raw_data %>%
group_by(congruent,prev_congruent) %>%
summarize(mean_rt = mean(RT),
sd_rt = sd(RT))
raw_data %>%
ggplot()+
aes(x=RT) +
papaja::theme_apa() +
geom_histogram(bins = 100)
summary %>% ggplot()+
aes(x=factor(prev_congruent, levels = c(0,1)), y=mean_rt, color=as.factor(congruent), group=as.factor(congruent)) +
geom_point()+
geom_path()
mymodel = lm(RT ~ congruent * prev_congruent, data = raw_data)
summary(mymodel)
```