Hi there,
I am carrying out a mediation analysis in brms that contains an ordinal mediator, modelled with the cumulative(probit) family, and a zero-inflated outcome, modelled with the negative binomial family. For example:
bf_med <- bf(m ~ x) + cumulative(probit)
bf_out <- bf(y ~ m + x) + negbinomial()
m1 <- brm(bf_med + bf_out + set_rescor(FALSE), data=df, cores=4)
Based on this post I understand that the different paths must be standardized to calculate the mediation, direct, and indirect effects.
My questions are:
-
To calculate the direct effect of the treatment on the outcome, the x → y pathway, would this be standardized in the same way as the mediator on outcome effect, the m → y pathway? As they are both from the second sub-model.
-
When standardizing the x → y and m → y pathways, how should the negative binomial family be accounted for? I’m guessing exp() should be used somewhere, to inverse the log link function, but should this be used directly on the posterior, after standardization, or is something different required?
The code below is a modified version the simulation/ mediation code from the previous post, but now to simulate y as zero-inflated count data. This is my first attempt at simulation/ reprex, so please let me know if there are any issues.
Thanks,
Josh
library(brms)
library(tidyverse)
set.seed(100)
###Data simulation
n_obs <- 100
x_alpha <- 0
x_sigma <- 1
mx_beta <- 0.5
m_tau <- c(-1, 0, 1)
#regression coefficients
beta0 <- 1
beta1 <- 0.5
# Ordered probit random draws
rop <- function(x, tau){
op <- vector(mode = 'numeric', length = length(x))
n_levels <- length(tau) + 1
probs <- rep(NA, times = n_levels + 1)
probs[1] <- 0
probs[n_levels + 1] <- 1
for(n in 1:length(x)){
probs[2:n_levels] <- pnorm(tau - x[n])
op[n] <- sample(1:n_levels, size = 1, prob = probs[2:(n_levels + 1)] - probs[1:n_levels])
}
op
}
df <- data.frame(row = 1:n_obs) %>%
mutate(x = rnorm(n(), x_alpha, x_sigma),
m = rop(mx_beta * x, m_tau),
y = rnbinom(n_obs, mu = exp(beta0 + beta1*x + m), size = 0.8))
###brms model
bf_med <- bf(m ~ x) + cumulative(probit)
bf_out <- bf(y ~ m + x) + negbinomial()
m1 <- brm(bf_med + bf_out + set_rescor(FALSE), data= df, cores=4)
summary(m1)
###posterior samples and compute the indirect effect (mediation effect) a*b, as per Andrew Johnson approach
s1 <- as_draws_df(m1)
sd_x <- sd(df$x)
sd_y <- sd(df$y)
sd_m <- sd(df$m)
#calculate standardized a, the standardized x -> m pathway
a <- s1$b_m_x * sd_x / ( sqrt( s1$b_m_x^2 + sd_x^2 + 1 ) )
#calculate standardized b, the standardized m -> y pathway - mediator effect
## Q2. exp() in here somewhere?
b <- s1$b_y_m * sd_m / sd_y
#calculate a*b, the indirect effect (mediation effect)
ab <- a*b
## calculate the standardized direct effect, x -> y pathway
## Q1. standardize the same way as for the mediator effect, b?
## Q2. exp() in here somewhere?
direct <- s1$b_y_x * sd_x / sd_y
median(a) ## standardized a
median(b) ## standardized b, mediator effect
median(ab) ## standardized indirect effect
median(direct) ## standardized direct effect
median(ab+direct) ## standardized total effect