Wang Haihua
🚅 🚋😜 🚑 🚔
The Bayes' Theorem is occasionally called inverse probability theorem. As the name tells, if we have known $p(A|B)$, then Bayes' Theorem can tell us about $P(B|A)$.
To see how Bayes' Theorem is derived, start from conditional probability
$$ P(A|B)P(B)=P(A\cap B)\\ P(B|A)P(A)=P(A\cap B) $$Equate and arrange, we obtain the famous Bayes' Theorem:
$$ P(B|A) = \frac{P(A|B)P(B)}{P(A)} $$If there are $k$ partitions of $B$, $P(A)$ can bee explicitly written in total probability form
$$ P(B_i|A)=\frac{P(A|B_i)P(B_i)}{\sum_{i=0}^k P(A|B_i)P(B_i)} $$Since Bayes' Theorem can be somewhat counterintuitive, it might take some time to grasp the tricky logic lurking behind.We will go through some examples, it is advised to study them thoroughly.
A certain disease affects about 1 out of 10,000 people. There is a test to check whether the person has the disease. The test is quite accurate. In particular, we know that
the probability that the test result is positive (suggesting the person has the disease), given that the person does not have the disease, is only 2 percent;
the probability that the test result is negative (suggesting the person does not have the disease), given that the person has the disease, is only 1 percent.
A random person gets tested for the disease and the result comes back positive. What is the probability that the person has the disease?
Event $A$: the test result is positive
Event $B$: the person has the disease
pB_A =( .99*.0001)/(.99*.0001+.02*.999)
print('The probability that a person have positive results and having the disease is %.3f%%.'%(pB_A*100))
The probability that a person have positive results and having the disease is 0.493%.
The result comes with a supprise. But if you dwell on it a while, you will notice an obvious fact that there are much more 'healthy people'(people who do not have this type of disease) i.e. $9999:1$. Even if you got to guess, you should consider this fact, which we call prior. It means even if a person has a positive result, yet he is extremely likely to be from healthy group.
You can think this as an algothrim of computing Bayes' Theorem: first we find all people who have positive results, dispite that they have disease or not, then we find all people who truly have disease and with a positive result. The ratio of them is the probability of having the disease given the positive result.
Even if $100\%$ of patients with pancreatic cancer have a certain symptom, when someone has the symptom, it does not mean that this person has a $100\%$ chance of getting pancreatic cancer. Assume the incidence rate of pancreatic cancer is $1/100000$, while $1/10000$ healthy individuals have the same symptoms worldwide, the probability of having pancreatic cancer given the symptoms is only $9.1\%$, and the other $90.9\%$ could be 'false positives'.
What is the probability of having pancreatic cancer if the person has corresponding symptoms.
Event $A$: the person has symptoms
Event $B$: the person has the pancreatic cancer
pB_A = (1/100000)/(1/100000+1/10000*0.91)
print('The probability that a person who has symptoms truly have pancreatic cancer is %.3f%%.'%(pB_A*100))
The probability that a person who has symptoms truly have pancreatic cancer is 9.901%.
A factory produces an item using three machines—A, B, and C—which account for $20\%$, $30\%$, and $50\%$ of its output, respectively. Of the items produced by machine A, $5\%$ are defective; similarly, $3\%$ of machine B's items and $1\%$ of machine C's are defective. If a randomly selected item is defective, what is the probability it was produced by machine C?
pB_A = .5*.01/(.2*.05+.3*.03+.5*.01)
print('The probability that a defective product made by machine C is %.3f%%.'%(pB_A*100))
The probability that a defective product made by machine C is 20.833%.
Bag I contains 4 white and 6 black balls while another Bag II contains 4 white and 3 black balls. One ball is drawn at random from one of the bags and it is found to be black. Find the probability that it was drawn from Bag I.
Event $A$: black ball
Event $B$: from bag I
pB_A = 6/10*.5/(6/10*.5+3/7*.5)
print('The probability that the ball is from Bag I given it is black is %.3f%%.'%(pB_A*100))
The probability that the ball is from Bag I given it is black is 58.333%.
A man is known to speak truth 2 out of 3 times. He throws a die and reports that number obtained is a four. Find the probability that the number obtained is actually a four.
Event $B$: speak truth
Event $A$: reports number 4
pB_A = (1/6*2/3)/(1/6*2/3+5/6*1/3)
print('The probability that he obtains 4 given given he speaks the truth is %.3f%%.'%(pB_A*100))
The probability that he obtains 4 given given he speaks the truth is 28.571%.
A company audit reveals that $4 \%$ of department budgets contain errors. A program is developed to analyze budgets and in a test, identifies errors in $98 \%$ of budgets with errors and $5 \%$ of those without. If a budget is marked by the program as possibly having an error, what is the probability that the budget DOES have an error?
Event A: Program has an error
Event B: The budget has an error
pB_A = .98*.04/(.98*.04+.05*.96)
print('The probability that the budget got flagged and does have an error is %.3f%%.'%(pB_A*100))
The probability that the budget got flagged and does have an error is 44.954%.