|
| 1 | +\begin{answer}{bayescoins} |
| 2 | +This is another question that tests your knowledge of Bayes' law. |
| 3 | +Let's define some notation to use. |
| 4 | +Define $H$ as the event that a coin comes up head, and $T$ that a coin comes up tails, and let $10H$ denote getting ten heads from ten coin flips. |
| 5 | +Let $C_{F}$ be the event where we select the fair coin from the bag, and $C_{R}$ the event that we select the rigged coin. |
| 6 | +This is one of the simplest questions about Bayes' law as there is not much to unpack. |
| 7 | +You want to know the probability of the rigged coin being selected, given you saw ten heads. |
| 8 | +By rote application of Bayes' law: |
| 9 | +\begin{align} |
| 10 | +\label{eq:1000coins:bayeslaw1} |
| 11 | + P( C_{R} \vert 10H) |
| 12 | + &= |
| 13 | + \frac{ |
| 14 | + P( 10H \vert C_{R} ) |
| 15 | + P( C_{R} ) |
| 16 | + }{ |
| 17 | + P( 10H \vert C_{R} ) |
| 18 | + P( C_{R} ) |
| 19 | + + |
| 20 | + P( 10H \vert C_{F} ) |
| 21 | + P( C_{F} ) |
| 22 | + } |
| 23 | + \text{.} |
| 24 | +\end{align} |
| 25 | +Consider |
| 26 | +$P( 10H \vert C_{R} )$, the probability of getting ten heads in a row with the rigged coin. |
| 27 | +Since this will happen with certainty |
| 28 | +$P( 10H \vert C_{R} ) = 1$. |
| 29 | +For the fair coin each flip is independent, so you have |
| 30 | +$$P( 10H \vert C_{F} )=P( H \vert C_{F} )^{10}= ({1}/{2})^{10} = {1}/{1024}.$$ |
| 31 | +Since you picked te coin out of a bag of 1000 coins, the probability that you selected the rigged coin is |
| 32 | +$P(C_{R}) = 1/1000$ and the probability that the coin you selected is fair is |
| 33 | +$P(C_{F}) = 999/1000$. |
| 34 | +You can substitute these into \eqref{eq:1000coins:bayeslaw1} to get |
| 35 | +\begin{align*} |
| 36 | + P( C_{R} \vert 10H) |
| 37 | + &= |
| 38 | + \frac{ |
| 39 | + (1) |
| 40 | + \left( \frac{1}{1000} \right) |
| 41 | + }{ |
| 42 | + (1) |
| 43 | + \left( \frac{1}{1000} \right) |
| 44 | + + |
| 45 | + \left(\frac{1}{1024}\right) |
| 46 | + \left(\frac{999}{1000}\right) |
| 47 | + } |
| 48 | + \\ |
| 49 | + &= |
| 50 | + \frac{ |
| 51 | + 1 |
| 52 | + }{ |
| 53 | + 1 |
| 54 | + + |
| 55 | + \left(\frac{999}{1024}\right) |
| 56 | + } |
| 57 | + \\ |
| 58 | + &= |
| 59 | + \frac{ |
| 60 | + 1 |
| 61 | + }{ |
| 62 | + \left(\frac{2023}{1024}\right) |
| 63 | + } |
| 64 | + \\ |
| 65 | + &= |
| 66 | + \frac{1024}{2023} |
| 67 | + \text{,} |
| 68 | +\end{align*} |
| 69 | +which is slightly more than $1/2$. |
| 70 | + |
| 71 | +This question is so well known that your interviewer likely won't even let you finish it. |
| 72 | +Once they see that you are on the right track they will move on to the next question. |
| 73 | +My interviewer didn't care about the answer, but he wanted me to describe \eqref{eq:1000coins:bayeslaw1} in detail. |
| 74 | +Since Bayes' law is just the application of conditional probability, you can derive it from first principles: |
| 75 | +\begin{align} |
| 76 | +\label{eq:1000coins:bayesexplain} |
| 77 | + P( C_{R} \vert 10H) |
| 78 | + &= |
| 79 | + \frac{ |
| 80 | + P( 10H , C_{R} ) |
| 81 | + }{ |
| 82 | + P( 10H ) |
| 83 | + } |
| 84 | +\end{align} |
| 85 | +and even a frequentist will agree. |
| 86 | +The nominator is the joint probability of ten heads and the rigged coin being selected, and it is easier to split this into another conditional probability: |
| 87 | +\begin{align*} |
| 88 | + P( 10H , C_{R} ) |
| 89 | + = |
| 90 | + P( 10H \vert C_{R} ) p( C_{R} ) |
| 91 | + \text{.} |
| 92 | +\end{align*} |
| 93 | +Technically, we can also say |
| 94 | +\begin{align*} |
| 95 | + P( 10H , C_{R} ) |
| 96 | + = |
| 97 | + P( C_{R} \vert 10H ) p( 10H ) |
| 98 | + \text{,} |
| 99 | +\end{align*} |
| 100 | +but this is not helpful, as it contains the quantity we are trying to solve for, $P( C_{R} \vert 10H )$, and will lead to circular reasoning. |
| 101 | + |
| 102 | +You can expand denominator in |
| 103 | +\eqref{eq:1000coins:bayesexplain} |
| 104 | +using the law of total probability to consider all the possible ways you can see ten heads. |
| 105 | +Since you only have two types of coins---either a fair coin or a rigged one---there are only two ways ten heads can happen: |
| 106 | +\begin{align*} |
| 107 | + P( 10H ) = |
| 108 | + P( 10H \vert C_{R} )p(C_{R}) |
| 109 | + + |
| 110 | + P( 10H \vert C_{F} )p(C_{F}) |
| 111 | + \text{.} |
| 112 | +\end{align*} |
| 113 | +If the interviewer wants you to explain even further, you can note that this is derived form the marginal probability |
| 114 | +\begin{align*} |
| 115 | + P( 10H ) = |
| 116 | + P( 10H , C_{R} ) |
| 117 | + + |
| 118 | + P( 10H , C_{F} ) |
| 119 | + \text{,} |
| 120 | +\end{align*} |
| 121 | +by applying the law of conditional probability to each of the terms. |
| 122 | +Putting all this together yields \eqref{eq:1000coins:bayeslaw1}. |
| 123 | + |
| 124 | +My interviewer used this Bayes' law question to test my handle on probability concepts. |
| 125 | +It is easy to confuse these basic concepts, which is another reason for doing proper interview preparation. |
| 126 | +Some interviewers ask this question and demand an ``intuitive'' solution that doesn't rely on algebraic manipulation. |
| 127 | +In this case, you could opt for a visual explanation of Bayes' Law as discussed in answer \ref{a:bayeslawdisease}. |
| 128 | +If that's not what your interviewer wants, use the following argument. |
| 129 | +You know the probability of choosing the rigged coin is $1/1000$. |
| 130 | +You also know the probability of getting ten heads from a fair coin is $1/2^{10} = 1/1024$. |
| 131 | +These two events are about equally likely, meaning the probability that we have the double headed coin is about a half. |
| 132 | +If you only had nine heads in a row, the fair coin would give a probability of $1/512 = 2/1024$. |
| 133 | +That means the outcome of nine heads is about twice as likely with the fair coin as the probability of selecting the rigged coin from the bag. |
| 134 | +So the odds of ${fair}{:}{rigged}$ are $2{:}1$, leading you to assign a probability of about $1/3$ to the rigged coin being selected. |
| 135 | +%TODO: could link this up to section on gambling mathematics |
| 136 | +\end{answer} |
| 137 | + |
0 commit comments