Why is the probability of having a *rare* disease super low even if the test is very accurate? Let's say someone wants to test the probability that the person has a disease:

*

*the person gets tested for a test accuracy of 98% (P(B|A)), meaning that with 98% of the time (if a person has the rare disease, it'll correctly tell that the patient has it, and if the person don't have the disease, it'll correctly tell that it doesn't have it 98% of the time. ). So,


*

*P(B|A) = 98% = 0.98

*P(B|A^C) = 2% = 0.02


*We know that the occurance of the disease in the population (P(A)) is:

*

*1 of every 10000 people: 0.0001

*P(A) = 0.0001 and P(A^C) = 0.9999



*If the person has a positive test result, how likely is the person to actually have the disease? Let's define A: have the disease and B: test is positive.

*

*So the question is what is P(A|B) (probability that the person has the disease GIVEN that the test is positive)

*Use Bayes' rule to get the result

*

*$$P(A|B) =  \frac{P(B|A)P(A)}{P(B|A)P(A) + P(B|A^C)P(A^C)}$$

*$$P(A|B) =  \frac{0.98*0.0001}{0.98*0.0001+0.02*0.9999}$$

*$$= 0.004876592$$
so the chance that you have the disease is actually less than $1\%$ (or it is $0.49\%$)





So the probability is not even half a percent that you actually have the disease. How does this makes any sense?
 A: So while writing my question, I found a way to visualize it. I thought it'd be useful to write up a way to see it.
Example of disease probability given population information
# Prevalence of a disease in a population 
preval = 1/100
accuracy.of.test = 0.85

par(mar=c(5.1, 4.1, 4.1, 12), xpd=TRUE)
# Show graphically what is that proportion 
plot(c(0, 1), c(0, 1), type= "n", xlab = "", ylab = "", asp=1, axes=F,
     main = paste("Population prevalence of",preval, "disease in population\n(Area is proportional to the population)"))

# Show the population as a large square 1X1 
rect(0, 0, 1, 1, density = 30, col = "blue", angle = -30, border = "transparent")

# Show the proportion of people having the disease 
rect(0, 0, 0 + sqrt(preval), 0 + sqrt(preval), #density = 160, 
     col = "black", angle = 30, border = "transparent")

# Show the proportion of people that have the disease, that are tested and found a positive result 
rect(0, 0, 0+ sqrt(preval*accuracy.of.test), 0+ sqrt(preval*accuracy.of.test), #density = 160, 
     col = "red", angle = 30, border = "transparent")

# Add legend to distinguish the areas 
legend("right", 
       bg = NA, bty = "n",
       # horiz=TRUE,
       # ncol=3,
       # box.col = "white",
       inset = c(-0.35,0),
       legend = c("Population", 
                  paste0("Diseased group (",preval*100,"%)"),
                  paste0("Accuracy of test (",accuracy.of.test*100,"%)")), 
       fill = c("blue","black", "red"),
       density = c(30,NA,NA), 
       angle = c(-30,NA,NA))


# Calculate the posterior probability of having a disease -----------------

# Define the variables  
p.BgivenA = accuracy.of.test
p.BgivenA.c = 1-p.BgivenA
p.A = preval
p.A.c = 1-p.A

# Calcualte groups of probabilities 
p.BgivenA*p.A

p.BgivenA*p.A
p.BgivenA.c*p.A.c

p.BgivenA*p.A + p.BgivenA.c*p.A.c

# Actual calculation of the posterior 
p.AgivenB = p.BgivenA*p.A/(p.BgivenA*p.A+p.BgivenA.c*p.A.c)
p.AgivenB

# Get the percentage 
percent.having.rare.disease = p.AgivenB * 100 

# Conclusion 
cat("You have a",
    round(percent.having.rare.disease,2),"% chance of having the rare disease, provided that the accuracy is",
    accuracy.of.test,"% and that the probability of having the disease in the population is", preval*100,"%")

This code will give:

