Unexpected results from logistic regression model

I can’t quite sort through all the plumbing of the original specification. However, I would strongly recommend avoiding “hand-coded” specifications like this. Indexing is difficult enough as it is. The idea of building up parameters and likelihoods bit by bit seems fraught to me.

Also, if you are needing to set max_treedepth and/or set target_accept=.97, you may have issues with your model specification.