Strep throat is a common virus. To detect whether someone has this virus, doctors administer a swab test. Even though the swab test helps doctors make a diagnoses, it does, at times, give the wrong results. Specifically, the test could come back negative when in fact a patient has strep (false negative) or the test could come back positive when in fact a patient does not have strep (false positive). As a doctor, it is important to understand the chances of these false positives and false negatives occurring so that risks could be communicated accurately with patients.
A doctor asks:
What is the probability of not having the virus given that you get a positive test result?
The doctor knows a few pieces of information to help her compute this probability (see https://www.medicinenet.com/rapid_strep_test/article.htm for reference):
The sensitivity of a test refers to the ability of the test to correctly identify the patients who have strep. This means that the rapid strep test will be positive in 95 out of 100 patients who have strep throat. 5 out of 100 patients with strep will be missed by the test referred to as false negative.
The specificity of a test refers to the ability of the test to correctly identify the patients that do not have strep. This means that the rapid strep test will be negative 98 out of 100 patients who do not have strep throat. 2 out of 100 patients without strep will be false positives.
This would be a two step simulation.
Step one of the simulation: Put 3 blue marbles in a bag and 1 red marble in a bag. Mix them up and draw one at random. If it is a blue marble, the person has strep throat. If it is a red marble, the person does not have strep throat.
Step two of the simulation: This step depends on whether or not the person in step one has strep.
If the person does have strep: Put 95 blue marbles in a bag and then put 5 red marbles in the bag. Mix them up and then draw one at random. If you draw a blue marble, the person has strep and tested positive. If you draw a red marble, the person has strep and tested negative.
If the person does not have strep: Put 98 red marbles in a bag and then put 2 blue marbles in the bag. Mix them up and then draw one at random. If you draw a red marble, the person does not have strep and tested negative. If you draw a blue marble, the person does not have strep and tested positive.
Repeat steps one and two of the simulation twenty times.
## Negative Positive Total
## No Disease 6 1 7
## Disease 1 12 13
## Total 7 13 20
P(do not have strep| positive test) = 1/13 = 7.70%
xdata <- c()
for (i in 1:10000)
{
strep <- rbinom(1,1,.75)
sensitivity <- rbinom(1,1,.95)
specificity <- rbinom(1,1,.98)
if (strep==1 & sensitivity==1) {xdata <- c(xdata, "disease_positive")}
if (strep==1 & sensitivity==0) {xdata <- c(xdata, "disease_negative")}
if (strep==0 & specificity==1) {xdata <- c(xdata, "no_disease_negative")}
if (strep==0 & specificity==0) {xdata <- c(xdata, "no_disease_positive")}
}
positiveTests <- length(which(xdata=="no_disease_positive")) + length(which(xdata=="disease_positive"))
falsePositive <- length(which(xdata=="no_disease_positive"))/positiveTests
print(falsePositive)
## [1] 0.007286225
P(do not have strep| positive test) = 0.0072862 = 0.7286225%
Let A represent that you do not have strep and let B represent that you get a positive test result. P(A|B) = P(B|A) * P(A)/P(B)
P(positive test result|do not have strep) = 2/100
P(not having strep) = 1/4
P(positive result) = P(positive test | have strep) * P(have strep) + P(positve test | do not have strep) * P(do not have strep)
= (95/100)(3/4) + (2/100)(1/4) = .7175
So, P(do not have strep | positive test) = (2/100) * (1/4) / (.7175) = .00697 = .697%