-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
371 lines (326 loc) · 12.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<link href="css/bootstrap.css" rel="stylesheet">
<link rel="icon" href="img/icon.png">
<title>Antibody Result Interpretation</title>
<script src="https://d3js.org/d3.v6.min.js"></script>
<script src="js/d3-simple-slider.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js" charset="utf-8"></script>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" style="color:#9A9DA0">Nir Yungster</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="">Demo
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/yungster/positive-predictive-value">Github</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://twitter.com/NirYungster">Twitter</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://medium.com/@niryungster">Blog</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Page Text -->
<div class="container">
<div class="row">
<br>
April 27, 2020
<div class="col-lg-12 text-center">
<h1 class="mt-5">Interpreting Positive COVID-19 Antibody Tests</h1>
<p id="warning-note">
Note: this tool does not constitute medical advice. Please consult a physician before making medical decisions related to tests for the COVID-19
virus or virus antibodies. Positive antibody test results may be incorrect, and anitbody positive status is
<a href='https://www.scientificamerican.com/article/what-immunity-to-covid-19-really-means/'>not equivalent to immunity</a>.
</p>
<p class="lead" style="text-align:left; font-weight:200">A number of large-scale studies are underway to understand the prevalence of
COVID-19 antibodies in various populations. As with any medical test, antibody testing is not infallible. Some people
without the antibody will test positive (i.e. a false positive) and some with the antibody will test negative (i.e. a false negative).
<br><br>
This tool can be used to interpret the meaning of an individual positive test result in the context of an antibody
population study. Proper interpretation depends not only on the accuracy of a test, but also on the prevalence of COVID-19 antibodies in the
population being tested. You'll notice that whenever the false positive rate exceeds the prevalence, most positive test results will
be incorrect. This situation is known as a <a href="https://medium.com/@niryungster/where-you-live-affects-what-your-covid-19-test-means-a-visual-interpretation-5762d3c2a188">
false positive paradox</a>.
<br><br>
Note that this tool does not factor in whether an individual has previously tested positive for the COVID-19 virus or
displayed symptoms of COVID-19 - such factors will make a positive antibody test result more likely to be correct. <span style="font-weight:400">The tool is meant for
interpreting positive results from population studies where participants are no more or less likely to have had the COVID-19 virus than their general community at large.</span>
</p>
<hr>
<p class="lead" id="second-paragraph" style="text-align:left; font-weight:200;">
The visualization below represents a population being tested for the COVID-19 virus antibody. Each square represents 0.1% of the population being
tested and is categorized as one of the following test outcomes.
</p>
<div id='legend-img'>
<img style="height:150px" src="img/legend.png"></img>
<!-- <div class="caption" style="margin-top:10px; font-weight:200">
The four possible outcomes of an anitbody test. Gray-fill indicates a negative <br>
antibody test result, while color-fill indicates a positive test result. </div> -->
</div>
<p class="lead" id="second-paragraph" style="text-align:left;">Use the sliders below to explore the effects of test accuracy and antibody prevalence
on the <i>Positive Predictive Value</i> of a test—the likelihood that a positive test result is correct.
</p>
</div>
</div>
</div>
<!-- Demo -->
<div class="demo-container">
<div id="sliders-container">
<div id="slider-container">
<div id='infection-rate-slider'>
<span class="slider-title">Antibody Prevalence: </span>
<span id="value-infection"></span>
<div id="slider-infection"></div>
</div>
</div>
<div class="slider-container">
<div id='false-positive-rate-slider'>
<span class="slider-title">False Positive Rate: </span>
<span id="value-falsepositive"></span>
<div id="slider-falsepositive"></div>
</div>
</div>
<div class="slider-container">
<div id='false-negative-rate-slider'>
<span class="slider-title">False Negative Rate: </span>
<span id="value-falsenegative"></span>
<div id="slider-falsenegative"></div>
</div>
</div>
</div>
<div id="graphics-container">
<div id='population-container'>
<h5 id='population-title'>
Population Test Results
</h5>
<div id='population-box'></div>
</div>
<div id='positives-container'>
<h5 id='positives-title'>
All Positive Test Results
</h5>
<div id='positives-graphics'>
<div id='true-pos-block'>
<div id='true-positives-box'></div>
<h6 id='true-pos-box-text'>
True Positives
<div class='box-subheading'><i>(Has Antibody)</i></div>
</h6>
</div>
<div id='false-pos-block'>
<div id='false-positives-box'></div>
<h6 id='false-pos-box-text'>
False Positives
<div class='box-subheading'><i>(No Antibody)</i></div>
</h6>
</div>
</div>
<div id="values-container">
<h4 id='pos-pred-value-container'>
<span class="value-title">Positive Predictive Value: </span>
<span id='pos-pred-value'><br>
</h4>
</div>
<div id='sub-pred-value'><i>(Likelihood a Positive Test is Correct)</i></div>
</div>
</div>
</div>
<script src="jquery/jquery.slim.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/sliders.js" charset="utf-8"></script>
<script src="js/makeGrid.js" charset="utf-8"></script>
<script>
// color boxes based on slider values
trueNegColor = '#d9d9d9' //gray
truePosColor = '#e31a1c' //red
falsePosColor = '#feb24c' //orange
// population grid
var numRows = 25, numCols = 40, numBoxes = numCols * numRows;
makeGrid(numRows, numCols, '#population-box', 'pop-')
var numRowsTP = 15, numColsTP = 10, numBoxesTP = numColsTP * numRowsTP;
makeGrid(numRowsTP, numColsTP, '#true-positives-box', 'tp-', fillColor='#ffffff')
var numRowsFP = 15, numColsFP = 10, numBoxesFP = numColsFP * numRowsFP;
makeGrid(numRowsFP, numColsFP, '#false-positives-box', 'tn-', fillColor='#ffffff')
function shuffle(array) {
var copy = [], n = array.length, i;
// While there remain elements to shuffle…
while (n) {
// Pick a remaining element…
i = Math.floor(Math.random() * array.length);
// If not already shuffled, move it to the new array.
if (i in array) {
copy.push(array[i]);
delete array[i];
n--;
}
}
return copy;
}
var boxIndices = d3.range(1, numBoxes + 1, 1);
shuffledIndices = shuffle(boxIndices);
var iRate, fpRate, fnRate, numInfected, numHealthy,
numFP, numTP, numTN, numFN, posPredictiveValue;
var truePosBoxIndices = d3.range(1, numBoxesTP + 1, 1);
var falsePosBoxIndices = d3.range(1, numBoxesFP + 1, 1);
updateAll();
infectedRateSlider.on('onchange', function spit(d) {
d3.select('#value-infection').text(d3.format('.1%')(infectedRateSlider.value()));
updateAll();
})
falsePosSlider.on('onchange', function spit(d) {
d3.select('#value-falsepositive').text(d3.format('.1%')(falsePosSlider.value()));
updateAll();
})
falseNegSlider.on('onchange', function spit(d) {
d3.select('#value-falsenegative').text(d3.format('.0%')(falseNegSlider.value()));
updateAll();
})
function computeRates() {
iRate = infectedRateSlider.value();
fpRate = falsePosSlider.value();
fnRate = falseNegSlider.value();
numInfected = iRate * numBoxes;
numHealthy = numBoxes - numInfected;
numFP = fpRate * numHealthy;
numTN = numHealthy - numFP;
numFN = fnRate * numInfected;
numTP = numInfected - numFN;
posPredictiveValue = (1 - fnRate) * iRate / (iRate * (1 - fnRate) + (1 - iRate) * fpRate)
}
function updatePosPredVal(){
d3.select('#pos-pred-value').text(d3.format('.1%')(posPredictiveValue));
}
function updateBoxes() {
// update box indices
falseNegativesIx = shuffledIndices.slice(0, numFN);
truePositivesIx = shuffledIndices.slice(numFN, numFN + numTP);
trueNegativesIx = shuffledIndices.slice(numFN + numTP, numFN + numTP + numTN);
falsePositivesIx = shuffledIndices.slice(numFN + numTP + numTN, );
// color healthy
colorBoxes(trueNegativesIx, trueNegColor, '#ffffff', 'pop-')
// color infected
colorBoxes(truePositivesIx, truePosColor, '#ffffff', 'pop-')
// color false positives
colorBoxes(falsePositivesIx, falsePosColor, '#ffffff', 'pop-')
// false negatives
colorBoxes(falseNegativesIx, trueNegColor, truePosColor, 'pop-')
}
function updatePosBoxes() {
truePosBoxIx = truePosBoxIndices.slice(numBoxesTP - numTP, );
notTruePosBoxIx = truePosBoxIndices.slice(0, numBoxesTP - numTP);
falsePosBoxIx = falsePosBoxIndices.slice(numBoxesFP - numFP, );
notFalsePosBoxIx = falsePosBoxIndices.slice(0, numBoxesFP - numFP);
colorBoxes(truePosBoxIx, truePosColor,'#ffffff', 'tp-');
colorBoxes(notTruePosBoxIx, '#ffffff','#ffffff', 'tp-');
colorBoxes(falsePosBoxIx, falsePosColor,'#ffffff', 'tn-');
colorBoxes(notFalsePosBoxIx, '#ffffff','#ffffff', 'tn-');
}
function updateAll(){
computeRates();
updateBoxes();
updatePosBoxes();
updatePosPredVal();
}
function colorBoxes(boxArray, clr, clroutside, boxPrefix) {
boxArray.forEach(function(ix){
d3.select('#' + boxPrefix + ix).attr("fill", clr).attr("stroke", clroutside);
})
}
</script>
<style type="text/css">
.slider-title {
/* font-weight: normal; */
}
.value-title, #pos-pred-value {
/* font-size: 14pt; */
padding-bottom: 0;
}
#pos-pred-value {font-weight: bold}
#sliders-container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
margin: 5px;
align-content: center;
align-items: center;
}
#slider-container {
margin: 10px;
}
#graphics-container, #values-container, #positives-graphics {
/* width: 600px; */
display: flex;
flex-wrap: wrap;
align-content: center;
justify-content: space-around;
margin-top: 10px;
}
#true-positives-box, #false-positives-box
{
margin: 10px;
}
.rect {
padding: 2px;
}
#positives-title, #population-title {
text-align: center;
/* font-weight: bold; */
/* font-size: 14pt; */
margin: 10px;
}
#pos-pred-value-container {
padding-top: 10px;
width: 360px;
}
#false-pos-box-text, #true-pos-box-text {
text-align: center;
font-weight: 600;
}
.box-subheading {
font-weight: 100;
font-size:10pt;
}
#sub-pred-value {
text-align: center;
margin: 0px;
}
#second-paragraph {
padding-top: 0.25cm;
}
#sub-pred-value {
margin-top:0px;
font-weight:100;
}
.demo-container {
margin-bottom: 30px;
}
#legend-img {
margin-left: auto;
margin-right: auto;
}
.caption {
font-size: 10pt;
}
#warning-note {
text-align: left;
font-weight: 200;
font-style: italic;
font-size: 11pt;
padding-left: 80px;
padding-right: 80px;
}
</style>