Sensitivity and Specificity
Bayes' theorem
For two events H and E, the simplest form of Bayes' theorem is: $$ P(H | E) = \frac {P(E | H) P(H)} {P(E)} . $$ The event H is called hypothesis and the event E is called evidence. The Bayes' formula is used to update the prior (a priori) probability P(H) of the hypothesis to the posterior (a posteriori) probability P(H | E) after observing the evidence E.
Sensitivity and specificity
We know:
- Suppose that 5 in 1,000 people (0.5%) has a particular disease (prevalence of the disease).
- A diagnostic test for the disease has 99% sensitivity (if a person has the disease, the test will give a positive result with a probability of 0.99).
- The test has 98% specificity (if a person does not have the disease, the test will give a negative result with a probability of 0.98).
We ask:
- What is the probability that a person has the disease after he was tested positive.
- What is the probability that a person does not have the disease after she was tested negative.
The hypotheses are the events $D$ to have the disease and
the events $\overline{D}$ of not having the disease and the prior probabilities are
$$\begin{align}
P(D) & = 0.005 = preval \\
P(\overline{D}) & = 0.995 .
\end{align}$$
The evidence is the test being positive (+) or negative (-).
The sensitivity and specificity
give the conditional probabilities:
$$\begin{align}
P(+ | D) & = 0.99 = sens \\
P(- | D) & = 0.01 \\
P(+ | \overline{D}) & = 0.02 \\
P(- | \overline{D}) & = 0.98 = spec
\end{align}$$
The posterior probabilities are given by Bayes formula.
Positive prediction:
$$\begin{align}
P(D | +) & = \frac{P(+ | D) P(D)} {P(+ | D) P(D) + P(+ | \overline{D}) P(\overline{D}) } \\
& = \frac{sens \times preval} {sens \times preval + (1- spec) \times (1 - preval) } \\
& = \frac{0.99 \times 0.005} {0.99 \times 0.0005 + 0.02 \times 0.995} = 0.20
\end{align}$$
and negative prediction:
$$\begin{align}
P(\overline{D} | -) & = \frac{P(- | \overline{D}) P(\overline{D})} {P(- | D) P(D) + P(- | \overline{D}) P(\overline{D}) } \\
& = \frac{spec * (1 - preval)} {spec \times (1 - preval) + (1 - sens) \times preval} \\
& = \frac{0.98 \times 0.995} {0.98 \times 0.9995 + 0.01 \times 0.005} = 1.0
\end{align}$$
The quantity $P(D|+)$ is the probability that someone with a positive test actually has the disease. It is called in epidemiology the positive predictive value of a test. The quantity $P(\overline{D} | -)$ is the probability that someone with a negative test actually does not have the disease. It is called in epidemiology the negative predictive value of a test.
In the example the positive predictive value of the test is fairly poor: only around 20% percent of the people testing positive have the disease. This can be easily understood: if the disease is fairly rare then the false positive will be much more numerous than the true positive. On the other hand the negative predictive value is excellent.
The situation changes when only people with some symtoms are tested. Then the prevalence increases to a high value, say 50%. The corresponding positive predictive value changes dramatically: $$\begin{align} P(D | +) & = 98 \% \\ P(\overline{D} | -) & = 99 \%. \end{align}$$
Covid-19 Tests
The following values for Covid-19 fast antigen tests were reported in Tages-Anzeiger on 16-Oct-2020:
Sensitivity | Specificity | |
---|---|---|
Roche | 96.52% | 99.68% |
Abbott | 93.30% | 99.40% |
Python program
def positivePrediction(prevalence, sensitivity, specificity):
numerator = sensitivity * prevalence
denominator = sensitivity * prevalence + (1 - specificity) * (1 - prevalence)
return numerator / denominator
def negativePrediction(prevalence, sensitivity, specificity):
numerator = specificity * (1 - prevalence)
denominator = specificity * (1 - prevalence) + (1 - sensitivity) * prevalence
return numerator / denominator
Links
-
Bayes formula
(the formula for the negative predictive value is not correct)
Lectures by Prof. Luc Rey-Bellet, University of Massachusetts
Whole course
Other courses - PCR-Tests auf SARS-CoV-2 Deutsches Ärzteblatt
- Covid-19 test accuracy supplement: The math of Bayes’ Theorem by Jeffrey L. Schnipper and Paul E. Sax (August 2020)