A coin toss problem

Introduction

In [1], Professor Takis Konstantopoulos put this question: Toss a fair coin 10000 times, what’s the probability of observing heads showing up exactly 5000 times? To make things more interesting, let’s generalize this coin toss problem as this one: Toss a fair coin n=10i (for i=1, 2, , 10) times, what’s the probability of observing heads showing up exactly n/2 times? In this note, we will solve the general problem, aiming to gain insights from the problem solving process.

Two methods

Method 1: We can use R function

dbinom(x = n/2, size = n, prob = 1/2)

Method 2: We can try out the Central Limit Theorem (CLT). Let random variable X follow Binomial(n,1/2) distribution. We want to find Pn(X=n/2), where we use subscript n to emphasize that the probability depends on n. We have Pn(X=n/2)=Pn(n/2X<n/2+1)=Pn(0Y<1/n/4), where Y=Xn/2n/4. According to the CLT, if n is large enough then Y approximately follows the standard normal distribution. Thus, Pn(X=n/2)pnorm(b)0.5, where b=1/n/4.

R code and results

# helper functions --------------------------------------------------------
## method 1
find_prob_builtin <- function(n = 10)
{dbinom(x = n/2, size = n, prob = 1/2)
}

## method 2
find_prob_clt <- function(n = 10)
{b <- 1 / sqrt(n/4)
 pnorm(b) - 0.5
}

# some results ------------------------------------------------------------
y1 <- sapply(10^(1:10), find_prob_builtin)
y2 <- sapply(10^(1:10), find_prob_clt)

df <- data.frame(i = 1:10,
                 Pn_method1 = y1,
                 Pn_method2 = y2)

knitr::kable(df, format = 'html')
i Pn_method1 Pn_method2
1 0.2460938 0.2364554
2 0.0795892 0.0792597
3 0.0252250 0.0252145
4 0.0079786 0.0079783
5 0.0025231 0.0025231
6 0.0007979 0.0007979
7 0.0002523 0.0002523
8 0.0000798 0.0000798
9 0.0000252 0.0000252
10 0.0000080 0.0000080

From the above table, we can have the following insights:

  1. The CLT works well even when n=10.

  2. For n=10i (i=1, ,10), an empirical formula is Pn(X=10i/2)2.5×10(i+1)/2, if n is odd8.0×10(i+2)/2, if n is even.

Further discussions

Using Stirling’s formula, we can show that limn+Pn(X=n/2)=0.

To fully understand the mathematics/algorithm behind dbinom(), we can study [2].

References

[1] Konstantopoulos, T. (2020). Takis Tackles: Mathematical Higher Education. URL: https://imstat.org/2020/07/16/takis-tackles-mathematical-higher-education/

[2] Loader, C. (2002). Fast and Accurate Computation of Binomial Probabilities. URL: https://www.r-project.org/doc/reports/CLoader-dbinom-2002.pdf

Lingyun Zhang (张凌云)
Lingyun Zhang (张凌云)
Design Analyst

I have research interests in Statistics, applied probability and computation.