1
$\begingroup$

I had an algebra student I know ask me an interesting question: What is the probability of drawing a heart out of a deck of cards, and then drawing an even number right after it?

Clearly, the probability of drawing a heart out of the deck is 13/52, or 1/4. The probability of drawing an even number as card #2 ($c\in\{2,4,6,8,10\}$) for any suit is 20/51, except when the first card drawn is an even heart, then the probability of the second draw is 19/51.

I wish it were as simple as $ P(E|H) = \frac{P(E\cap H)}{P(H)} = \frac{\frac{5}{52}}{\frac{13}{52}} = \frac{5}{13} $.

My Monte Carlo simulation I wrote to simulate this process does not match: I get something in the neighborhood of 9-10% from the code I wrote. Where is my logic faulty?

import java.util.Random;

public class CardCounter {

    /**
     * @param args
     */
    public static void main(String[] args) {
        int heartThenEvenCount = 0;
        int cardsNotEqualCount = 0;

        for(int i = 0; i < 1000000; i++) {
            Random r = new Random();

            int card1 = r.nextInt(51) + 1;
            int card2 = r.nextInt(51) + 1;

            /* Assume that 1-13 are hearts
            Ace = 1
            King = 0
            Queen = 12
            Jack = 11
            Other numbers as they are written on card. */

            //Make sure the cards are not the same
            if(card1 != card2) {
                // Check to see if the first card is a heart.
                cardsNotEqualCount++;
                if(card1 <= 13) {
                    // Check to see if the second card is even, but not a face card.
                    int card2Rank = (card2 % 13); 
                    if(card2Rank > 0 && card2Rank <= 10 && (card2Rank % 2) == 0) {
                        heartThenEvenCount++;
                    }
                }
            }
        }
        System.out.println(heartThenEvenCount + " / " + cardsNotEqualCount);
        System.out.println(heartThenEvenCount/(double)cardsNotEqualCount);
    }
}
$\endgroup$
  • $\begingroup$ I was going to suggest the law of total probability as well, but saw that you already have 2 fine responses. $\endgroup$ – StatsStudent May 7 '16 at 3:52
  • $\begingroup$ I prefer the newer response by David, as it's much more elegant to use independence in this scenario. However, the other responses are a good example of how to proceed when the events are not independent. $\endgroup$ – Aaron Voelker May 7 '16 at 7:19
  • 1
    $\begingroup$ Please note that creating new Random instance in every loop step is inefficient, and more importantly, it will make random numbers of inferior quality. $\endgroup$ – Display Name May 7 '16 at 17:34
  • $\begingroup$ Good call. I wrote this in about ten minutes, so pardon the bad programming (and perhaps even statistical) practice. :) $\endgroup$ – ZachTheRiah May 7 '16 at 20:49
2
$\begingroup$

I don't know what the heck your "wish it were as simple as" analytical calculation is supposed to be, but you have already laid out the pieces, and just need to combine them properly. Use the law of total probability and break down (condition on) whether the 1st card heart is not an even number or is an even number.

So P(1st card is heart and 2nd card is an even number) = P(1st card is heart and not an even number) * P(2nd card is even number given 1st card is not an even number) + P(1st card is heart and is an even number) * P(2nd card is even number given 1st card is an even number) = $(8/52) (20/51) + (5/52) (19/51) = .0961538...$ which is in the 9 to 10% neighborhood you say your simulation provided.

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Your $P(E|H) = 5/13$ is just the probability that the 1st card is an even number given that it is a heart. But of course, that doesn't answer the original question even though it is relevant information. $\endgroup$ – Mark L. Stone May 7 '16 at 3:12
2
$\begingroup$

You probably need the law of total probability. For clarity, let's denote the following events: \begin{align} & A = \{\text{the first drawing is a heart}\}, \\ & B = \{\text{the second drawing is an even number}\}, \\ & C = \{\text{the first drawing is an even number}\}. \end{align} The probability of interest is $P(A \cap B)$, which is $P(A)P(B \mid A)$. Clearly, as you stated $P(A) = 1/4$. To find $P(B \mid A)$, by law of total probability, \begin{align} P(B \mid A) & = P(B \cap C \mid A) + P(B \cap C^c \mid A) \\ & = P(B \mid C \cap A)P(C \mid A) + P(B \mid C^c \cap A)P(C^c \mid A). \end{align} It is straightforward to verify that \begin{align} & P(C \mid A) = \frac{P(A \cap C)}{P(A)} = \frac{5/52}{13/52} = \frac{5}{13}, \\ & P(C^c \mid A) = \frac{P(A \cap C^c)}{P(A)} = \frac{8}{13}, \\ & P(B \mid C \cap A) = \frac{19}{51}, \\ & P(B \mid C^c \cap A) = \frac{20}{51}. \end{align} Thus $P(B \mid A) = \frac{255}{663}$, and the final answer is $255/2652 = 0.09615385$.

| cite | improve this answer | |
$\endgroup$
2
$\begingroup$

Drawing a heart on the first card and drawing an even number on the second card are independent events, so the answer is just the product of the individual probabilities. Drawing a heart is 1/4 and drawing an even number is 5/13, so the answer is 5/52 = .0961538...

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Maybe it needs a bit of explanation (probability that you draw an even number in the second drawing is the same as in the first drawing and it is the same if you take into account only 1/4 of the cases when you draw it and 1/4 of the cases when you do not do it (or 1/4 of the cases when you draw an even number in the first drawing, reducing the probability, and 1/4 of the cases when you draw another card in the first drawing, not reducing the probability)), but it is really as simple as OP wished. $\endgroup$ – BartekChom May 7 '16 at 7:11
  • $\begingroup$ To hopefully be a bit more clear: if $A$ is the event that the first card is a heart, and $B$ is the event that the second card is even, then knowing that $A$ has occurred doesn't affect the probability that $B$ will occur. That is, $P(B|A) = P(B)$, which means $P(A \cap B) = P(A)P(B)$ (see indepedence). $\endgroup$ – Aaron Voelker May 7 '16 at 7:17
  • $\begingroup$ It looks to me this anwser used circular proof: without showing $P(B \mid A) = P(A)$, how can you claim indepedence? The intuition cannot replace mathematical proof. $\endgroup$ – Zhanxiong May 7 '16 at 14:36
  • 1
    $\begingroup$ Sure it can.. you can always revert back to first principles to rigorously show $P(B | A) = P(A)$ as the other responses have done in an indirect way, but there comes a time when that is a waste of effort, and it suffices to use your understanding of what a concept means. You see this all the time in higher level mathematics. Rigour is often left for when additional understanding can be revealed (which is indeed the case for the original poster, which is why I did not downvote the other answers) or to convince the unconvinced. Just saying, you shouldn't be so quick to dismiss this answer. $\endgroup$ – Aaron Voelker May 7 '16 at 19:13
  • $\begingroup$ Correction: $P(B|A) = P(B)$ for the previous two comments. $\endgroup$ – Aaron Voelker May 7 '16 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.