I’m constructing a multi-level model, and would like to plot the multi-level effects. I thought mcmc-intervals() was useful, but I couldn’t extract particular variables I intended to. I would like to extract the plots of Year effects for each environmental variable (ex. Builtup) . When I set regex_pars = paste("r_Year")
, the results included all “r_Year_environmental variables” and “cor_Year…”.
bmodel<- brm(amount ~ Builtup + Kinetic_energy + Railway + Road + tide + Rocky_coast + Cliff_coast + Sandy_coast + Artificial_coast + Mud_coast +
offset(volunteers) +
(1+ Builtup + Kinetic_energy + Railway + Road + tide + Rocky_coast + Cliff_coast + Sandy_coast + Artificial_coast + Mud_coast|Year),
data = dms,
family = gaussian(),
prior = c(set_prior("normal(0,10)", class = "b")),
warmup = 800,
iter = 1500,
chains = 4,
cores = 4,
threads = threading(14),
save_all_pars = TRUE,
backend = "cmdstanr",
control = list(adapt_delta = 0.999, max_treedepth=20),
save_model = "test_stanscript",
file = "test")
ma <- mcmc_intervals(
bmodel,
regex_pars = paste("r_Year"),
prob = 0.95,
point_est = "median",
point_size = 1,
) +
geom_vline(xintercept = 0, color = "red", alpha = 0.6, lwd = .8, linetype = "dashed") +
labs(
title = "Effect of Environmental Variables in Each Year",
subtitle = "multi-level model: varying intercept and slope"
)
ma