 # Data imputation in multilevel meta analysis brms

Please also provide the following information in addition to your question:

• Operating System: R 4.0.0
• brms Version: 2.12.0

Dear all,

I am conducting a multilevel meta-analysis in brms. Some of my predictor variables I was unable to obtain in the studies and in requests to authors. So, somehow I have to impute this data. I used the “mice” package according to the brms vignette. However, the model releases the following message: `"Error: Argument 'data' must be coercible to a data.frame"`

My question is whether there is a way to impute this data in this model of analysis. Below is a reproducible example of my analysis.

Thank you for your attention!
Best

``````    #covariance matrix of outcomes
cor_matrix <- function(x, r, v = rep(1, length(x)), na.rm = FALSE) {
mat <- diag(v)
se <- sqrt(v)
se[is.na(se)] <- 0
if (length(x) > 1L) {
for (i in 2:nrow(mat)) {
for (j in 1:(i-1)) {
if (x[i] == x[j]) {
mat[i, j] <- mat[j, i] <- r * se[i] * se[j]
}
}
}
}
dimnames(mat) <- list(1:nrow(mat), 1:ncol(mat))
if (na.rm) {
keep <- !is.na(diag(mat))
mat <- mat[keep, keep]
}
mat
}

#data
dat <- data.frame(
yi = rnorm(20),
level = factor(c(1, 1, "NA", "NA", "NA", 1, "NA", "NA", 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, "NA", 4)),
log_time = rnorm(20),
exer = rnorm(20),
study_ID = 1:20,
vi = 0.25
)

#data imputation
library(mice)
imp <- mice(dat, m = 5, print = FALSE)

#prior
prior <-c(prior(normal(0, 100), class = Intercept),
prior(normal(0, 10), class = b),
prior(cauchy(0, 10), class = sd))

#matrix
v.m1 <- cor_matrix(dat\$study_ID, r = 0.9, v = dat\$vi)
cor_obs <- cor_matrix(dat\$study_ID, r = 0.9)

#model
m1 <- brm(bf(
yi ~ 1 + log_time + level + exer + (1|study_ID) + fcor(v.m1),
sigma = 1
),
family = gaussian(),
prior = prior, chains = 1,
data2 = list(v.m1 = v.m1),
control = list(adapt_delta = 0.99), data = imp)``````

Sorry, it seems your question fell through - maybe @torkar can answer?

2 Likes

Hi,

not sure I can provide much here except,

1. `brms` has direct support for using `mice`. See Paul’s excellent guide here.
2. If it’s any help you can check out this which I’ve written.

If you only have missingness in predictors (independent variables/covariates) then I would recommend you to model that directly, i.e., what Paul refers to as: Imputation during model fitting, in the link above.

1 Like

Hi,

Thank you for the answers @torkar and @martinmodrak.

I found the problem, instead of using `m1 <- brm(bf...` the folowing code
`m1 <- brm_multiple(bf...` must be used.

However, the imputation during model fitting seems to be preferable from the point of view of computation time.

1 Like

Indeed, I didn’t spot that. And you’re right, `brms` will re-samples x times. In the old days x=5, but now they say one should set x to the number of % missing in the data. So if you have 20% missingness, then x=20, so `brms` would need to sample 20 times… :)

1 Like