Rstan: any init_r counterpart for optimizing to deal with initialization failure?

Hi Stan Friends,
I am relatively new to stan and currently working on a time series model that is a sum of HMM and some special class of Gaussian process (celerite in specific).

It usually takes a long time to run but things work fine when using the sampling function, just usually needs to specify init_r to be larger than the default (e.g. 5 or 10) to start the sampler.

However, sometimes I only need a point estimate to save time. So I tried to use optimizing and I always failed to initialize it with Error in sampler$call_sampler(c(args, dotlist)) : Initialization failed.. So I am wondering if there is any counterpart of init_r for optimizing routine or do I have to find which parameter is causing the trouble then scale it in the model itself?


Weird setting inits for optimization fits actually seems to be unsupported by rstan… I would consider filing this as an issue at rstan’s GitHub repo. However, cmdstanr supports inits for optimization: Run Stan's optimization algorithms — model-method-optimize • cmdstanr so switching to cmdstanr should solve your problem here. (And I personally believe that cmdstanr has become the better interface, although it is currently still not on CRAN).

Best of luck with your model!

Thanks for that! I am using rstan mainly because I need to include some external C++ code and I am not sure if cmdstanr can do that for now. Anyway, thanks again!

1 Like

I didn’t try it myself, but I think cmdstanr should let you use custom C++ code, see e.g. this thread: Custom c++ using cmdstanr? - #9 by rok_cesnovar that shows how to do it - although it is a bit less user friendly than in rstan.