Identifying the number of iterations used for a model after fitting

Dear all,

This might be a silly question, but I’m wondering if there is a way to identify the number of iterations used for a model after the model is fit. Is the number of iterations used still derivable from the model summary or any other matrices?

It depends on what you’re working with.

If you fitted through one of the interfaces (rstan,cmdstanr, etc.), the resulting fit objects have the various metadata included that you can query.

If you have the CSV files from fitting a model with cmdstan, then they have the metadata (iterations, etc) at the top of the file.

I’m using this:


m1 <- brm(
  vorsi ~ position+poa+
    (1| sub) +
    (1| word),
  data = d1,
  sample_prior = TRUE,
  family = gaussian(),
  core=28, iter = 15000,warmup = 6000,
  init = 0, 
  backend = "cmdstanr",
  control=list(adapt_delta=0.999,max_treedepth=15),
  seed=111)

iter = 15000

This means that 15000 iterations were used per chain

Sorry if it is unclear, my question is about retrieving the number of iterations used after the model is fit. Is there a way to retrieve this info? More specifically, I have a model fit and would like to query the number of iterations used in this model. Assuming that I do not have access to the model structure where I can see iter = 15000. I hope this makes clearer now.

If you call summary() on a brm object, then the number of iterations should be printed at the top. For example:

> summary(fit1)
 Family: poisson 
  Links: mu = log 
Formula: count ~ zAge + zBase * Trt + (1 | patient) 
   Data: epilepsy (Number of observations: 236) 
  Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
         total post-warmup draws = 4000
2 Likes

Thanks!
Not sure how I overlooked this bit.

If you need this number to be returned for use in a script, you can also do brms::ndraws (see also brms::niterations and brms::nchains)

1 Like