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?
*Must do this problem through simulation in R (or other software) AND after you have simulated, you must compute the probability theoretically. Check that answers “match.” Minimum of 10,000 runs for the simulation. Open up a new RMarkdown file. Complete the activity. Make sure you are using complete sentences, different sections for different parts of the problem, etc.
P(having strep) = .15 P(has no strep) = .85 P(false negative) = .10 P(false positive) = .01 P(true positive∣has strep) = 1−0.10 =0.90
xdata = c()
for (i in 1:10000)
{
strep <- rbinom(1,1,.15)
# false_negative <- rbinom(1,1,.10)
# false_positive <- rbinom(1,1,0.01)
#the .15 chance strep is given
if (strep == 1)
{
test <- rbinom(1, 1, .90)
#we test the prob. of .9
if (test == 1)
{
xdata = c(xdata, "true_positive")
}
# fails the .9 test
if (test == 0)
{
xdata = c(xdata, "false_negative")
}
}
#strep is not given
if (strep == 0)
{
#test for false positive .01 prob.
test <- rbinom(1, 1, .01)
#is false positive
if (test == 1)
{
xdata = c(xdata, "false_positive")
}
# does not have strep and tests negative
if (test == 0)
{
xdata = c(xdata, "true_negative")
}
}
}
xdata[1:10]
## [1] "true_negative" "true_negative" "true_negative" "true_negative"
## [5] "true_negative" "true_negative" "true_negative" "true_positive"
## [9] "true_negative" "true_negative"
falsePositives <- length(which(xdata == "false_positive"))
truePositives <- length(which(xdata == "true_positive"))
falsePositives / (falsePositives + truePositives)
## [1] 0.06058543
The chances of not having Strep and not have the test be positive, it will be around a 5.88% chance.
##The theoretical calculation would be: P(no strep and positive)=(0.85)(0.01)=0.0085 P(strep and positive)=(0.15)(0.90)=0.135
P(no strep∣positive)<- 0.0085/(0.0085+ 0.135)
no_strep_positive <- (0.0085/(0.0085+ 0.135))
print(no_strep_positive)
## [1] 0.05923345
The theoretical probability of not having strep and it showing up as positive will would be around 5.92%. We have 5.88% based on simulation and 5.92% based off of theoretical probability.Both are fairly close and off by a margin of less than 0.1%, we cam assume both will “match” ifwe were to add more trials in our simulation.