Skip to content

Instantly share code, notes, and snippets.

@steveharoz
Created November 27, 2019 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveharoz/445d8bd2c7d9d7b5b39e92fbffefa331 to your computer and use it in GitHub Desktop.
Save steveharoz/445d8bd2c7d9d7b5b39e92fbffefa331 to your computer and use it in GitHub Desktop.
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