Steven R. Dunbar
Department of Mathematics
203 Avery Hall
University of Nebraska-Lincoln
Lincoln, NE 68588-0130
http://www.math.unl.edu
Voice: 402-472-3731
Fax: 402-472-8466

Topics in
Probability Theory and Stochastic Processes
Steven R. Dunbar

__________________________________________________________________________

Distinguishing A Biased Coin From a Fair Coin

_______________________________________________________________________

Note: These pages are prepared with MathJax. MathJax is an open source JavaScript display engine for mathematics that works in all browsers. See http://mathjax.org for details on supported browsers, accessibility, copy-and-paste, and other features.

_______________________________________________________________________________________________

Rating

Rating

Mathematically Mature: may contain mathematics beyond calculus with proofs.

_______________________________________________________________________________________________

Section Starter Question

Section Starter Question

You are presented with two coins: one is fair and the other has a 60% chance of coming up heads. Unfortunately, you don’t know which is which. How many flips would you need to perform in parallel on the two coins to give yourself a 95% chance of correctly identifying the biased coin?

_______________________________________________________________________________________________

Key Concepts

Key Concepts

  1. How to numerically compute the probability of a majority of heads in a sequence of paired coin flips of a biased coin and a fair coin.
  2. How to numerically compute the probability of statistical evidence of a biased coin in a sequence of paired coin flips of a biased coin and a fair coin.

__________________________________________________________________________

Vocabulary

Vocabulary

  1. A sequence of independent Bernoulli trials with probability 12 of success on each trial is metaphorically called a fair coin. One for which the probability is not 12 is called a biased or unfair coin.

__________________________________________________________________________

Mathematical Ideas

Mathematical Ideas

Introduction

The following problem appeared in the FiveThirtyEight.com weekly Riddler puzzle column on September 29, 2017:

On the table in front of you are two coins. They look and feel identical, but you know one of them has been doctored. The fair coin comes up heads half the time while the doctored coin comes up heads 60 percent of the time. How many flips you must flip both coins at once, one with each hand would you need to give yourself a 95 percent chance of correctly identifying the doctored coin?

Extra credit: What if, instead of 60 percent, the doctored coin came up heads p some percent of the time? How does that affect the speed with which you can correctly detect it?

This problem appeared in a paper “What’s Past is Not Prologue” by James White, Jeff Rosenbluth, and Victor Haghani. They in turn were inspired by the problem posed in a paper “Good and bad properties of the Kelly criterion” by MacLean, Thorp and Ziemba.

Solving this problem requires some interpretation and computation.

Probability of a Majority of Heads

In any fixed number of simultaneous flips, there is always a chance that the fair coin will have more heads than the biased coin. But the Weak Law of Large Numbers says that the probability that the biased coin will have a majority of heads increases to 1 as the number of flips increases. One way to determine which is the biased coin is to choose the coin which has a majority of heads. The authors White, Rosenbluth, and Haghani want to calculate how many flips of 2 coins, one biased and one fair, we must observe in order to be 95% confident that the coin with more heads is the biased coin.

Since each coin has a binomial distribution and the coins are assumed independent, the joint probability mass distribution after n flips is the product of the individual binomial probability mass distributions. Denote by Q(n; j,k) the probability of j heads for the fair coin and k heads for the biased in n flips. Use p for the probability of heads of the biased coin and 1 2 for the probability of heads for the fair coin. Then

Q(n; j,k) = n j 1 2 j 1 2 nj n kpk(1 p)nk.

Then summing over values where j < k gives the probability that the biased coin has more heads than the fair coin in n flips

j < k = 1 2n kn j<kn k n j pk(1 p)nk.

There is no closed formula to evaluate this sum so calculation is necessary. First create two vectors of length n + 1 with the binomial distribution on 0 to n with probability 1 2 for the fair coin and with probability p for the biased coin. Then using the outer product of these two vectors create the bivariate binomial distribution for the two coins. This will be an (n + 1) × (n + 1) matrix. The element in row i and column j is the product of the binomial probability of i 1 heads for the fair coin and the binomial probability of j 1 heads for the biased coin. The sum is over column indices strictly greater than the row indices. To create the sum, set the lower triangular part of the matrix and the diagonal of the matrix to 0 and use the sum command to sum all entries of the matrix. This seems to be efficient, even for values of n up to 200. To find the minimal value of n for which this probability is greater than 0.95 use binary search over a reasonable interval.

