Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
goldsteinepi committed Jul 8, 2020
1 parent b02a0c9 commit 6bf59a2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions testing_covid19_github.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#################

#define parameter ranges
sn_pcr = seq(0.6, 0.9, by=0.01)
sn_pcr = seq(0.6, 1.00, by=0.01)
sp_pcr = seq(0.9, 0.99, by=0.01)

pop = 1000 #population size
Expand Down Expand Up @@ -35,15 +35,21 @@ for (i in 1:length(prev))
}
rm(i)

true_pos = prev * pop
true_neg = (1-prev) * pop
test_pos_true_pos = round(sn_pcr * true_pos)
#test_pos_true_pos = round(sn_pcr[4] * true_pos)
test_neg_true_pos = true_pos - test_pos_true_pos
test_neg_true_neg = round(sp_pcr * true_neg)
test_pos_true_neg = true_neg - test_neg_true_neg
#for a given value of SN, SP
# true_pos = prev * pop
# true_neg = (1-prev) * pop
# test_pos_true_pos = round(sn_pcr * true_pos)
# test_neg_true_pos = true_pos - test_pos_true_pos
# test_neg_true_neg = round(sp_pcr * true_neg)
# test_pos_true_neg = true_neg - test_neg_true_neg

plot(x=prev, y=fn_hi, type="n", ylim=c(0,pop/2), xlab="Hypothetical COVID-19 prevalence", ylab="Count of tests")
plot(x=prev[1:4], y=fn_hi[1:4], type="n", ylim=c(0,150), xlab="Hypothetical COVID-19 prevalence", ylab="Count of tests", main="A)")
polygon(x=c(min(prev[1:4]),max(prev[1:4]),max(prev[1:4]),min(prev[1:4])), y=c(min(fn_hi[1:4]),max(fn_hi[1:4]),max(fn_lo[1:4]),min(fn_lo[1:4])), col=rgb(red=0.8,blue=0.8,green=0.8,alpha=1), border="NA")
polygon(x=c(min(prev[1:4]),max(prev[1:4]),max(prev[1:4]),min(prev[1:4])), y=c(max(fp_hi[1:4]),min(fp_hi[1:4]),min(fp_lo[1:4]),max(fp_lo[1:4])), col=rgb(red=0.2,blue=0.2,green=0.2,alpha=.75), border="NA")
lines(x=prev[1:4], y=prev[1:4] * pop, lwd=3)
legend("topleft", legend=c("False positives","False negatives","True prevalence"), fill=c(rgb(red=0.2,blue=0.2,green=0.2,alpha=.75),rgb(red=0.8,blue=0.8,green=0.8,alpha=1),NA), border=c("black","black","white"), lty=c(NA,NA,1), cex=0.8)

plot(x=prev, y=fn_hi, type="n", ylim=c(0,pop/2), xlab="Hypothetical COVID-19 prevalence", ylab="Count of tests", main="B)")
polygon(x=c(min(prev),max(prev),max(prev),min(prev)), y=c(min(fn_hi),max(fn_hi),max(fn_lo),min(fn_lo)), col=rgb(red=0.8,blue=0.8,green=0.8,alpha=1), border="NA")
polygon(x=c(min(prev),max(prev),max(prev),min(prev)), y=c(max(fp_hi),min(fp_hi),min(fp_lo),max(fp_lo)), col=rgb(red=0.2,blue=0.2,green=0.2,alpha=.75), border="NA")
lines(x=prev, y=prev * pop, lwd=3)
Expand Down Expand Up @@ -73,3 +79,4 @@ test_pos_true_neg = true_neg - test_neg_true_neg
range(test_neg_true_pos) #fn
range(test_pos_true_neg) #fp


0 comments on commit 6bf59a2

Please sign in to comment.