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
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
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:
-
The CLT works well even when
. -
For
( ), an empirical formula is
Further discussions
Using Stirling’s formula, we can show that
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