It might seem possible to use a bivariate normal approximation of the bivariate binomial distribution to calculate the probability. While there is such an approximation, the double integration of the bivariate normal with a non-zero covariance would be over a region of the form y > x 𝜖. There is no direct way with R to calculate the integral over a region of this form, so it is actually easier to calculate with the bivariate binomial distribution.

The result is that it takes 143 flips of the two coins for the probability to be greater than 0.95 for the 0.6 biased coin to have more heads than the fair coin.

The same analysis for various probabilities of heads p for the biased coin and for values 0.95, 0.9 and 0.75 of certainty is in Figure 1. The number of flips required decreases as the bias p increases, as expected. The number of flips required also decreases as the certainty decreases.


PIC

Figure 1: The number of flips N required to get a majority of heads with certainty 0.95 (black), 0.9 (red) and 0.75 (blue).

Determining which coin is biased

Assume that the biased coin is in the left hand. Let Lj be the result of left-hand coin flip j, knowing it is biased so Lj = Head = 1 with probability 0.6, Lj = Tail = 0 with probability 0.4. Let Rj be the result of right-hand coin flip j, knowing it is fair so Rj = Head = 1 with probability 0.5, Rj = Tail = 0 with probability 0.5. Let Xj = Lj Rj. This is a trinomial random variable with Xj = 1 with probability 15 = 0.2, Xj = 0 with probability 12 = 0.5, Xj = 1 with probability 310 = 0.3.

Consider the statistics of Xj,

𝔼 Xj = (1) (0.2) + 0 (0.5) + (+1) (0.3) = 0.1, Var Xj = (1)2 (0.2) + (0)2 (0.5) + (+1)2 (0.3) (0.1)2 = 0.49, σ[Xj] = 0.7.

Let Sn = 1 n j=1nX j be the sample mean. Then Sn is distributed on 1 to 1 by increments of 1n for a total of 2n + 1 points with

𝔼 Sn = 0.1, Var Sn = 0.49n, by independence,  σ[Sn] = 0.7n.

Thus, the distribution of Sn clusters around 110 with standard deviation 7(10(n)). The goal is find a number of flips such that the probability that Sn is closer to 0.1 than 0.2 with probability 0.95. This would be enough to clearly distinguish the mean from the possible alternative which is 0.1 coming from the biased coin in the right hand.

By the Chebyshev inequality

|Sn μ| k σ2k2.

Here the values for the Chebyshev inequality are

|Sn 110| 0.2 0.05.

Taking k = 210 = 0.2, if n is large enough then σ2k2 = (0.49n)(210)2 0.05 = 120. Solving for n, gives n > 245 however Chebyshev is notoriously weak, so this is more than actually necessary.

Expressing the precise distribution of Sn analytically is difficult. So instead, use a numerical calculation of the distribution. To numerically calculate the distribution of the sample mean Sn, use the R package distr and specifically the function convpow which takes the n-fold convolution power of a distribution to create the distribution of the n-fold sum of a random variable. Note that mathematically the support of the distribution of, for instance S100, would be from 1 to 1, with 201 points. However, the actual calculated distribution support of, for instance, S100, is 111 points from 46 to 64. The reason is that points with probability less than 1016 are ignored, so are not included in this domain. So use match(-10, (support(D100))) to find the index of 0.1 (namely 0.1 100 = 10). This turns out to be index 37. So summing the distribution over indices from 37 + 1 to 111 gives the probability that the random variable Sn is bigger than 0.1. Recall that 0.1 is the mean value if the biased coin is in the right hand. Searching for a value of n large enough that the probability exceeds 0.95 gives the required number of flips.

Using this algorithm, the necessary number of flips to distinguish a biased coin with a probability of heads 0.6 from a fair coin with a certainty level of 0.95 is 31. The same analysis for various probabilities of heads p for the biased coin and for values 0.95, 0.9 and 0.75 of certainty is in Figure 2. The number of flips required decreases as the bias increases as expected. The number of flips required also decreases as the certainty decreases as expected.


PIC

Figure 2: The number of flips N required to statistically distinguish a coin with probability p from a fair coin with 0.95 (black), 0.9 (red) and 0.75 (blue).

There is an interesting observation for values of p > 0.75 and all values of certainty. According to Figure 2, it only takes 2 flips of the coins to identify the biased coin for these parameters. That is because the probability distribution of S2 = 1 2[(L1 R1) + (L2 R2)] is in Table 1. The probability that S2 is greater than 0.1 is 0.343750 + 0.375000 + 0.140625 = 0.863125.


