How to find out which statement the error occurred at

I am finally executing my model. I get a

Rejecting initial value:
Log probability evaluates to log(0), i.e. negative infinity.
Stan can’t start sampling from this initial value.

Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
Initialization failed.

This is after all the data have been fed. How do I find out which statement caused the error?

Have you upgraded to 2.16 of cmdstan/Rstan whatever Stan you’re using? In 2.15 some of the error messages were getting hidden accidentally. If not, try that. If you have, best bet is to just run through the model commenting out sections till to find what’s triggering it.

Usually errors like that are from constraints messed up (like trying to use a negative standard deviation) or from indexing errors. Feel free to post the model.

its 2.16. My model is really big, so I don’t think I want to post it all. I thought there would be some kind of debugging message that I can turn on.

The log probability errors are hard because Stan just checks the value of log prob at each model evaluation and doesn’t keep track of where it underflowed. You can debug these by adding print statements every time you have a ~ or target+= evaluation to track it down.

Other errors often are sometimes reported with a line number, and sometimes not (eg dimension mismatches).

it’s not the case that any one statement is wrong; this message indicates that the sampler cannot initialize the unconstrained parameters of the model. check the parameters and the priors you’re putting on them.

I got thru all the bugs by inserting lots print statements.

print debugging is a valid technique.
and TRON stands for “trace on” - who knew?


The messages should be showing up in 2.16. Are you running in a single chain or multiple chains in parallel?