5

I am working on a problem where, given the binomial probability density function: $$X(p,n,k) = \left(\frac{n!}{k!(n-k)!}\right)p^k(1-p)^\left(n-k\right)$$ I need a function $Y(p,n,x) = k$ where $p, n$ and $k$ carry the same meanings as the parameters in the binomial distribution, and $x$ is a random number $\in [0,1]$ chosen via an arbitrary random process.

The purpose of $Y$ is to allow for the random generation of integers, $k \in [0,n]$, for a given value of $p$ and $n$, via the random parameter $x$, such that the likelihood of generating k is exactly $X$. I need a closed form for $Y$ or an approximation method that is not stochastic. There are functions in the C++ standard library that claim to provide this functionality but are somehow internally stochastic and inconsistent across hardware/operating system changes are therefore unusable to me.

I've seen a similar question posed in this stack exchange page but it did not provide what I am looking for.

Is such a function $Y$ even possible? In attempting to solve it myself I came across this stack exchange page on calculating the inverse of $n!$ using the Lambert W function, which I will need some time to fully understand before I can comfortable use in my work. An additional issue with the $W$ function is that I would eventually need an algorithmic way to represent $W$ in a computer program.

VRR
  • 129
  • 2
    Are you looking for a function $k(x):[0,1] \to {0,1,2,\ldots,n}$ that given a uniform random $x$ produces a $k(x)$ binomially distributed with parameters $n$ and $p$? If so this is the inverse of the cumulative binomial distribution function, often called the quantile function. It is not difficult to program - in R it is called qbinom() - but it is not what your question says. – Henry Oct 26 '18 at 21:46
  • @Henry I will look into this possibility, though for the moment I am not certain they are the same. – VRR Oct 26 '18 at 21:53
  • Also, if you're using R you can use rbinom() to generate binomial random variates. If you fix a seed then you get the same sequence of values each time. – Trevor Gunn Oct 26 '18 at 21:54
  • Wikipedia gives two references for generating binomial variates. – Trevor Gunn Oct 26 '18 at 21:56

1 Answers1

1

More than a full answer, this is a first step in looking for a solution.

P_Inv_Bin_1

Consider a function $f(k)$ such that $$ \Delta \,f(k) = \Delta \,x = \left( \matrix{ n \cr k \cr} \right)p^{\,k} \left( {1 - p} \right)^{\,n - k} $$

That is precisely the Cumulative of the binomial distribution you give $$ C_X (k\,;\,n,p) = \sum\limits_{j = 0}^{k - 1} {\binom{n}{j} p^{\,j} \left( {1 - p} \right)^{\,n - j} } $$

We shall make it continuous in $k$, using
for the sum the Indefinite Sum, i.e.
$$ \eqalign{ & \Delta F(x) = F(x + 1) - F(x) = f(x)\quad \Rightarrow \cr & \Rightarrow \quad F(x) = \Delta ^{\, - 1} f(x) = \sum\nolimits_{\;j = 0}^{\;x} {f(j)} \cr} $$

So we write $$ C_X (k\,;\,n,p) = \left( {1 - p} \right)^{\,n} \sum\nolimits_{\;j = 0}^{\;k} {\binom{n}{j}\left( {{p \over {1 - p}}} \right)^{\,j} } $$

The floor of its functional inverse (in $k$) is then the function you are looking for.

But unfortunately there is no close expression available for the partial sum on the lower index of a binomial.

G Cab
  • 35,272