I hope that that the following observations are useful. I spent a day on a train coding a Weibull regression model and a flexible parametric survival model using the Stan Math Library to calculate gradient and Hessians. Observations:
- I started with the “Using the Stan Math C++ Library” vignette and the online documentation. This is strong documentation – thank you.
- My first stumble was that, given containers of matching sizes, the
weibull_lpdf()functions return the log sum of probabilities and sum of log probability densities, respectively. For potentially censored data, this is not overly helpful – so I unrolled the vectorised calls into scalar calls using a for loop. (I should have read the documentation more carefully:().
- My major stumble was trying to calculate the Hessian. After some debugging, I was able to use a functor to calculate the objective and gradient functions, but I was not able to get the Hessian to work, with abstruse and voluminous C++ template compiler errors. I eventually found a suggestion at https://discourse.mc-stan.org/t/subtraction/7994 to use
#include <stan/math/mix/mat.hpp>– and suddenly everything worked:). Is there any way to add this include statement to the vignette?
- For a new user, it was unclear when to use
subtract()) and when to use
-, possibly with
.eval()). These were mixed in the vignette – and some guidance may be helpful.
Sincerely, Mark Clements.