This R script does some simple calculations to determine what specificity is required to a given positive predictive value for a screening test across a range of supplied prevalences and sensitivities.
prevalence <- seq(0.005,0.050,by=0.005)
ppv <- seq(0.5,0.95,by=0.05)
sensitivity <- seq(0.85,1.0,by=0.05)
dat <- data.frame(prevalence=rep(prevalence,length(ppv)*length(sensitivity)),
ppv=rep(ppv,length(sensitivity),each=length(prevalence)),
sensitivity=rep(sensitivity,each=length(prevalence)*length(ppv)))
dat$specificity <- 1 - ((dat$prevalence*dat$sensitivity)*(1-dat$ppv))/(dat$ppv*(1-dat$prevalence))
ggplot(dat, aes(x=prevalence,y=specificity,colour=factor(ppv))) +
geom_line() +
scale_colour_discrete("Positive\nPredictive\nValue") +
scale_x_continuous("Prevalence") +
scale_y_continuous("Specificity") +
facet_wrap(vars(sensitivity),ncol=2) +
theme_bw() +
theme(legend.position="bottom")