# follow up: A flips an **unfair** coin 11 times, B 10 times: what is the probability A gets more heads?

• I added a follow up question what if the coin is unfair? to my original question A flips a fair coin 11 times, B 10 times: what is the probability A gets more heads than B?, but the moderators asked me to start a new question

• I believe the "naive approach" in the original question is wrong, it is only correct by accident. Because if they use an unfair coin, where $$p_H$$ is the probability to get head, and if we follow the same "naive method":

For the first 10 times of A, he has the same expected number of heads as B. So if the 11th flip of A results in H, he gets more head than B, so the answer is $$p_H$$.

• this answer is wrong based on the following numerical result:

from matplotlib import pyplot as plt
import numpy as np
from scipy.special import comb as C

def game(p, n1=11, n2=10):
q = 1-p
x = sum([
C(n1, a) * p**a * q**(n1-a) * sum([
C(n2, b) * p**b * q**(n2-b)
for b in range(0, a-1 + 1)
])
for a in range(0, n1 + 1)
])
return x

p = np.linspace(0, 1, 100)
x = [game(pi) for pi in p]

plt.plot(p, x)
plt.axhline(0.5)
plt.axvline(0.5)
plt.show()


There's no closed formula in general. But except in extreme cases, a Normal approximation will work well.

("Extreme" cases occur when one or more of the expected counts of heads or tails for either player is tiny. "Tiny" depends on the accuracy you need, but as we will see below, even when one of these expected counts is as low as $$3,$$ the approximation can be good to more than two decimal places.)

As is usual, this approximation is obtained by matching moments: the mean of $$A-B$$ is $$\mu = 11 p_A - 10 p_B$$ while the variance of $$A-B$$ is $$\sigma^2 = 11 p_A(1-p_A) + 10 p_B(1-p_B).$$ To approximate the answer, we will use a Normally distributed variable $$X$$ with the same two moments.

As indicated by this plot of the probability mass function (PMF) of $$(A,B)$$ (drawn on top of an image of its approximation afforded by $$X$$), a good way to represent the event "A wins outright" is with the set where $$X \ge 1/2$$ (rather than, say, $$X \gt 0$$), corresponding to all points below and to the right of the white diagonal line, because this does a better job of capturing the correct probability. (Using $$1/2$$ rather than $$0$$ is often called a "continuity correction," referring to replacing a discrete calculation involving the PMF with a calculation based on the continuous random variable $$X.$$)

Thus, in terms of the standard Normal distribution function $$\Phi,$$ a suitable approximate answer is

$$\Pr(X \ge 1/2) = \Phi\left(\frac{\mu - 1/2}{\sigma}\right).$$

In the figure $$p_A = 0.7$$ and $$p_B = 0.4.$$ The fully accurate answer, obtained by summing the PMF where $$a \gt b,$$ is $$0.927\ldots,$$ while the Normal approximation gives $$0.929\ldots.$$

When $$p_A=p_B=1/2,$$ the symmetry of the problem as noted in your previous question continues to hold for the Normal approximation (provided the continuity correction is used!) and, since $$\mu - 1/2 = 0,$$ both methods give the correct value of $$0.5 = 1/2$$ exactly.

This R code performs the calculations.

#
# Specify the problem.
#
B <- (A <- 11) - 1
p.A <- 7/10
p.B <- 4/10
#
# Compute the bivariate PMF.
#
X <- within(expand.grid(a = 0:A, b = 0:B),
Probability <- dbinom(a, A, p.A) * dbinom(b, B, p.B))
#
# Normal approximation.
#
m <- diff(c(p.B, p.A) * c(B, A))
s <- sqrt(sum(c(p.A, p.B) * (1 - c(p.A, p.B)) * c(A, B)))
#
# Compare the results.
#
c(Accurate = sum(subset(X, a > b)\$Probability),
Approximate = pnorm((m - 1/2) / s))

• Great answer! Would be sharing of the r code possible? Many thanks in advance. Aug 6, 2022 at 10:41
• @Max Done. The image is obtained by applying ggplot to the data frame X.
– whuber
Aug 6, 2022 at 12:22

We have that $$A\sim\text{Bin}(11,q)$$ and $$B\sim\text{Bin}(10,p)$$

We want \begin{align} \text{Pr}(A>B)&=1-\text{Pr}(A\leq B)\\ &=1-\sum_{i=0}^{10}\text{Pr}(B=i)\cdot\text{Pr}(A>i)\\ &=1-\sum_{i=0}^{10}\text{Pr}(B=i)\cdot\big(1-\text{Pr}(A\leq i)\big)\\ &=1-\sum_{i=0}^{10}\text{Pr}(B=i)\cdot\bigg(1-\sum_{j=0}^{i}\text{Pr}(A=j)\bigg)\\ &=1-\sum_{i=0}^{10}{10\choose i}p^{i}(1-p)^{10-i}\cdot\bigg(1-\sum_{j=0}^{i}{11\choose j}q^{j}(1-q)^{11-j}\bigg) \end{align}