admin管理员组

文章数量:1391960

I'm trying to set some global options for iterations and chains in brms to avoid specifying them explicitly in each model call, as I have a very long script with many models. According to the documentation, I tried setting the following options globally, but they don't work:

library(brms)

options(
  brms.iter = 100,          # Does not work
  mc.iter = 100,            # Does not work
  brms.chains = 1,          # Does not work
  mc.chains = 1,            # Does not work
  mc.cores = 4,             # Works, but confusing because it's not brms.cores
  brms.backend = 'cmdstanr' # Works
)

mdl <- brm(speed ~ dist, data = cars)

What's the correct way to globally control the number of iterations and chains?

I'm trying to set some global options for iterations and chains in brms to avoid specifying them explicitly in each model call, as I have a very long script with many models. According to the documentation, I tried setting the following options globally, but they don't work:

library(brms)

options(
  brms.iter = 100,          # Does not work
  mc.iter = 100,            # Does not work
  brms.chains = 1,          # Does not work
  mc.chains = 1,            # Does not work
  mc.cores = 4,             # Works, but confusing because it's not brms.cores
  brms.backend = 'cmdstanr' # Works
)

mdl <- brm(speed ~ dist, data = cars)

What's the correct way to globally control the number of iterations and chains?

Share Improve this question asked Mar 14 at 8:36 matmat 2,6395 gold badges37 silver badges79 bronze badges 3
  • discourse.mc-stan./t/… The answer to this question may be helpful – Coco Q. Commented Mar 14 at 9:03
  • 1 In brms, global options for iterations and chains can't be set via options(). Instead, specify them in each brm() call or use a custom wrapper function to apply defaults. – Szymon Roziewski Commented Mar 14 at 9:06
  • @SzymonRoziewski thanks. Can you post a response so I can validate it and close the thread? – mat Commented Mar 14 at 12:10
Add a comment  | 

1 Answer 1

Reset to default 1

In brms, there isn't a direct way to globally set the number of iterations and chains using R's global options. However, you can work around this limitation by defining default arguments with a custom wrapper function for your models.

brm_custom <- function(..., iter = 2000, chains = 4, cores = 1) {
  brm(..., iter = iter, chains = chains, cores = cores)
}

mdl <- brm_custom(speed ~ dist, data = cars)

本文标签: How to globally set iterations and chains in R brmsStack Overflow