Table 1: Probability distribution of S2 for p = 0.75.
11 201 21
0.015625 0.1250000.3437500.3750000.140625

Differences between the Two Calculations

The two values of n required are strikingly different. Why is that so?


Support of bivariate binomial

Figure 3: The support of the bivariate binomial and the calculation of the multinomial distribution for n = 10.

The calculation of the probabilities uses fundamentally the same information, as the diagram in Figure 3 for the case n = 10 illustrates. The 11 × 11 array of dots represents the support of the bivariate binomial distribution as a matrix, with rows from 0 to 11 for the number of heads from the fair coin and columns 0 to 11 for number of heads for the biased coin.

The probability that the majority of flips is from the biased coin is the sum of the probabilities in the strict upper triangle of the support of the bivariate distribution. The shaded portion of Figure 3 shows this domain.

The multinomial probability distribution on 10 to 10 of the 10-fold sum j=010(L j Rj) is the sum of the probabilities along diagonals of the bivariate binomial distribution as indicated by the red arrows. In the case the biased coin has p = 0.6 so the mean of Ln Rn = 0.1, the probability of the event

[Sn > 1 10 ] = 1 n j=1n(L j Rj) > 1 10 = j=1n(L j Rj) > n 10

is the sum of the probabilities in the strict upper triangle and additionally the main diagonal and the subdiagonals from n 10 to 0. Thus the total probability is larger for the statistical calculation and for a given level of certainty to exceed the certainty the required number of flips is less.

The choice of decision criterion is motivated by the application. The original problem posed in FiveThirtyEight.com was drawn from a white paper by James White, Jeff Rosenbluth, and Victor Haghani from Elm Partners Investing. In turn their example is motivated by a paper “Good and bad properties of the Kelly criterion” by McLean, Thorp and Ziemba. The question is a simplified and idealized version of an investment question about how much evidence is required to select a higher performing investment, modeled by a biased coin, from a lower performing investment with just an even chance at making a profit, modeled by a fair coin. In that case, the 95% certainty of a majority of gains is a reasonable choice of criterion. However, if the question is merely to identify the biased coin, then it makes sense to use the Central Limit Theorem to distinguish the mean given that the biased coin is in the left hand from the mean given that the biased coin is in the right hand. That is, the probability distribution of the sample mean “condenses” around the expected value of the difference with smaller variance as the number of flips increases. Some of the probability may even come from cases where there are a more heads produced by the fair coin but the preponderance of evidence indicates the biased coin. Thus it takes a smaller number of flips to confidently identify the biased coin.

Sources

The definition of biased coin is from Wikipedia. The problem appeared in the FiveThirtyEight.com weekly Riddler puzzle column on September 29, 2017. This first subsection with the majority solution is adapted from a white paper “What’s Past is Not Prologue” by James White, Jeff Rosenbluth, and Victor Haghani from Elm Partners Investing. In turn, their example is motivated by a paper “Good and bad properties of the Kelly criterion” by McLean, Thorp and Ziemba. The second subsection with the statistical solution is original.

_______________________________________________________________________________________________

Algorithms, Scripts, Simulations

Algorithms, Scripts, Simulations

Algorithm

Scripts

R

R script for majority binary search..

1prob <- function(n, p) { 
2    fair <- dbinom(0:n, n, 0.5)         #fair binomial distribution 
3    biased <- dbinom(0:n, n, p)         #biased binomial dist 
4    bivarBinom <- fair %o% biased       #outer product, (n+1) x (n+1) matrix 
5    bivarBinom[ lower.tri(bivarBinom, diag=TRUE) ] <- 0 
6    # retain only the upper triangular values, without diagonal 
7    sum( bivarBinom )                   #add them all up 
8} 
9 
10reqN <- c()                             #initialize vector to hold results 
11for (certainty in c(0.95, 0.9, 0.75)) { #three representative values 
12    for (p in seq(0.55, 0.99, length=45)) { #array of bias values 
13        low <- 2                            #minimum to start search 
14        high <- 1000                        #arbitrary guess for max for search 
15 
16        while (high - low > 1) { 
17            try <- floor( (low + high)/2 ) #binary search 
18            if ( prob(try, p) <= certainty ) low <- try + 1 else high <- try 
19            ## uses monotone increasing nature of probability 
20        } 
21 
22        reqN <- c(reqN, low)            #add search result to vector of results 
23    } 
24} 
25 
26N <- matrix(reqN, 45,3)                 #reformat to three columns, one for each certainty 
27 
28ps = seq(0.55, 0.99, length=45)         #array of bias values to plot on horiz 
29plot( ps, N[,1], pch=20, xlab="p", ylab="N") #plot required N for certainty 0.95 
30points( ps, N[,2], pch=20, col="red")        #add plot for required N for 0.90 
31points( ps, N[,3], pch=20, col="blue")       #add plot for required N for 0.75
4cAp1x1-1300032:

R script for statistical binary search..

1 
2library(distr) 
3 
4prob <- function(nn, p) { 
5    D1 <- DiscreteDistribution( -1:1, c((1-p)/2, 1/2, p/2) ) 
6    ## trinomial distribution of X_n = L_n - R_n 
7    Dnn <- convpow(D1, nn) 
8    ## distribution of sum_{j=1}^n X_n 
9    end0 <- NROW( (support(Dnn)) ) 
10    ## last non-zero support point 
11    start0 <- match( floor(-(p-1/2)*nn)+1, (support(Dnn)) ) 
12    ##  non-zero support point close to mean (p-1/2)*nn + 1 
13    distDnn <- d(Dnn)(support(Dnn)) 
14    ## extract vector of distribution values on [start0, end0] 
15    sum( distDnn[start0:end0] )         #add up the probability 
16} 
17 
18reqN <- c()                             #initialize vector to hold results 
19 
20for (certainty in c(0.95, 0.9, 0.75)) { #three representative value 
21    try <- 150                          #place to start search 
22    for (p in seq(0.55, 0.99, length=45)) { #array of bias values 
23        low <- 1                            #minimum to start search 
24        high <- try                         #a maximum to start with 
25        ## For greater efficiency, note that the required number of flips 
26        ## for the next p  will be less than the number of flips for previous 
27        ## p, so restrict search to interval n=2 to n=try from previous search 
28        while (high - low > 1) { 
29            try <- round( (low + high)/2 ) #binary search 
30            if ( prob(try, p) <= certainty ) low <- try  else high <- try 
31        } 
32 
33        reqN <- c(reqN, high)            #add search result to vector of results 
34    } 
35} 
36 
37N <- matrix(reqN, 45,3)                 #reformat to three columns, one for each certainty 
38 
39ps = seq(0.55, 0.99, length=45)         #array of bias values to plot on horiz 
40plot( ps, N[,1], pch=20, xlab="p", ylab="N") #plot for required N for certainty 0.95 
41points( ps, N[,2], pch=20, col="red")        #add plot for required N for 0.90 
42points( ps, N[,3], pch=20, col="blue")       #add plot for required N for 0.75
4cAp2x1-1300046:

__________________________________________________________________________

Problems to Work

Problems to Work for Understanding

__________________________________________________________________________

Books

Reading Suggestion:

References

[1]   Leonard C. MacLean, Edward O. Thorp, and William T. Ziemba. Long-term capital growth: the good and bad properties of the Kelly and fractional Kelly capital growth criteria. Quantitative Finance, 10(7):681–687, 2010.

[2]   James White, Jeff Rosenbluth, and Victor Haghani. What’s past is Not prologue. https://ssrn.com/abstract=3034686, April 2017.

__________________________________________________________________________

Links

Outside Readings and Links:

__________________________________________________________________________

I check all the information on each page for correctness and typographical errors. Nevertheless, some errors may occur and I would be grateful if you would alert me to such errors. I make every reasonable effort to present current and accurate information for public use, however I do not guarantee the accuracy or timeliness of information on this website. Your use of the information from this website is strictly voluntary and at your risk.

I have checked the links to external sites for usefulness. Links to external websites are provided as a convenience. I do not endorse, control, monitor, or guarantee the information contained in any external website. I don’t guarantee that the links are active at all times. Use the links here with the same caution as you would all information on the Internet. This website reflects the thoughts, interests and opinions of its author. They do not explicitly represent official positions or policies of my employer.

Information on this website is subject to change without notice.

Steve Dunbar’s Home Page, http://www.math.unl.edu/~sdunbar1

Email to Steve Dunbar, sdunbar1 at unl dot edu

Last modified: Processed from LATEX source on December 14, 2017