Steven R. Dunbar
Department of Mathematics
203 Avery Hall
University of Nebraska-Lincoln
Lincoln, NE 68588-0130
Probability Theory and Stochastic Processes
Steven R. Dunbar
Distinguishing A Biased Coin From a Fair Coin
Mathematically Mature: may contain mathematics beyond calculus with proofs.
You have with two coins: one is fair and the other has a biased chance of coming up heads. Unfortunately, you don’t know which is which. How can you determine which is the biased coin? What do you need to know?
This problem serves as a warmup for the more detailed calculations below.
You have two coins. One is fair with . The other coin is biased with . First you toss one of the coins once, resulting in heads. Then you toss the other coin three times, resulting in two heads. Which coin is more likely to be the biased coin, the ﬁrst or the second?
Assuming tossing the biased coin once and tossing the fair coin three times the probability of observing the outcome is
On the other hand, assuming tossing the fair coin once and tossing the biased coin three times the probability of observing the given outcome is
This means it was more likely that is was the biased coin tossed once while tossing the fair coin three times.
Take a uniform prior, that is, assume that the ﬁrst coin is equally likely to be either of the two coins. Let denote the observation, and the event that the ﬁrst coin is biased. Then
The conditional probabilities are
From Bayes Theorem,
Take even prior odds to be even, that is, assume that the ﬁrst coin is equally likely to be either of the two coins. Let be the observed outcomes. The likelihood ratio is
Then the odds in favor of the ﬁrst coin being biased and the second coin being fair are , so the probability is .
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 percent of the time. How many ﬂips you must ﬂip both coins at once, one with each hand would you need to give yourself a percent chance of correctly identifying the doctored coin?
Extra credit: What if, instead of percent, the doctored coin came up heads some percent of the time? How does that aﬀect the speed with which you can correctly detect it?
This problem appeared in a paper “What’s Past is Not Prologue” by James White, Jeﬀ Rosenbluth, and Victor Haghani. In turn, a problem posed in a paper “Good and bad properties of the Kelly criterion” by MacLean, Thorp and Ziemba inspired the problem by White, Rosenbluth, and Haghani.
Solving this problem requires some interpretation and computation.
In any ﬁxed number of simultaneous ﬂips, 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 as the number of ﬂips 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 paired ﬂips of coins, one biased and one fair, we must observe in order to be conﬁdent that the coin with more heads is the biased coin.
Assuming independence, since each coin has a binomial distribution the joint probability mass distribution after ﬂips is the product of the individual binomial probability mass distributions. Denote by the probability of heads for the fair coin and heads for the biased in ﬂips. Use for the probability of heads of the biased coin and for the probability of heads for the fair coin. Then
Then summing over values where gives the probability that the biased coin has more heads than the fair coin in ﬂips
This sum has no closed formula evaluation so calculation is necessary. First create two vectors of length with the binomial distribution on to with probability for the fair coin and with probability 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 matrix. The element in row and column is the product of the binomial probability of heads for the fair coin and the binomial probability of 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 and use the sum command to sum all entries of the matrix. This seems to be eﬃcient, even for values of up to . To ﬁnd the minimal value of for which this probability is greater than use binary search in over a reasonable interval.
It might seem possible to use a bivariate normal approximation of the bivariate binomial distribution to calculate the probability. Although approximation of the bivariate binomial distribution with a bivariate normal distribution is possible, the double integration of the bivariate normal with a non-zero covariance would be over a region of the form . The R language has no direct way 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 ﬂips of the two coins for the probability to be greater than for the biased coin to have more heads than the fair coin.
The same analysis for various probabilities of heads for the biased coin and for values , and of certainty is in Figure 1. The number of ﬂips required decreases as the bias increases, as expected. The number of ﬂips required also decreases as the certainty decreases.
Assume that the biased coin is in the left hand. Let be the result of left-hand coin ﬂip , knowing it is biased so with probability , with probability . Let be the result of right-hand coin ﬂip , knowing it is fair so with probability , with probability . Let . This is a trinomial random variable with with probability , with probability , with probability .
Consider the statistics of ,
Let be the sample mean. The distribution of is on to by increments of for a total of points with
Thus the distribution of clusters around with standard deviation . If the biased coin is in the right hand, the distribution of clusters around with standard deviation .The goal is ﬁnd a number of ﬂips such that with high probability the sample mean is closer to the theoretical mean (when the biased coin is in the left hand) than the value (the theoretical mean coming from the situation with the biased coin in the right hand). Take “the sample mean closer to than ” to mean that is closer to than the distance to the midpoint between the two means. Precisely, the goal is to ﬁnd so that . This is the same event as which is the same criterion as having the majority of heads above.
Expressing the precise distribution of analytically is diﬃcult. So instead, use a numerical calculation of the distribution. To numerically calculate the distribution of the sample mean , use the R package distr and speciﬁcally the function convpow that takes the -fold convolution power of a distribution to create the distribution of the -fold sum of a random variable. Note that mathematically the support of the distribution of, for instance , would be from to , with points. However, the actual calculated distribution support of, for instance, , is points from to . The reason is that convpow ignores points with probability less than and so these points are not included in the domain. So use match(0, (support(D100))) to ﬁnd the index of . This turns out to be index . So summing the distribution over indices from to gives the probability that the random variable . Searching for a value of large enough that the probability exceeds gives the required number of ﬂips. From some experimentation, the numerical support of the distribution is positive for , that is, for . That means that the numerical search should start from a high of .
Using this algorithm, the necessary number of ﬂips to distinguish a biased coin with a probability of heads from a fair coin with a certainty level of is . The same analysis for various probabilities of heads for the biased coin and for values , and of certainty is in Figure 2. The number of ﬂips required decreases as the bias increases as expected. The number of ﬂips required also decreases to for certainty , for certainty and for certainty .
The calculation of the probabilities uses fundamentally the same information, as the diagram in Figure 3 for the case illustrates. The array of dots represents the support of the bivariate binomial distribution as a matrix, with rows from to for the number of heads from the fair coin and columns to for number of heads for the biased coin.
The probability that the majority of ﬂips 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 to of the sum 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 so the mean of , the probability of the event
is the sum of the probabilities in the strict upper triangle. This is the same criterion as for the majority of heads above. For the search using the sample mean again requires pair ﬂips to distinguish the coins with certainty .
The framing of the application motivates the choice of criterion. The original problem posed in FiveThirtyEight.com comes from a white paper by James White, Jeﬀ Rosenbluth, and Victor Haghani from Elm Partners Investing. The paper “Good and bad properties of the Kelly criterion” by McLean, Thorp and Ziemba motivated their example. The question is a simpliﬁed and idealized version of an investment question about how to identify a higher performing investment, modeled by a biased coin, from a lower performing investment with just an even chance at making a proﬁt, modeled by a fair coin. In that case, the certainty of a majority of gains is a reasonable choice of criterion. 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.
The coin ﬂips are independent. So if a coin comes up heads with probability and we ﬂip it times, the binomial distribution gives the probability that it comes up heads exactly times. Number the coins and probabilities of coming up heads and respectively. Flip each coin times and record how many times each coin come up heads, but we don’t know which coin is which. Say the coins come up heads and times for the left and right coin respectively. Call the vector of observed data .
Exactly two possible scenarios occur:
Compute the posterior probability by using Bayes rule:
and similarly for . Assume that scenarios and have the same prior probability so . Therefore, the Bayesian condition for conﬁdence simpliﬁes to
To be conﬁdent with level about one of the scenarios then the posterior probability must be greater than .
By deﬁnition, for all . So the two cases above can’t simultaneously be true when . Rearranging these inequalities, we have
The implication is that we can stop ﬂipping coins once the diﬀerence between log-likelihoods grows suﬃciently large. The smaller is , the larger the diﬀerence in log-likelihoods must be before we can declare that we are conﬁdent. Simplify the expression by substituting the deﬁnition for the likelihoods and in terms of the binomial probabilities becoming
Take logarithms of both sides and combine the expressions into a single inequality involving the absolute diﬀerence of log-likelihoods
The implication is that we can stop ﬂipping coins once the diﬀerence between log-likelihoods grows suﬃciently large. The smaller is , the larger the diﬀerence in log-likelihoods must be before we can declare that we are conﬁdent. After simpliﬁcation, this becomes
The number of heads and in the left and right hands are random variables. In one hand the number of heads from the coin with will have the binomial probability distribution with mean and standard deviation . In the other hand the number of heads from the coin with will have the binomial probability distribution with mean and standard deviation . Normal distributions with corresponding means and standard deviations can approximate each binomial distribution.
As a ﬁrst approximation, substitute the empirical probabilities and obtained from the distribution means. Rearrange to isolate to obtain
This expression is a lower bound on the number of samples required, in terms of the conﬁdence , the known probabilities and and the empirical probabilities and . Note that if , then which is expected. Taking , and , then . More generally, Figure 4 shows a plot of the number of ﬂips required as a function of for ﬁxed and ﬁxed , so in percentages conﬁdence.
However, this is only a lower bound on the real number of ﬂips required to ﬁnd the biased coin since and can be closer than what was used above. In fact, in the scenario Fair on Left can have in the range and in the range . The probability of each of these events is determined by quantiles of the binomial distribution, or approximately by the normal distribution. Since
with probability determined by the quantile . (Note that since this is positive for suﬃciently large .) The number of ﬂips then required to determine which is the biased coin is then determined by
Choosing a quantile , substituting for , and , and then solving for gives a lower bound for the number of ﬂips required for distinguishing the fair coin from the biased coin.
For example, choosing gives the approximate probability that in the range and independently that in the range . Then the probability of both events is approximately . Using , and , the inequality is
Solving for gives . As another example set with a probability of of in the range and independently that in the range and joint probability of . Then solving gives . As a ﬁnal example, choosing gives a probability of of in the range and independently with probability approximately that in the range and joint probability of . This is equivalent to the original calculation giving the lower bound of .
The extended Bayesian analysis introduces another parameter . Using two parameters and , as long as for reasonable values of , might be better. Now some experimentation, including binary search, is necessary to choose a value of required to determine the biased coin with certainty . The scripts below show the results of that experimentation and compare it to the other determination methods based on the majority and the Central Limit Theorem. For example, with in the left hand, and in the right hand it takes ﬂips to identify the fair coin in the left hand with certainty. A close look at the results show why the log-likelihood Bayesian criterion requires more ﬂips for the same certainty. The short answer is that the log-likelihood is a stricter requirement than the majority requirement in the other two approaches. In one trial with ﬂips, the fair coin in the left hand came with heads while the biased coin in the right hand came up with heads. The majority of heads was in the right hand, but the absolute diﬀerence of the log-likelihoods is , not greater than . Both heads totals are well within the two-standard deviation range around the respective expected values of heads and heads respectively.
An R script testing all three methods against placing the fair and biased coins in the left and right randomly is in the scripts section. In summary, even with more ﬂips, the Likelihood method is slightly less eﬀective than the two majority methods. It is also a more complicated procedure.
The deﬁnition of biased coin is from Wikipedia.
The simple probability problem is adapted from Bogolmony, Cut-the-Knot, Two Coins, One Fair, One Biased.. The same problem appears in FlyingColoursMaths Two Coins, One Fair, One Biased..
The problem of how many tosses to ﬁnd the biased coin appeared in the FiveThirtyEight.com weekly Riddler puzzle column on September 29, 2017. This ﬁrst subsection with the majority solution is adapted from a white paper “What’s Past is Not Prologue” by James White, Jeﬀ 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.
The Bayesian analysis is adapted and extended from
Lessard,Finding the baised coin..
R script for Majority Binary Search..
R script for Statistical Binary Search..
R script for Log Likelihood..
R script for Testing Each Method..
 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.
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 eﬀort 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 reﬂects the thoughts, interests and opinions of its author. They do not explicitly represent oﬃcial 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 modiﬁed: Processed from LATEX source on September 7, 2018