Skip to content

Instantly share code, notes, and snippets.

@mcfrank
Created October 10, 2019 21:22
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 mcfrank/b238e12633d29f8f6d597df11b6ae4ec to your computer and use it in GitHub Desktop.
Save mcfrank/b238e12633d29f8f6d597df11b6ae4ec to your computer and use it in GitHub Desktop.
Sample categorical regression with table turning
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