Obtain gradient of every target+=

I just implemented a function in R to compute subjectwise gradient contributions from my stan models, useful for misspecification checks, but it would also be wonderful to get observation wise gradients. I can’t see an easy way to do this outside of stan because of the dependencies in the structure, has anyone thought in this direction before? It would be a neat feature, I think…


Maybe code the model such that the Stan model can be configured to only compute the log lik for a specific data item?

Is there a ref for what you are doing?


hmmm true that’s a possibility. Inefficient but perhaps not too bad. I think there are lots of approaches that use the ‘score’ (gradient contribution) for various checks. individual parameter contributions is one small set of work I have some connection to… https://www.tandfonline.com/doi/full/10.1080/10705511.2019.1667240?af=R

1 Like

That is an interesting idea. About subject-wise vs observation-wise, I was involved in a paper where we considered this in the context of LMM. Not sure whether it is helpful, but see Sec 3.1 here: