--- title: "Bayes Problem" author: "Prof. Eric A. Suess" date: "2/12/2024" format: html: self-contained: true --- **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](https://www.wsj.com/articles/use-of-coronavirus-rapid-tests-may-have-fueled-white-house-covid-19-cluster-experts-say-11601855665) 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](https://www.statista.com/statistics/1112993/covid-19-incidence-rate-us-by-age/) Further reading, [Abbott defends rapid COVID-19 test with interim trial results](https://www.massdevice.com/abbott-defends-rapid-covid-19-test-with-interim-trial-results/) and [Abbott: ID NOW COVID-19 results more accurate with earlier testing](https://www.massdevice.com/abbott-id-now-covid-19-results-more-accurate-with-earlier-testing/), [Abbott Statistian](https://g.co/kgs/EEPSEU) An individual is randomly chosen from this population and is given the test. Calculate the probability that (a) the test is positive, $P(+)$. (b) the individual actually suffers from the disease $D$ if the test turns out to be positive, $P(D|+)$. (c) the individual actually does not suffer from the disease $D^c$ if the test turns out to be positive, $P(D^c|+)$. (d) Is the result for $P(D^c|+)$ surprising? Explain. (e) Change the values in the lie detector code to verify your calculations. \newpage ```{r} ### 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 ```