Does the init argument work with cmdstanr?

Hey Charles, inits for vector parameters seem to work for me. For example:

library(cmdstanr)

file <- write_stan_tempfile(
  "parameters {
   real alpha;
   vector[2] beta;
  }
  model {
   alpha ~ normal(10, 1);
   beta ~ normal(-10, 1);
  }
  "
)
mod <- cmdstan_model(file)

inits_chain1 <- list(alpha = 15, beta = c(-5, -10))

fit <- mod$sample(chains = 1, init = list(inits_chain1), save_warmup = TRUE)
draws <- fit$draws(inc_warmup=TRUE)
posterior::as_draws_matrix(draws)[1, ]

The first row has the values of my inits:

# A draws_matrix: 1 draws, and 4 variables
    variable
draw lp__ alpha beta[1] beta[2]
   1  -25    15      -5     -10

If you’re seeing different behavior a minimal example demonstrating it would be super helpful.

1 Like