# Log-logistic distribution sampling functions et al

Hi, in the reference for available distributions there is no docs for the log-logistic distribution. In this forum there is only thread about this and it was self-written. Do we have an official one exist somewhere? Thanks.

If it’s not in the docs and that’s the only forum reference you found, it’s probably not there.

If you need a custom distribution that isn’t included in Stan, there are workarounds. Check: https://mc-stan.org/docs/2_18/stan-users-guide/user-defined-probability-functions.html and https://mc-stan.org/docs/2_18/reference-manual/increment-log-prob-section.html

Going from the Wikipedia definition of the log-logistic (for p(x | \alpha, \beta)), you could probably do something like:

target += log(beta) - log(alpha) + (beta - 1) * (log(x) - log(alpha)) - 2 * log1p(pow(x / alpha, beta))


Thanks, I could get these likelihood done, but as mentioned in the title, the main concern is the random sampling function *_rng for use in generated quantities block. Not sure how to implement that?

Actually, “sampling function” isn’t as clear as you’d hope it’d be, since the likelihood is also known as the “sampling model”.

With regard to the random variate generation, here’s a hint from Wikipedia [if you can’t take it from here I’ll try and help out more later]:
If X \sim \text{log-logistic}(\alpha, \beta) then \log(X) \sim \text{logistic}(\log(\alpha), 1/\beta). To generate a logistic random variate Y with parameters a and b, we can generate U \sim \text{uniform}(0, 1) and then make Y = a + b (\log(U) − \log(1 − U)). Setting a = \log(\alpha) and b = 1/\beta and letting X = \exp(Y) should get you what you need. Please check the calculations as I haven’t had time to do so.

3 Likes