Refit model with different Y's efficiently in brms

Hi, I want to refit a simple model >18,000 times. The model estimates the mean and SD of some characteristic of a plant species based on several species-specific observations. Each time, the response variable is a new species and I set the sample mean of that species as the prior for the mean.

Is there a way to avoid recompiling if you change the response variable?

I now coded it as a for loop:

for (i in 1:N){
stanvars <- stanvar(m1, name=β€˜m1’)
bprior <- prior(normal(m1,2), class = Intercept) + prior(cauchy(0,2), class = sigma)
fit <- brm(paste(colnames(df2[i]), β€œ~ 1”),data = df2, family = gaussian(), prior = bprior,chains=2, iter = 1000,stanvars=stanvars)

I was first thinking of fitting a multilevel model with each species as a grouping variable, but I don’t know if that’s feasible with 18,000 species.


  • Operating System: Windows 10
  • brms Version: 2.10


1 Like