Hi
I have a few questions regarding brms and its applications with tidybayes. The models I used are the following, where the parameter behandling_dummy is binary, 0 or 1:
model_1 <- brm(n|trials(N) ~ behandling_dummy + (1 + behandling_dummy|studie),
data = Lancet_data, family = binomial(),
prior = prior_sc)
model_2 <- brm(n|trials(N) ~ behandling_dummy*respirator_dummy +
(1 + behandling_dummy*respirator_dummy|studie) + (1|infektion),
data = Lancet_data, family = binomial(), prior = prior_sc,
control = list(adapt_delta = 0.99, max_treedepth = 20))
I am trying to create forest plots with my models using tidybayes and the code I use to do this is taken from:
Instead of the intercept, I wanted study specific effect for behandling_dummy in odds-ratio so I had to change the code accordingly:
study.draws <- spread_draws(model_1, r_studie[studie,behandling_dummy], b_behandling_dummy)%>%
mutate(b_behandling_dummy = r_studie + b_behandling_dummy)
pooled.effect.draws <- spread_draws(model_1, b_behandling_dummy)%>%
mutate(studie = "Pooled Effect")
forest.data <- bind_rows(study.draws, pooled.effect.draws) %>%
ungroup() %>%
mutate(b_behandling_dummy = exp(b_behandling_dummy)) %>%
mutate(studie = str_replace_all(studie, "[.]", " "))%>%
mutate(studie = reorder(studie, b_behandling_dummy))
forest.data.summary <- group_by(forest.data, studie) %>%
mean_qi(b_behandling_dummy)
ggplot(aes(b_behandling_dummy , relevel(studie, "Pooled Effect", after = Inf)),
data = forest.data) + coord_cartesian(xlim = c(-1, 5)) +
geom_vline(xintercept = exp(fixef(model_1)[2, 1]), color = "grey", size = 1) +
geom_vline(xintercept = exp(fixef(model_1)[2, 3:4]), color = "grey", linetype = 2) +
geom_vline(xintercept = exp(0), color = "black", size = 1) +
geom_density_ridges(fill = "blue", rel_min_height = 0.01, col = NA, scale = 1,
alpha = 0.8) +
geom_pointinterval(data = forest.data.summary, size = 1) +
geom_text(data = mutate_if(forest.data.summary, is.numeric, round, 2),
aes(label = glue("{b_behandling_dummy} [{.lower}, {.upper}]"), x = Inf), hjust = "inward") +
labs(x = "Effect size",
y = element_blank()) +
theme_minimal()
My questions are:
-
Did I change the code to simulate a forest plot correctly according to my needs above?
-
Is it possible to add each studies weight in the plot?
-
How do I simulate a forest plot for the second model now that I have interaction with respirator_dummy which is also binary?
This is my first time using this so I hope my questions were clear. Any help is appreciated, thanks.
- Operating System: MacOS
- brms Version: 2.14.4