Classic Bayesian Manipulation of test quantities

We are given that the prior probability of patient A having Syphilis is 0.9. Let's call this random variable S. A blood test can be administered with positive predictive value 0.9. We'll call this random variable B. Formally,

$$ p(S=tr) = 0.9, \qquad\qquad p(B=tr\,|\,S=tr) = 0.9$$

Unfortunately this is not all the information we'll need - we also need the negative predictive value of the test. We'll define this to be:

\begin{align*} p(B=fa\,|\,S=fa) &= \beta, \\\\ &\text{meaning that we can calculate}\\\\ p(B=tr) &= p(B=tr|S=tr)p(S=tr) + p(B=tr|S=fa)p(S=fa) \\ &= 0.9\times0.9 + (1-\beta)\times0.1 \end{align*}

Actual calculation

Now the quantity that we actually want is $$p(S=tr\,|\,B=tr)$$ And if you remember Bayes' rule (first line), this gives

\begin{align*} p(S=tr\,|\,B=tr) &= \frac{p(B=tr\,|\,S=tr)p(S=tr)}{p(B=tr)} \\ &= \frac{0.81}{0.81+0.1(1-\beta)} \end{align*}

which is a hyperbola in $(1-\beta)$, giving the following result:


In [1]:
import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0, 0.99, 0.01)
s = 8.1/(8.1+(1-t))
plt.plot(t, s)

plt.xlabel('Negative Predictive Value')
plt.ylabel('p(S=tr|B=tr)')
plt.title('Posterior probability of Syphilis')
plt.grid(True)
plt.savefig("test.png")
plt.show()



In [ ]: