brms/Stan/C++/R issue,

Dear all. I found an issue for implementing a brms model:

# Fit Bayesian mediation model
> f2 <- bf(NA_AFF ~ C3a)
> f3 <- bf(C4pa ~C3a+NA_AFF)
> m2 <- brm(f2 + f3 + set_rescor(FALSE), data = dat, cores = 4)
Compiling the C++ model

I aim to use the mediation() function from the bayestestR package. .But it does not find the brm model (m2). Also, it does not appears in the R studio environment:

mm <-mediation(m2)
Error in mediation(m2) : object ‘m2’ not found

I first contacted the maintainer of the bayestestR package, and he confirmed the problem was more related to brms/rstan.

Operating System: Windows 10
brms Version: 2.13.0

Thanks in advance for your comments.

Hi JulianG,

after you run m2 <- brm(f2 + f3 + set_rescor(FALSE), data = dat, cores = 4) do you get any error messages? Maybe try m2 <- brm(f2 + f3 + set_rescor(FALSE), data = dat, chains= 1, cores = 1) first to see all the output from sampling in the console. Maybe something goes wrong there?

Hey Julianquandt,
Thanks for replying. I tried your suggestion:

> library(mediation)
> library(brms)
> library(bayestestR)
> # load sample data
> mDATA_aff <- read_excel("D:/I2/CAPs/results/k8/Schaefer/med_ana/dat_med.xlsx", sheet = "AFF")
> dat <- as.data.frame(mDATA_aff)
> 
> # Fit Bayesian mediation model
> f2 <- bf(NA_AFF ~ C3a)
> f3 <- bf(C4pa ~C3a+NA_AFF)
> m2 <- brm(f2 + f3 + set_rescor(FALSE), data = dat, chains= 1, cores = 1)
Compiling the C++ model
> 
> mm <-mediation(m2)
Error in mediation(m2) : object 'm2' not found

But unfortunately the output is the same.

so nothing is happening after it says Compiling the C++ model without throwing any errors? Does it even say start sampling at some point?

Nothing. I literally sent you everything I get

are you able to run other brms/rstan models; if you haven’t tried try e.g. brm(weight ~ Time, ChickWeight)? is rstan set up correctly?

Good Point. I ran:

> brm(weight ~ Time, ChickWeight)
Compiling the C++ model
> m3 <-brm(weight ~ Time, ChickWeight)
Compiling the C++ model
> m3
Error: object 'm3' not found

And I get the same pattern: No brms object found,

I’ve previously installed rstan package version 2.21.1. My r version in 4.0.2

what do you get when you type traceback() in the console?

For future reference:

seems like the discussion was moved to another thread and solved there.

Hi Julianquandt. Sorry for not getting back to you. I got “cut” by the forum itself. It said that I exeeded the limit of 3 answers… please wait 3 hours. Anyway, your input helped me to solve the issue faster in the new thread. Thank you very much, and once more, sorry for not getting back to your earlier.

1 Like

no worries :), good to hear that the problem was solved! I already figured something like this was the case and thought it might be useful for other people that might end up here to be linked to the solution.