Statistics · real student question

In a mail system 20% of all messages are spam. 70% of spam messages contain the word "lottery", while only 12.5% of legitimate messages contain it. A message arrives containing the word "lottery". What is the probability that it is spam?

Question

In a certain mail system 20%20\% of all messages are spam. Statistics show that 70%70\% of spam messages contain the word lottery, while only 12.5%12.5\% of legitimate messages contain it.

A message arrives that contains the word lottery. What is the probability that it is spam?

Step-by-step solution

  1. Name the events and sort the given numbers. Let GG = "the message is spam", NN = "the message is legitimate", and LL = "the message contains the word lottery". The data are

    P(G)=0.2,P(N)=0.8P(G)=0.2,\qquad P(N)=0.8
    P(LG)=0.7,P(LN)=0.125P(L\mid G)=0.7,\qquad P(L\mid N)=0.125

    Notice the direction: you are given the probability of the word given the class, but asked for the class given the word. Reversing a conditional probability is exactly what Bayes' theorem is for.

  2. Write down Bayes' theorem for the quantity asked.

    P(GL)=P(LG)P(G)P(L)P(G\mid L)=\frac{P(L\mid G)\,P(G)}{P(L)}

    The numerator is the probability of being spam and containing the word; the denominator is the probability of containing the word at all, over the whole mail stream.

  3. Get the denominator from the law of total probability. Every message is either spam or legitimate, so those two cases partition the sample space:

    P(L)=P(LG)P(G)+P(LN)P(N)=0.7×0.2+0.125×0.8P(L)=P(L\mid G)P(G)+P(L\mid N)P(N)=0.7\times 0.2+0.125\times 0.8
    P(L)=0.14+0.10=0.24P(L)=0.14+0.10=0.24

    So about one message in four contains the word — and most of that mass comes from the far larger pool of legitimate mail.

  4. Substitute and simplify to an exact fraction.

    P(GL)=0.140.24=1424=7120.5833P(G\mid L)=\frac{0.14}{0.24}=\frac{14}{24}=\frac{7}{12}\approx 0.5833

  5. Interpret the result and sanity-check it. Seeing the word raises the probability of spam from the prior 20%20\% to about 58.3%58.3\% — strong evidence, but still far from certainty, because legitimate mail is four times as common to begin with. A useful cross-check: of a notional 10001000 messages, 200200 are spam and 140140 of those contain the word, while 800800 are legitimate and 100100 of those contain it. Of the 240240 flagged messages, 140140 are spam: 140/240=7/12140/240=7/12, matching the formula.

Answer

P(spamword)=71258.33%P(\text{spam}\mid \text{word}) = \frac{7}{12} \approx 58.33\%

Need to solve a different problem like this? Open the solver →