Simulating from Posterior Predictive with a Custom Likelihood


I’m wondering how to randomly generate values from my custom likelihood?

My understanding is I need to generate simulated data alongside my observed data to perform leave-one-out cross-validation with LOO (Stan - Loo).

I can see that this is simple when using one of STAN’s pre-specified likelihood functions: 27.1 Simulating from the posterior predictive distribution | Stan User’s Guide.
I have a fairly complicated custom likelihood function that I use in my model. Is there an easy way to randomly sample from this function?


Here are some suggestions:

  1. Can you do inverse transform sampling on your likelihood? Or does it have any relationship with a more standard probability density? I have done both for my own work.

  2. You can always do the simulation outside of Stan.

Can you share what your likelihood looks like?

This is not correct. You need the pointwise log-likelihood for LOO.

You can achieve this by generating random uniform values and transforming them by the inverse CDF. Again, you don’t need to do this for loo, but answering for completeness.

If anybody is interested, I gave a summary of what I ended up doing in this thread here: Compound Sampling-Binomial? - #13 by freddie090

(I went option #2 @sonicking - the likelihood is quite fiddly!)