How to define initial values in stan() in R

You need a list of lists that is equal to the number of chains. But if you want to use the same initial values for all of the chains (which is not a good idea), then it is better to define a function that returns such as list like

init_fun <- function(...) list(mu=4.5, sigma2=0.05)

and then call

stan(model_code, data, iter = 500, init = init_fun)

However, if you feel the need to specify initial values yourself, then you have probably done something else wrong.

2 Likes