# My beta-binomial model has probabilities at exactly 0 and 1. How can I fix it?

The probability that A wins when he/she has $$\alpha$$ points and player B having $$\beta$$ points is equal to

$$p_\text{win}(\alpha,\beta)=\binom{\alpha+\beta+1}{\alpha-1}p^\alpha(1-p)^\beta$$

where $$p$$ is the probability that A wins a point.

Next I implement this into the probability mass function of the binomial distribution

$$\operatorname{Binomial}(n\mid N, p_\text{win})$$

As I result I can infer from $$n$$ and $$N$$ the probability that A wins a point, $$p.$$ However, during the sampling there are a significant amount of zeros and ones for $$p.$$ resulting in the following error:

Probability parameter is 1/inf/nan, but must be in the interval [0, 1]

To overcome this I would like to transform $$p$$ to its unconstrained equivalent, $$x.$$ I use logit parameterization for this

$$\operatorname{BinomialLogit}(n\mid N, x) = \operatorname{Binomial}(n\mid N, \operatorname{logit}^{-1}(x))$$

I am unsure how to rewrite $$p_\text{win}$$ in terms of $$x.$$ to the above. Please advise

• psst... you didn't hear this from me... but you could always $p\gets\textrm{clip}[p,0.0001,0.999]$ Apr 27, 2023 at 13:58
• Perhaps more work, but you might consider building upon the Continuous Bernoulli distribution Apr 27, 2023 at 14:37
• Will zero/one-inflated beta (ZOIB) solve your problem? Apr 27, 2023 at 14:39
• Can you work in log space (sampling $\log(p)$)? Sampling $\log(p)$ directly is fairly straightforward if $p$ is Beta-distributed. Apr 27, 2023 at 21:10
• This question doesn't make sense to me --- you say you are inferring $p$ (which is presumably an unknown parameter?) but then you refer to having values of 0 and 1 for $p$. Please clarify what parts of your problem are data and what parts are unknown parameters. (If you already have known values of zero or one for $p$ then the resulting win probabilities are trivial, so I don't see the problem.)
– Ben
May 18, 2023 at 1:32

For some combinations of $$\alpha, \beta$$, the beta distribution concentrates its mass near 0 or 1. One option is to impose a prior on $$p$$. For example, you could consider
$$p \sim \text{Beta}(a + \alpha, b + \beta)$$ where $$a > 0$$ and $$b >0$$, which will bound $$p$$ away from the extremes. Choosing $$a=b$$ might make sense, if you believe the teams are evenly matched prior to playing the game. The larger $$a$$ and $$b$$ are, the lower the variance of $$p$$. The same is true for $$a + \alpha$$ and $$b + \beta$$.
Alternatively, you could implement your idea & re-parameterize the model: draw $$x$$ from some distribution, and then transforming it to the $$[0,1]$$ interval. For instance, $$x \sim \text{Normal}(\mu, \sigma^2)$$ is symmetric about 0 for $$\mu = 0$$ and therefore $$p=\text{logit}^{-1}(x)$$ is symmetric about 0.5 on the probability scale.
The re-parameterization solution is not a panacea, though, because you may not want a symmetric distribution (if the teams are not evenly matched). However, setting $$\mu$$ very far from 0 will risk $$p$$ getting so close to 0 or 1 that the you have the same problem that you do now.
From the perspective of coding, you could write a series if if/then statements to detect p close to 0 or 1. In the case of p=0, you know a binomial distribution will have 0 successes; for p=1 a binomial distribution will have $$N$$ successes.
Or set p = median([p, eps, 1 - eps]) where eps is a small value, such as 1e-6. There's nothing statistically principled about this, it's just a kludge.