library(tidyverse)
library(brms)
example_data <- tibble(outcome = c(rep(1, 200),
sample(2:31, 200, replace = TRUE),
rep(32, 150))) |>
mutate(outcome_0 = outcome - 1) |>
mutate(outcome_collapsed = case_when(
outcome == 1 ~ "1",
outcome >= 2 & outcome <= 31 ~ "2-31",
outcome == 32 ~ "32"
)) |>
mutate(outcome_collapsed = factor(outcome_collapsed, ordered = TRUE))
ggplot(example_data, aes(x = outcome)) +
geom_histogram(binwidth = 1, boundary = 0, color = "white")
model_zero_poisson <- brm(
bf(outcome_0 ~ 1),
data = example_data,
family = zero_inflated_poisson(),
cores = 4, refresh = 0
)
pp_check(model_zero_poisson)
model_mixture_poisson <- brm(
bf(outcome ~ 1),
data = example_data,
family = mixture(poisson, poisson),
cores = 4, refresh = 0
)
pp_check(model_mixture_poisson)
ggplot(example_data, aes(x = outcome_collapsed)) +
geom_bar()
model_collapsed <- brm(
bf(outcome_collapsed ~ 1),
data = example_data,
family = cumulative,
cores = 4, refresh = 0
)
pp_check(model_collapsed, type = "bars")
Created on 2023-03-30 with reprex v2.0.2
Whoa, this is awesome @dmi3kno—thanks!