# 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