diff --git a/newquestions/bayescoins/.gitignore b/newquestions/bayescoins/.gitignore deleted file mode 100644 index ce41d5e..0000000 --- a/newquestions/bayescoins/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -* -!.gitignore - -!*.tex -!*.bib - -# This whitelists the folder -# It applies the same rules as above inside this folder -!/plot/ - - - diff --git a/src/QuantitativePrimer.pdf b/src/QuantitativePrimer.pdf index 8395b20..c9f67d1 100644 Binary files a/src/QuantitativePrimer.pdf and b/src/QuantitativePrimer.pdf differ diff --git a/src/QuantitativePrimer.tex b/src/QuantitativePrimer.tex index 2602973..aba50c6 100644 --- a/src/QuantitativePrimer.tex +++ b/src/QuantitativePrimer.tex @@ -8,7 +8,7 @@ % C: Increment with minor error corrections and additions % When B is incrememted, C is reset to zero % When A is incrememted, B and C is reset to zero -\newcommand{\docversion}{V1.1.5} +\newcommand{\docversion}{V1.2.0} \begin{document} %\doublespacing @@ -783,6 +783,23 @@ \subsection{Phone interview, 1 hour} \input{answers/drop20cards.tex} \clearpage + +\subsection{Face-to-face, 1 hour} + +\begin{question}{bayescoins} +\index{questions!Bayes' law and coin flips} +You have a bag with 1000 coins in it. +One of them is a double headed coin, the other 999 are fair coins. +I pick one coin from the bag at random, and flip it ten times. +It comes up heads all ten times. +What is the probability that I have selected the double headed coin? +\end{question} + + +\clearpage +\input{answers/bayescoins.tex} + + \section{Old friends} Two questions stood out: I got the \emph{Air Force One} question three times in 2014, and I got the \emph{Stick Breaking} question more than three times during 2017.\footnote{I never got \emph{Air Force One} in 2017, nor did I get \emph{Stick Breaking} in 2014. Questions seem to go in and out of fashion and there is evidence of cross-pollination.} @@ -1644,7 +1661,7 @@ \subsection{Questions for them} to foldernames? \item What programming languages does the team use? R, Python, C++, Julia, Matlab? For data analysis? For scripting? For production? - \item Is the team Bayesians, frequentists, or whatever gets the job done? + \item Is the team made up of Bayesians, frequentists, or whatever gets the job done? \item What are the backgrounds of the other team members? What would someone with my background contribute? \item Are modellers expected to write the code to implement their models, or is this handled by developers? \item How are datasets accessed? SQL (Postgres, MySQL, MSSQL, sqlite), Hadoop, csvs, Excel, shared folders, or do people throw around USB sticks? diff --git a/newquestions/bayescoins/ExampleQuestion.tex b/src/answers/bayescoins.tex similarity index 70% rename from newquestions/bayescoins/ExampleQuestion.tex rename to src/answers/bayescoins.tex index 89f8ed0..4c47f74 100644 --- a/newquestions/bayescoins/ExampleQuestion.tex +++ b/src/answers/bayescoins.tex @@ -1,38 +1,7 @@ -\documentclass[11pt]{article} - -\usepackage[utf8]{inputenc} -\usepackage[a4paper]{geometry} - - -\usepackage{graphicx} -\usepackage{amsmath,amssymb,mleftright} -\usepackage{mathtools} % For cases environment -\usepackage[round]{natbib} -\usepackage{microtype} -\usepackage{xcolor} - -\usepackage[british]{babel} - -% Make a title for your question and provide your name (or a pseudonymn) -\title{Bayes and 1000 coins} -\author{D. Bester} -\date{} - -\begin{document} -\maketitle - -\section{Question} - -You have a bag with 1000 coins in it. -One of them is a double headed coin, the other 999 are fair coins. -I pick one coin from the bag at random, and flip it ten times. -It comes up heads all ten times. -What is the probability that I have selected the double headed coin? - -\section{Answer} -This is another question about Bayes' law. -Let's make some notation to use, 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. +\begin{answer}{bayescoins} +This is another question that tests your knowledge of Bayes' law. +Let's define some notation to use. +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. 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. This is one of the simplest questions about Bayes' law as there is not much to unpack. You want to know the probability of the rigged coin being selected, given you saw ten heads. @@ -58,11 +27,11 @@ \section{Answer} Since this will happen with certainty $P( 10H \vert C_{R} ) = 1$. For the fair coin each flip is independent, so you have -$P( 10H \vert C_{F} )=P( 10 \vert C_{F} )^{10}= ({1}/{2})^{10} = {1}/{1024}$. +$$P( 10H \vert C_{F} )=P( H \vert C_{F} )^{10}= ({1}/{2})^{10} = {1}/{1024}.$$ Since you picked te coin out of a bag of 1000 coins, the probability that you selected the rigged coin is $P(C_{R}) = 1/1000$ and the probability that the coin you selected is fair is $P(C_{F}) = 999/1000$. -You can substitute +You can substitute these into \eqref{eq:1000coins:bayeslaw1} to get \begin{align*} P( C_{R} \vert 10H) &= @@ -100,7 +69,7 @@ \section{Answer} which is slightly more than $1/2$. This question is so well known that your interviewer likely won't even let you finish it. -Once they see you can answer it they will move on to the next question. +Once they see that you are on the right track they will move on to the next question. My interviewer didn't care about the answer, but he wanted me to describe \eqref{eq:1000coins:bayeslaw1} in detail. Since Bayes' law is just the application of conditional probability, you can derive it from first principles: \begin{align} @@ -113,8 +82,8 @@ \section{Answer} P( 10H ) } \end{align} -and even a frequentist will agree with you here. -The nominator is the joint probability of ten heads and the rigged coin, and it is easier to split this into another conditional probability: +and even a frequentist will agree. +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: \begin{align*} P( 10H , C_{R} ) = @@ -128,7 +97,7 @@ \section{Answer} P( C_{R} \vert 10H ) p( 10H ) \text{,} \end{align*} -but this is not helpful, as it contains the probability we are trying to determine and will lead to circular reasoning. +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. You can expand denominator in \eqref{eq:1000coins:bayesexplain} @@ -150,27 +119,19 @@ \section{Answer} \text{,} \end{align*} by applying the law of conditional probability to each of the terms. -Combining the nominator and the denominator yields \eqref{eq:1000coins:bayeslaw1}. +Putting all this together yields \eqref{eq:1000coins:bayeslaw1}. My interviewer used this Bayes' law question to test my handle on probability concepts. It is easy to confuse these basic concepts, which is another reason for doing proper interview preparation. Some interviewers ask this question and demand an ``intuitive'' solution that doesn't rely on algebraic manipulation. -In this case, you could opt for a visual explanation of Bayes' Law, like that of answer \ref{a:bayeslawdisease}. +In this case, you could opt for a visual explanation of Bayes' Law as discussed in answer \ref{a:bayeslawdisease}. If that's not what your interviewer wants, use the following argument. You know the probability of choosing the rigged coin is $1/1000$. You also know the probability of getting ten heads from a fair coin is $1/2^{10} = 1/1024$. These two events are about equally likely, meaning the probability that we have the double headed coin is about a half. If you only had nine heads in a row, the fair coin would give a probability of $1/512 = 2/1024$. -That means the outcome of nine heads is about twice as likely with the fair coin as the probability of selecting the rigged coin. +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. 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. %TODO: could link this up to section on gambling mathematics +\end{answer} - - - -%% Uncomment this if you need references -%\bibliography{references.bib} -%\bibliographystyle{chicago} - - -\end{document}