Sheet1 Sol
Sheet1 Sol
Dr. A. Alpers
Tutorial in Week 1
and
Pr(B) = Pr(B \ (A ∩ B)) + Pr(A ∩ B).
Eliminating Pr(B \ (A ∩ B)) from both equations gives
Exercise 2. Let A and B be two events, and let Ac denote the complement of A, i.e. ,Ac = Ω \ A.
Solution.
B = (B ∩ A) ∪ (B ∩ Ac ) = A ∪ (B ∩ Ac ).
Exercise 3.
Page 1 of 3
(a) According to an Oxford study from 2020, lateral flow tests (LFTs) for COVID have a true
positive rate (sensitivity) of 76.8% and a true negative rate (specificity) of 99.68%. At the
peak of the second wave 2% of England’s population were assumed to be infected with the
virus. What is the probability that a person in England with a positive LFT, at that time,
actually has COVID?
(b) What is the probability that a person in England with a positive LFT actually has COVID
if we assume that only 0.3% of England’s population have COVID?
(c∗ ) Simulate (a) by selecting a person at random from the community and deciding whether the
person has COVID. Then administer the test and decide whether it was positive. Keep a
counter for the times the test is positive and for the times the test is positive and the person
has COVID.
Solution.
(a) Let A denote the event that a person has COVID (during the peak of the second wave in
England), and let B denote the event that the LFT is positive. What we are looking for is
the probability Pr(A|B), i.e., given that the LFT is positive, what is the probability that the
person has actually COVID.
We apply Bayes’ formula
Pr(B|A)Pr(A)
.
Pr(A|B) =
Pr(B)
In our case, we know that Pr(A) = 0.02. We also know Pr(B|A) = 0.768, as this is the
probability that given a person has COVID there will be a detection (sensitivity). Further
we know that among the non-diseased people (which is 98% of the community) the test
will in 100% − 99.68% = 0.32% of the cases report a detection of COVID (‘false positive’).
Therefore, Pr(B), which is the unconditional probability that the test outcome is positive is
Pr(B) = 0.768 · 0.02 + 0.0032 · 0.98 = 0.018496. Plugging this in into Bayes’s formula gives
the probability
0.768 · 0.02
Pr(A|B) = = 0.83044982699.
0.018496
(b) Repeating the above calculations with the new numbers give:
0.768 · 0.003
Pr(A|B) = = 0.41933605125.
0.768 · 0.003 + 0.0032 · 0.997
In other words, we have a rate of false positives of about 59%!
(c) We simulate with the following MATLAB code.
1 nTrials =10^8;
2 COVIDprobability =0.02; % COVIDprobabili ty =0.003; % for ( b )
3 sensitivity =0.768;
4 specificity =0.9968;
5
6 person = rand (1 , nTrials ) ;
7 p e r s o n h a s r e a l l y C O V I D =( person <= COVIDprobability ) ;
8 t e s t p o s i t i v i f p e r s o n h a s C O V I D =( rand (1 , nTrials ) <= sensitivity ) ; % draw random numbers describing if test outcome will be
positiv if person has COVID
9 t e s t n e g a t i v i f p e r s o n h a s n o t C O V I D =( rand (1 , nTrials ) <= specificity ) ; % draw random numbers describing if test outcome will
be negativ if person hasn ’ t COVID
10
11 npositives = sum ( p e r s o n h a s r e a l l y C O V I D .* t e s t p o s i t i v i f p e r s o n h a s C O V I D +(1 - p e r s o n h a s r e a l l y C O V I D ) .*(1 -
testnegativifpersonhasnotCOVID ));
12 h as CO V ID a nd te s tp o s = sum ( p e r s o n h a s r e a l l y C O V I D .* t e s t p o s i t i v i f p e r s o n h a s C O V I D ) ;
13
14 fprintf ( ’ Trials : % d \ nPositives : % d \ nCOVID and positive : % d \ nP ( B ) : %.4 f \ n ’ , nTrials , npositives , hasCOVIDandtestpos ,
h as CO V ID a nd te s tp o s / npositives ) ;
ex COVID.m
Page 2 of 3
A simulation outcome for 108 trials gives
Trials: 100000000
Positives: 1848824
COVID and positive: 1535526
P(B): 0.8305
The probability P (B) = 0.8305 = 83.05% fits very well with the result that we expect from
the above calculations.
Exercise 4. Suppose 20% of the women in a class received an A on the test and 15% of the men
received an A. The class is 60% women, the others are men. Given that a person chosen at random
received an A, what is the probability this person is a man?
Solution. Let A be the event of receiving an A, M be the event of being a man, and M C
the event of being a woman. We are given Pr(A|M C ) = 0.20, Pr(A|M ) = 0.15, Pr(M C ) = 0.60,
Pr(M ) = 0.40. We would like to know Pr(M |A).
From Bayes Theorem we have
And, as above:
Pr(A ∩ M ) = Pr(A|M )Pr(M ) = 0.15 · 0.40 = 0.06.
Plugging everything in, we obtain
and finally
Pr(M |A) = 0.06/0.18 = 0.33.
Page 3 of 3