Created
October 10, 2019 21:22
-
-
Save mcfrank/b238e12633d29f8f6d597df11b6ae4ec to your computer and use it in GitHub Desktop.
Sample categorical regression with table turning
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(brms) | |
library(langcog) | |
d <- tibble(subject = c(1, 1, 1, 1, 2, 2, 2, 2, | |
3, 3, 3, 3, 4, 4, 4, 4), | |
response = c("E",NA,"A","error", | |
"E","E","E","error", | |
"A","A","E","error", | |
"A","A","A","A"), | |
condition = c(rep("Expt", 8), rep("Cntl", 8))) | |
ms <- d %>% | |
filter(!is.na(response)) %>% | |
group_by(subject, response, condition) %>% | |
count %>% | |
spread(response, n, fill = 0) %>% | |
gather(response, n, A, E, error) %>% | |
group_by(subject, condition) %>% | |
mutate(prop = n / sum(n)) %>% | |
group_by(condition, response) %>% | |
multi_boot_standard(col = "prop") | |
ggplot(ms, | |
aes(x = response, y = mean, fill = condition)) + | |
geom_bar(stat = "identity", position = "dodge") + | |
geom_linerange(aes(ymin = ci_lower, ymax = ci_upper), | |
position = position_dodge(width = .9)) | |
mod <- brm(data = d, | |
formula = response ~ condition + (1 | subject), | |
family = "categorical") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment