I want to generate the posterior predictive distribution in a bivariate meta-analysis using brms. The model is described as (ref):
And here is the posterior predictive distribution:
As shown below, one needs to use brms::fcor() to include the within-study covariance-variance matrix in the brms model. However, I have never generated the posterior predictive distribution in a model with fcor(). I tried to apply the brms::posterior_predict() syntax I usually use for univariate meta-analysis models (no fcor()), but I get the following error:
Error: Dimensions of ‘M’ for FCOR terms must be equal to the number of observations.
I don’t understand it. Could anyone give me some light on this topic? See full code below.
Thanks!
# Install/load packages
pacman::p_load(brms,
tidybayes,
tidyverse)
pacman::p_load_gh("stan/cmdstanr",
"wviechtb/metafor") # for {metadat} and vcor()
# Load dataset with two correlated outcomes
dat = metadat::dat.berkey1998
### construct variance-covariance matrix assuming within-study correlation = 0.5
V = metafor::vcalc(vi, cluster=author, type=outcome, rho=0.5, data=dat)
# Specify formula
mf2 =
brms::bf(yi ~ 0 + outcome + (0 + outcome|author) + fcor(V))
# Fit model
m2 = brms::brm(
formula = mf2,
prior =
prior(constant(1), class = "sigma"),
data = dat,
data2 = list(V = V),
family = gaussian,
warmup = 5000, iter = 10000,
chains = 4,
seed = 123,
backend = "cmdstanr"
)
## see ?brms::fcor for further details on formula syntax and data2 argument
## see https://bit.ly/34tHcUU for explananations on the "constant(1) prior"
## and formula syntax
m2
nd = data.frame(author = "new",
outcome = c("AL", "PD"))
brms::posterior_predict(object = m2,
newdata = nd,
re_formula = NULL,
allow_new_levels = TRUE,
sample_new_levels = "gaussian")