Created
November 27, 2019 22:55
-
-
Save steveharoz/445d8bd2c7d9d7b5b39e92fbffefa331 to your computer and use it in GitHub Desktop.
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
library(tidyverse) | |
library(patchwork) | |
set.seed(8) | |
data = expand.grid( | |
x = 1:2, | |
subject = 1:20 | |
) %>% mutate(y = runif(40)) | |
# attention check | |
data = data %>% | |
mutate(attn_check_pass = !(x == 1 & y > 0.5) ) %>% | |
group_by(subject) %>% | |
mutate(attn_check_pass = mean(attn_check_pass) == 1) | |
# plot without exclusions | |
ggplot(data) + | |
aes(x=x, y=y) + | |
geom_point() + | |
geom_line(aes(group=subject), color="blue", alpha=0.25) + | |
geom_smooth(method="lm") + | |
labs(title="All data") + | |
# confounding attention check | |
data %>% | |
filter(attn_check_pass) %>% | |
ggplot() + | |
aes(x=x, y=y) + | |
geom_point() + | |
geom_line(aes(group=subject), color="blue", alpha=0.25) + | |
geom_smooth(method="lm") + | |
labs(title="Drop if fail confounding attention check") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment