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){
m1<-sample_mean[i,2]
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.

FWIW

  • Operating System: Windows 10
  • brms Version: 2.10

update(): https://rdrr.io/cran/brms/man/update.brmsfit.html

1 Like