I have a brm model that I'd like to generate predicted values for a fixed value of one parameter (length). I think I need to do this with the posterior_predict function (or possibly the posterior_epred function), but these functions both generate large matrices with no labels so it's impossible to know what is actually being generated.
library(tidyverse)
library(brms)
set.seed(42)
df <- data.frame(mass = rnorm(100, mean = 50, sd = 5),
length = rnorm(100, mean = 20, sd = 2),
sex = sample(c("f", "m"), 100, replace = TRUE),
site = sample(LETTERS[1:3], 100, replace = TRUE))
m <- brm(mass ~ length * sex + site, data = df, prior = prior(normal(0, 10)))
newdata <- data.frame(site = rep(LETTERS[1:3], each = 30),
sex = rep(c("f", "m"), 45),
length = 20)
pred1 <- bind_cols(newdata, predict(m, newdata)) # results in a usable dataframe
pred2 <- posterior_predict(m, newdata) # results in a large matrix with no labels
pred3 <- posterior_epred(m, newdata) # results in a large matrix with no labels
ggplot(data = pred1, aes(x = Estimate, y = site, col = sex)) + geom_violin()

posterior_predictandposterior_epredis explained in the documentation (sort of like the difference between a prediction interval and confidence interval of the mean, in a frequentist analysis).add_predicted_drawsandadd_epred_drawswhich give "tidy" versions of the two different types of posterior predictions.newdata |> add_predicted_draws(m) |> median_qi(). This will give 95% equal tailed credible interval by default but other options are possible