# Fractional logit in Stan with code

Hi all -

For my ordered beta regression paper (https://osf.io/preprints/socarxiv/2sx6y/) I had to implement a fractional logit model in Stan, the code for which is available in the paper repo:

I am posting here as this model is popular in some fields and it came up on Twitter recently. I believe this is the correct version, but note that the model is a “pseudo-likelihood” which means it’s not a real statistical distribution. As such… it doesn’t work very well in an MCMC set. up, and I don’t recommend it in general as the posterior has inflated variance and a lot of useful tools (simulation-based calibration, etc) aren’t available.

But if you need it… there it is.

7 Likes

It is possible to normalize this distribution, see Fractional logit model in Stan - #2 by bbbales2

\int_{0}^{1} p^{x}(1-p)^{1-x} d x=\frac{1-2 p}{2 \tanh ^{-1}(1-2 p)}

However, the parameter p doesn’t really mean anything, but the mean of the distribution is \int_{0}^{1} \frac{x p^{x}\left((1-p)^{1-x}\left(2 \tanh ^{-1}(1-2 p)\right)\right)}{1-2 p} d x=\frac{p}{2 p-1}+\frac{1}{2 \tanh ^{-1}(1-2 p)}, a function of p with no analytical functional inversion.
(picture from Wolfram Alpha)

In addition the distribution is undefined when p=0.5, but the limit is 1.

It should be possible to add a RNG with inverse transform sampling based on the inverse CDF: x=\frac{\log \left(-\frac{p-1}{2 p q-p-q+1}\right)}{\log (1-p)-\log (p)}

(CDF: \int_{0}^{x} \frac{p^{x}(1-p)^{1-x}\left(2 \tanh ^{-1}(1-2 p)\right)}{1-2 p} d x=-\frac{p^{x}(1-p)^{1-x}+p-1}{1-2 p}=q)

That being said, it is still a fairly worthless distribution.

EDIT: Fixed some derivations. Some step were incorrect, yielding the rest incorrect.
Addition: This is, as pointed out by @spinkney, also known as the continuous Bernoulli distribution.

Does this simplify to the continuous Bernoulli? Continuous Bernoulli distribution - Wikipedia

2 Likes

It seems so! Good catch! Since p(x \mid \lambda) \propto \lambda^{x}(1-\lambda)^{1-x}, \int_{0}^{1} \lambda^{x}(1-\lambda)^{1-x} d x=\frac{1-2 \lambda}{2 \tan ^{-1}(1-2 \lambda)}, which I derived the rest of my results on.

1 Like

That does look oddly similar. It is also interesting that the Wikipedia shows a connection to the Beta distribution, though it seems like it will only do so for certain parameter values.