I am using the optimizing function in rstan to get a point estimate of my parameters. However, I want to store the log probability of my model for each iteration the optimizer takes. Basically in the end I want to create a plot of the log probabilities vs iteration number.

I know we have the verbose flag in the optimizing function but I can’t seem to find any way to store log probabilities of the model.

Is there a function in rstan that does that or is there some other way to get this?

Any suggestions or pointers would be really helpful.

Thanks

PS: I have edited the model code to remove the unnecessary complexities which aren’t relevant to the question. But if it would be required to answer the question, I would be happy to share it here.

```
model {
target += calculate_lpdf(X| X0);
for(i in 1:N){
Y[,i] ~ multinomial(pi[i]);
}
}
stan_model <- stan_model(file = "mymodel.stan")
optimization_result <- optimizing(stan_model, data = stan_data, verbose=TRUE, hessian = TRUE)
```