I made a notebook which demonstrates how to define probability functions in Stan language and use them for building the model, ppc, loo and predictions. I use geomagnetic storms and generalized Pareto distribution as an example. The notebook geomagnetic.Rmd is in github https://github.com/avehtari/BDA_R_demos/blob/master/demos_rstan/

And for easier viewing here’s a pdf

geomagnetic.pdf (427.7 KB)

Any feedback is welcome. I’m not certain if there is enough for a Stan case study, but at least this should be useful example for defining user defined probability distributions.