ppv<-function(sensitivity,specificity,prevalence){
a<-sensitivity* prevalence
b<- (1-specificity) * (1-prevalence)
a/(a+b)
}
specificity=rep(seq(0,1, length=100), each=100)
prevalence=rep(seq(0,1, length=100), times=100)
d<-data.frame(prevalence=prevalence,
specificity=specificity,
ppv=ppv(sensitivity=1,specificity=specificity, prevalence=prevalence))
g1 <- ggplot(d, aes(y=prevalence, x=specificity, z = ppv))
g1 + geom_contour(bins=20, show.legend = TRUE) + ggtitle("Positive predictive value")
specificity=rep(seq(0,1, length=100), each=100)
sensitivity=rep(seq(0,1, length=100), times=100)
d<-data.frame(prevalence=prevalence,
sensitivity=sensitivity,
ppv=ppv(sensitivity=sensitivity,specificity=specificity, prevalence=0.1))
g1 <- ggplot(d, aes(y=sensitivity, x=specificity, z = ppv))
g1 + geom_contour(bins=20, show.legend = TRUE) + ggtitle("Positive predictive value")