Evaluate performance and prevalence for any series of diagnostics tests, incl. SARS
The Bayes Lines Tool is a revolutionary set of software tools for back solving disease prevalence, test performance and confusion matrices for diagnostic test reports.
How does it work?
For all permutations of prevalence, sensitivity, and specificity, the Bayes Lines Tool returns all confusion matrixes for which the true + false positives equals the number of positives reported.
No prior knowledge of prevalence, sensitivity & specificity, type of test kits, or lab guidelines is required.
The Bayes Lines Tool consists of an SQL script and a simplified version in Excel. Both are available for download.
The SQL script generates all possible Bayesian confusion matrixes for a (series of) diagnostic test results, without making assumptions about prevalence, sensitivity or specificity.
The code in standard SQL is given as follows:
with tests as ( select :report_id::text as report_id, -- Feel free to call with any string, e.g. date-string :tests as tests_performed, -- integer :cases as positives_reported --integer ), permutations as ( select (prevalence::numeric / 1000)::numeric as prevalence, (sensitivity::numeric / 1000)::numeric as sensitivity, (specificity::numeric / 1000)::numeric as specificity from generate_series(1, 500, 1) as prevalence, generate_series(30, 999, 5) as sensitivity, generate_series(75, 999, 5) as specificity ), matrices as ( select t.report_id, t.tests_performed, t.positives_reported, round(prevalence, 2) as prevalence, --just for cosmetic purposes round(sensitivity, 3) as sensitivity, round(specificity, 3) as specificity, (t.tests_performed * prevalence)::int as has_disease, --calculation with full precision for data type numeric, but (t.tests_performed * (1 - prevalence))::int as hasnot_disease, --casting to integer for cosmetic purposes (t.tests_performed * prevalence * sensitivity)::int as true_positives, (t.tests_performed * (1 - prevalence) * specificity)::int as true_negatives from tests t, permutations p ) select *, hasnot_disease - true_negatives as false_positives, has_disease - true_positives as false_negatives from matrices where (true_positives + (hasnot_disease - true_negatives)) = positives_reported order by report_id, prevalence, sensitivity, specificity
The Bayes Lines Tool can be implemented as a simple SQL script (or any other flavour of your choice). We created a version in Excel for those who do not feel comfy with programming. Note that the Excel version is a bit limited because we could not fit 7 million rows in it. Hence the resolution of the permutations is a bit rougher. Pick your flavour below.
Excel file last updated Jan 25 2021, marked as version 1.2
This group of scientists submitted a research paper titled “Bayes Lines Tool (BLT) – A SQL-script for analyzing diagnostic test results with an application to SARS-CoV-2-testing” with F1000 Research on 23 January 2021.
Follow us on our individual Twitter accounts, or join the discussion in the #UnbiasedScience channel on Telegram.
You can also reach us at firstname.lastname@example.org