Conditional probability
"What is the probability that it will rain?" is not the same question as "what is the probability that it will rain, given that the sky is cloudy?". The second question involves less uncertainty: you know something that has already happened, and that changes the probabilities. This section formalises that idea — conditional probability — and two of its most powerful consequences: calculating a probability by combining several causes, and "reversing" a condition using Bayes' theorem.
Conditional probability: P(A|B)
In a Spanish deck of 40 cards (4 suits with 10 cards each: jack, knight and king are the face cards of each suit), one card is drawn at random. We consider the events…
In a Spanish deck of 40 cards (4 suits with 10 cards each: jack, knight and king are the face cards of each suit), one card is drawn at random. We consider the events $A$: "drawing a king" and $B$: "drawing a face card" (jack, knight or king).
Calculate the probability that the card is a king given that a face card has come up, that is, determine $P(A|B)$.
Given two events $A$ and $B$ of a random experiment, it is known that the probability of their intersection is $P(A \cap B) = 0,12$ and that the probability of event $B$…
Given two events $A$ and $B$ of a random experiment, it is known that the probability of their intersection is $P(A \cap B) = 0,12$ and that the probability of event $B$ is $P(B) = 0,4$. Calculate the probability of $A$ occurring given that $B$ has occurred.
Contingency tables
When data come from a survey with two criteria crossed (sex and favourite subject, age and habit), a contingency table organises the frequencies and makes it very easy to see how to calculate conditional probabilities: you just look inside the relevant row or column.
| Science ($C$) | Humanities ($L$) | Total | |
|---|---|---|---|
| Girls ($M$) | 40 | 25 | 65 |
| Boys ($H$) | 15 | 20 | 35 |
| Total | 55 | 45 | 100 |
A survey was conducted among 100 1st Baccalaureate students regarding their preference between two fields of study. The data is presented in the following contingency…
A survey was conducted among 100 1st Baccalaureate students regarding their preference between two fields of study. The data is presented in the following contingency table:
| Science ($C$) | Arts ($L$) | Total | |
|---|---|---|---|
| Girls ($M$) | 40 | 25 | 65 |
| Boys ($H$) | 15 | 20 | 35 |
| Total | 55 | 45 | 100 |
If we choose a student at random and she turns out to be a girl, what is the probability that she prefers Arts? Calculate $P(L|M)$.
Tree diagrams and the product rule
Rearranging the definition of $P(A|B)$ gives the product rule: it is very useful in multi-stage experiments (successive draws), where it is shown with a tree diagram.
An urn contains 5 blue balls and 3 red balls. We draw two balls consecutively with replacement (we put the first ball back into the urn before drawing the second). a)…
An urn contains 5 blue balls and 3 red balls. We draw two balls consecutively with replacement (we put the first ball back into the urn before drawing the second).
- a) Represent the experiment with a tree diagram, indicating the probability on each branch.
- b) Calculate the probability that the second ball is red given that the first one was blue. Are the events dependent or independent? Justify your answer.
In an e-sports league, a team has a probability of winning a match of $70\,\%$ if it plays on its home server ($L$), but this probability drops to $40\,\%$ if it plays…
In an e-sports league, a team has a probability of winning a match of $70\,\%$ if it plays on its home server ($L$), but this probability drops to $40\,\%$ if it plays on an external server ($E$). It is known that $60\,\%$ of the matches are played at home.
- a) Represent the situation using a tree diagram, indicating the probability on each branch.
- b) If the team won the last match, what is the probability that it played on its home server?
- c) What is the total probability that the team wins any given match?
The law of total probability
When an outcome can arise by several different routes that do not overlap (several paths, several machines, several sources), the law of total probability adds up the contribution of each route.
Two fair six-sided dice numbered $1$ to $6$ are rolled. We consider the following events: $S$: "The sum of the scores obtained is equal to $7$". $A$: "An even number is…
Two fair six-sided dice numbered $1$ to $6$ are rolled. We consider the following events:
-
$S$: "The sum of the scores obtained is equal to $7$".
-
$A$: "An even number is rolled on the first die".
Calculate:
- a) The sample space of the sum of the scores and the probability of event $S$.
- b) The probability that the sum is $7$ given that an even number was rolled on the first die, $P(S/A)$.
- c) Does the fact that the first die is even affect the probability that the sum is $7$? Justify whether the events are dependent or independent.
Bayes' theorem
Bayes' theorem "reverses" a conditional probability: from known values of $P(A|B_i)$, it calculates $P(B_i|A)$ — for example, knowing that an order arrived late, which route is most likely to have been used?
In a cybersecurity laboratory, an artificial intelligence algorithm analyses emails to detect phishing*. It is known that: $5\%$ of the emails received by the company…
In a cybersecurity laboratory, an artificial intelligence algorithm analyses emails to detect phishing. It is known that:
-
$5\%$ of the emails received by the company are scam attempts (phishing).
-
If an email is phishing, the algorithm correctly identifies it as "suspicious" in $98\%$ of cases.
-
If an email is legitimate, the algorithm makes a mistake and marks it as "suspicious" in $3\%$ of cases (false positive).
If an employee receives a "suspicious email" alert in their inbox:
- a) What is the actual probability that the email is indeed a phishing attempt?
- b) If the algorithm indicates that the email is "safe", what is the probability that it is a mistake and actually phishing?
A study is carried out on the activities of students at a school in Madrid. The data show that: $80\%$ of students study a second language ($I$). $60\%$ of students…
A study is carried out on the activities of students at a school in Madrid. The data show that:
-
$80\%$ of students study a second language ($I$).
-
$60\%$ of students participate in a school sports team ($D$).
-
$30\%$ of those studying a second language do not participate in any sports team.
We choose a student at random. Calculate:
- a) The probability that they do both activities.
- b) Given that they participate in a sports team, the probability that they also study a second language.
- c) The probability that they do neither of the two activities.