A test will succeed with a certain percentage. Now this test is repeated X number of times. I want to be able to get an estimate of the total number of succeeded test.
Given that I know both the probability of success and the X number of attempts, is it possible to symbolically compute this estimate?
I want to use this in a piece of software. Where I generate a random value [0, 1] and then use the requested formula as a mapping function.
From what I gathered I need a quantile function of binomial distribution? Can I compute or estimate that one symbolically?
Suppose a fair die is rolled $n = 60$ times, then the number $X$ of Ones seen is $X \sim \mathsf{Binom}(n=60, p = 1/6).$ The expected number of Ones seen is $E(X) = np = 60(1/6) = 10.$ The probability of seeing exactly 10 Ones is $$P(X = 10) = {60 \choose 10}\left(\frac 1 6\right)^{10} \left(\frac 5 6\right)^{50} = 0.1270131.$$
PDF: The binomial PDF (or PMF) is defined as $f_X(k) = {n \choose k}p^k(1-p)^{n-k},$ for $k = 0, 1, \dots, n.$ In R statistical software, $f_X(10),$ for $n=60,\, p=1/6,$ can be computed by using the displayed formula or by using the built-in PDF
dbinom:CDF: The CDF is defined as $F_X(k) = P(X \le k),$ for any real value of $k.$ In our example for $k < 0,$ we have $F_X(k) = 0$ and for $k > n = 60,$ we have $F_X(k) = 1.$ From $k=0$ through $60,$ the CDF (denoted
pbinomin R) is a 'pure jump' function, which can be plotted as shown below:Blue dots emphasize that the value of the function $F_X(k)$ is the upper end of each vertical segment.
Inverse CDF: The 'quantile function' of $\mathsf{Binom}(60, 1/6)$ is the inverse of the CDF. In general, $F_X^{-1}(q) = c$ means $P(X \le c) = F_X(c) = q,$ for $0 < q < 1.$ In our example, the quantile function of $X$ can be used to get an interval in which values of $\mathsf{Binom}(60, 1/6)$ will lie with probability (just barely over) 95%. Specifically, $P(5 \le X \le 16) = P(X \le 16) - P(X \le 4) = 0.96.$ (Because of the discreteness of the binomial distribution it is not possible to get probability 0.95 exactly.)
The plot of the quantile function is shown below with horizontal dotted lines at 5 and 16:
Using the quantile function to simulate a random sample: Finally, you can use the quantile function to simulate values of $X \sim \mathsf{Binom}(60, 1/6)$ from values of $U \sim \mathsf{Unif}(0,1).$ Below we use 10,000 standard uniform random variables to simulate as many values of $X,$ for which $\bar X \approx E(X) = 10.$ (Notice that values of $X$ above about 20 or 25 are very rare.)
Below is a histogram of the simulated random sample of 10,000 observations from $\mathsf{Binom}(60, 1/6);$ centers of superimposed open circles show exact binomial probabilities. (The fit is about as good as can be anticipated for a sample of 10,000; a sample of a million values would give a much better match.)
Notes: (a) If you use the same seed (in
set.seed) as mine for the pseudorandom number generator in R, you will get exactly the same 10,000 observations I did. If you set a different seed, your results may be a little closer to (or farther from) a perfect fit than mine. [If you set no seed, R will pick an undisclosed, unpredictable seed from the system clock.] (b) R has a built-in functionrbinomfor generating random binomial samples. Essentially,runif(qbinom(m, n, p))is the same asrbinom(m, n, p), but the latter has slight modifications for more efficient running.