Skip to content

Instantly share code, notes, and snippets.

@diracdeltas
Last active October 1, 2020 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diracdeltas/3c2f8bd070f0f536bfc9cf77dc4654dc to your computer and use it in GitHub Desktop.
Save diracdeltas/3c2f8bd070f0f536bfc9cf77dc4654dc to your computer and use it in GitHub Desktop.
COVID-19 in SF calculations

WARNING: THIS IS NOT REAL SCIENCE

I am NOT a subject matter expert. The calculations below rely on some oversimplifying assumptions which are probably wrong. This is NOT intended to be public health advice.

Bayes Theorem

P(B|A) = P(A|B) * P(B) / P(A)

Probability of being COVID-negative when you test positive for COVID in SF

definitions

A := testing positive for COVID-19
B := not having COVID-19

FPR (False Positive Rate) is defined as the probability of testing positive (A) given that you don't have COVID (B). This is P(A|B). According to https://www.medrxiv.org/content/10.1101/2020.04.26.20080911v1.full.pdf, the interquartile FPR range of COVID-19 RT-PCR tests is 0.8-4.0%, based on similar diagnostic tests evaluated in 2004-2019. Let's assume it is 0.8% for now.

P(A) is the probability of testing positive for COVID-19. According to https://data.sfgov.org/stories/s/d96w-cdge, this is 1.58% in San Francisco as of September 23, 2020.

P(B) is the probability of actually having COVID-19. We don't know what this is but we will estimate it later.

maths

Plugging in the known values:

P(B|A) = 0.008 * P(B) / 0.0158 = 0.506 * P(B)

This means a SF resident who tests positive for COVID is about half as likely to be COVID-negative compared to the average SF resident.

To make things concrete, let's assume that 1% of people in SF have COVID, so P(B) = 0.99. Then the probability that someone in SF is COVID-negative if they get a positive test result is 0.506 * 0.99 = 0.501. This has the surprising implication that even if someone gets a positive COVID test result, they are slightly more likely to be COVID-negative than COVID-positive!

Actually this is not so surprising if you remember our assumption of 0.8% FPR. If 1.58% of tests come back positive but 0.8% are false positives, then 0.8 / 1.58 = 50.6% of tests that are positive are actually false positives.

Note that this is strongly dependent on the FPR of the COVID-19 PCR tests, which we aren't sure of AFAICT. https://testguide.labmed.uw.edu/public/guideline/covid_faq suggests that it's around 0.1% rather than 0.8%. At 0.1%, the probability of a SF resident being COVID-negative despite getting a positive test result is 6.3% if we assume 99% of SF residents are COVID-negative.

Estimating SF's COVID prevalence

definitions

Z := probability that someone in SF has COVID, AKA the COVID prevalence, AKA 1-P(B)
TPR := true positive rate, AKA the percentage of people with COVID who test positive 
FNR := false negative rate, AKA the percentage of people with COVID who test negative.

FNR + TPR = 1 because everyone with COVID who is tested has either a positive or a negative test result (ignoring tests which are invalid/indeterminate).

The probability of testing positive for COVID is the sum of the probability of a true positive for COVID and the probability of a false positive for COVID:

P(A) = TPR * Z + FPR * (1-Z)

Solving for Z:

Z = (P(A) - FPR) / (TPR - FPR)

maths

Let's use the values from the previous section of P(A) = 0.0158. From https://www.acc.org/latest-in-cardiology/journal-scans/2020/05/18/13/42/variation-in-false-negative-rate-of-reverse, the FNR of RT-PCR COVID tests is 20-66%. The TPR is therefore 34-80%.

Assuming 80% TPR and 0.8% FPR:

Z = (0.0158 - 0.008) / (0.8 - 0.008) = 0.98%

Assuming 34% TPR and 0.1% FPR.

Z = (0.0158 - 0.001) / (0.34 - 0.001) = 4.37%

For all values in between, see plot below where x is FPR and y is TPR.

plot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment