Last active
September 28, 2021 07:44
-
-
Save steveharoz/b418b27b0afdd9a5d2591a2ffa2eb189 to your computer and use it in GitHub Desktop.
ggdist psychometric functions
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(ggdist) | |
# make some data | |
expand_grid( | |
condition = c("A", "B"), | |
stimulus = seq(-3,3,0.3), | |
repetitions = 1:20 | |
) %>% | |
# make some noisy response data | |
mutate(response = round(pnorm(stimulus + rnorm(n()) + (condition == "A")*2-1))) %>% | |
# evenly distribute the x positions over 5 sub-bins | |
group_by(condition, response, stimulus) %>% | |
mutate(stimulus_spread = stimulus + (0:(n()-1) %% 5 - 2)/5*.3) %>% | |
ungroup() %>% | |
# plot it | |
ggplot() + | |
aes(x = stimulus_spread, y = response, color=condition, fill=condition) + | |
ggdist::stat_dots( | |
alpha = 0.5, # lower contrast | |
binwidth = .3/5, # size of a sub-bin | |
color = NA, # no outline | |
orientation = "horizontal", | |
aes(side=ifelse(condition=="A", "bottom", "top")) | |
) + | |
geom_smooth(method = "glm", method.args = list(family = "binomial")) + | |
scale_color_manual(values = c("#4DAF4A", "#984EA3")) + | |
scale_fill_manual(values = c("#4DAF4A", "#984EA3")) + | |
scale_y_continuous(breaks=c(0,0.5,1), labels=c("left", "", "right"), minor_breaks=FALSE) + | |
labs(x="stimulus (right minus left)") + | |
theme_minimal(16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment