Skip to content

Bayes' formula

Bayes' formula

The reverse question

A probability tree holds the second stage’s probabilities given the first stage. Sometimes the question is the other way round: what happened in the second stage is known – what is the probability of what happened in the first?

At the school of the last lesson: 25\displaystyle \frac{2}{5} of the students are boys, and 20% of the boys and 30% of the girls are active in a youth movement.
For a youth movement conference a student was chosen at random from the active ones. What is the probability that a girl was chosen?

  • The student is known to be active, so the choice is only among the active: P(A)=0.26\displaystyle {P(A)}={0.26}.
  • Of them, the active girls: P(F∩A)=0.18\displaystyle {P(F\cap A)}={0.18}.
P(F∣A)=P(F∩A)P(A)=0.180.26=913P(F|A)=\frac{P(F\cap A)}{P(A)}=\frac{0.18}{0.26}=\frac{9}{13}

P(A∣F)=0.3\displaystyle {P(A|F)}={0.3} – of the girls, 30% are active. P(F∣A)=913≈0.69\displaystyle {P(F|A)}={\frac{9}{13}\approx0.69} – of the active, about 69% are girls. These are two different questions.

Bayes’ formula

P(A∩B)\displaystyle P(A\cap B) can be written in two ways: by a tree that starts with B\displaystyle B, and by a tree that starts with A\displaystyle A. The two products are equal, and this is Bayes’ formula:

P(A∣B)⋅P(B)\displaystyle P(A|B)\cdot P(B) =\displaystyle = P(B∣A)⋅P(A)\displaystyle P(B|A)\cdot P(A)

The formula passes from one conditional probability to its reverse: when P(B∣A)\displaystyle P(B|A), P(A)\displaystyle P(A) and P(B)\displaystyle P(B) are known, dividing by P(B)\displaystyle P(B) gives P(A∣B)\displaystyle P(A|B).

At the school: P(F∣A)⋅0.26=0.3⋅35=0.18\displaystyle {P(F|A)\cdot0.26}={0.3\cdot\frac{3}{5}}={0.18}, so P(F∣A)=0.180.26=913\displaystyle {P(F|A)}={\frac{0.18}{0.26}}={\frac{9}{13}}.

Three steps with a tree

A reverse question is solved in three steps:

  1. Build the tree in the order of the experiment.
  2. Work out the probability of what is known – the sum of its paths (the law of total probability).
  3. Divide the paths that also answer the question by that probability.

Box I holds three red balls and four green ones.
Box II holds 12 red balls and four green ones.
A box is chosen at random, and two balls are taken from it one after the other, without putting back.
The two balls are known to be the same colour. What is the probability that they were taken from box I?

E\displaystyle E – the event “the two balls are the same colour”. Its paths are marked:

  • Two balls of the same colour from box I: 12⋅37⋅26+12⋅47⋅36=114+17=314\displaystyle {\frac{1}{2}\cdot\frac{3}{7}\cdot\frac{2}{6}+\frac{1}{2}\cdot\frac{4}{7}\cdot\frac{3}{6}}={\frac{1}{14}+\frac{1}{7}}={\frac{3}{14}}.
  • From box II: 12⋅1216⋅1115+12⋅416⋅315=1140+140=310\displaystyle {\frac{1}{2}\cdot\frac{12}{16}\cdot\frac{11}{15}+\frac{1}{2}\cdot\frac{4}{16}\cdot\frac{3}{15}}={\frac{11}{40}+\frac{1}{40}}={\frac{3}{10}}.
  • The same colour: P(E)=314+310=1835\displaystyle {P(E)}={\frac{3}{14}+\frac{3}{10}}={\frac{18}{35}}.
P(I ∣ E)=3141835=314⋅3518=512P(\text{I}\,|\,E)=\frac{\frac{3}{14}}{\frac{18}{35}}=\frac{3}{14}\cdot\frac{35}{18}=\frac{5}{12}
A medical test

Bayes’ formula explains why a positive test result does not necessarily mean that a person is ill.

A rare disease affects 1% of people.
The test picks up 95% of the ill: for them the result is positive.
For 10% of the healthy the result is positive by mistake.
A person chosen at random got a positive result. What is the probability that he is ill?
S\displaystyle S – the person is ill; +\displaystyle + – the result is positive.

  • A positive result: P(+)=0.01⋅0.95+0.99⋅0.1=0.0095+0.099=0.1085\displaystyle {P(+)}={0.01\cdot0.95+0.99\cdot0.1}={0.0095+0.099}={0.1085}.
  • Ill and positive: 0.0095\displaystyle 0.0095.
P(S∣+)=0.00950.1085≈0.09P(S|+)=\frac{0.0095}{0.1085}\approx0.09

Only about 9% of those with a positive result are ill. The healthy are so many that even 10% of them are far more people than all the ill.

Exercise 1

Three boxes, A\displaystyle A, B\displaystyle B and C\displaystyle C, hold black and white balls.
Box A\displaystyle A holds two black balls and three white ones.
Box B\displaystyle B holds three black balls and two white ones.
Box C\displaystyle C holds four black balls and one white one.
A box is chosen at random, and one ball is taken from it at random.
A white ball is known to have been taken.

Complete the tree, and work out the probability that the ball was taken from box B\displaystyle B.

    / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – check and a new line · * – times · ^ – power, ↓ – end of the power

    / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – a new line · * – times · ^ – power, ↓ – end of the power

    Exercise 2

    In a factory, machine A makes 60% of the parts, and machine B – 40%.
    5% of machine A’s parts are defective, and 10% of machine B’s.
    The probability that a part chosen at random is defective is 0.07\displaystyle 0.07.
    A part chosen at random is found to be defective.

    What is the probability that it was made by machine B?

      / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – check and a new line · * – times · ^ – power, ↓ – end of the power

      / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – a new line · * – times · ^ – power, ↓ – end of the power

      Exercise 3

      At the school of the example, 25\displaystyle \frac{2}{5} of the students are boys, and 26% of all the students are active in a youth movement.
      20% of the boys are active.
      A student who is not active in a youth movement is chosen at random.

      What is the probability that it is a boy?

        / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – check and a new line · * – times · ^ – power, ↓ – end of the power

        / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – a new line · * – times · ^ – power, ↓ – end of the power

        Exercise 4

        Bag A holds seven yellow scarves and five red ones.
        Bag B holds ten scarves: some yellow and the rest red.
        One scarf is taken at random from bag A and one from bag B.
        The probability that both scarves are yellow is 740\displaystyle \frac{7}{40}.

        a

        How many yellow scarves are in bag B? Write x\displaystyle x for the number of yellow scarves in bag B, and solve an equation.

          b

          Each scarf is put back in its bag, and again a scarf is taken from each bag.
          The scarves are known to be of different colours. What is the probability that the scarf from bag B is yellow?
          The tree’s first stage – bag A, its second – bag B.

            / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – check and a new line · * – times · ^ – power, ↓ – end of the power

            / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – a new line · * – times · ^ – power, ↓ – end of the power

            Exercise 5

            2% of people have a certain disease.
            The test for the disease is positive for 90% of the ill.
            It is positive by mistake for 5% of the healthy.

            a

            A person chosen at random got a positive result. What is the probability that he is ill? Round to two decimal places.

              / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – check and a new line · * – times · ^ – power, ↓ – end of the power

              / – fraction bar · Tab or the arrows – between numerator and denominator, then a note above or below · Enter – a new line · * – times · ^ – power, ↓ – end of the power

              b

              The test picks up 90% of the ill, yet the answer to the last part is far smaller than 90%. Explain why.