Bayes Problem

Author

Prof. Eric A. Suess

Published

February 12, 2024

Instructions: Complete each of the following question on paper and run the code in an R Quarto Notebook.

Question 1

In the recent Wall Street Journal Article Use of Coronavirus Rapid Tests May Have Fueled White House Covid-19 Cluster, Experts Say there is a description of how the rapid test has been used in the White House.

“What seems to have been fundamentally misunderstood in all this was that they were using it almost like you would implement a metal detector,” said Ashish Jha, dean of Brown University’s School of Public Health.

All tests, including those processed in a lab, can produce false negatives, he and other experts say. Some studies have shown that the Abbott Now ID test, which can produce a result in minutes, has around a 91% sensitivity—meaning 9% of tests can produce false negatives.

Suppose a test for COVID-19 has a 0.91 probability of positively (+) identifying the disease \(D\) when it is present. Suppose the test wrongly positively (+) identifies the disease \(D^c\) with probability 0.05 when the disease is not present. From statistical data it is known that 403.6 of 100,000 people in the population have the disease, so the prevalence of COVID-19 in the population is appoximately \(P(D) = 0.004\). Source: statista Further reading, Abbott defends rapid COVID-19 test with interim trial results and Abbott: ID NOW COVID-19 results more accurate with earlier testing, Abbott Statistian

An individual is randomly chosen from this population and is given the test. Calculate the probability that

  1. the test is positive, \(P(+)\).
  2. the individual actually suffers from the disease \(D\) if the test turns out to be positive, \(P(D|+)\).
  3. the individual actually does not suffer from the disease \(D^c\) if the test turns out to be positive, \(P(D^c|+)\).
  4. Is the result for \(P(D^c|+)\) surprising? Explain.
  5. Change the values in the lie detector code to verify your calculations.
### Conditional Probability Simulation
### Bayesian Probability

# lie detector

prev <- 0.50    # prevalence = P(L)
sens <- 0.80    # sensitivity = P(+|L)
spec <- 0.90        # specificity = 1 - P(+|L^c)

reps <- 10000

true.pos.test.pos <- 0  # counter for lie detector catching a truly lying person
test.pos <- 0       # counter for lie detector says person is lying

for(i in 1:reps){
    # simulate a person as lying or not
    lie <- 0
    if(runif(1) < prev){
        lie <- 1
    }
    # if lying simulate if test positive or not
    if(lie == 1 ){
        if(runif(1) <= sens){
            test.pos <- test.pos + 1
            true.pos.test.pos <- true.pos.test.pos + 1
        }
    }
    # if not lying simulate if test positive or not
    else{
        if(runif(1) <= (1-spec)) test.pos <- test.pos + 1
    }
}

# simulated probability

true.pos.test.pos/test.pos
[1] 0.8861607