For her vacation in Hawaii, Elizabeth has packed 5 pants, 4 skirts and 8 shirts. On her first day venturing out to explore the islands, Elizabeth is running late. In a rush to dress up, she opens her briefcase and picks out two pieces of clothing at random. Given that her first pick is a skirt, what is the probability that she is in luck and picks a shirt to go with it.
This is a typical example of conditional probability, which is the probability of a second event happening given that a first event has already occured. This particular case of conditional probability deals with dependent events. Elizabeth has to pull out a second piece of clothing that matches her first pick. Elizabeth having a matching pair of clothing is dependent on her first and second pick.
As most of you might have already guessed, the probability is: $$P(MatchingPair) = \frac{4}{17} * \frac{8}{16}$$
(Hint): She first picks a skirt with probability 4/17, which leaves her with 3 remaining skirts, 5 pants and 8 shirts. Out of the 16 remaining clothes, her only favourable picks are the 8 shirts, thus giving us 8/16. Our final answer is a combination of the first and second pick, thus giving us our final answer = 4/17 X 8/16
In probability theory, conditional probability is the probability of an event given that another event has occured. Denoted as P(B|A), is the probabilty of event B given event A has already occured.To put this into persepective, let us assume that the probability of rain on any random day is 10%. But if we know that there is a storm the same day, then the probability of rain will be much higher.
The concept of conditional probability is one of the most fundamental concepts in probability theory. While it may seem very trivial, conditional probabilities can be quite confusing and require careful attention.
Note: If events A and B are independent, then P(B|A) is simply P(B).
Given two events A and B from the sigma-field of a probability space with P(B) > 0, the conditional probability of A given B is defined as the quotient of the probability of the joint of events A and B, and the probability of B:
$$P(A|B) = \frac{P(A∩B)}{P(B)}$$Now let us prove the note mentioned earlier for independent events using this equation:
We know that, $$P(A|B) = \frac{P(A∩B)}{P(B)}$$
For independent events, we have P(A∩B) = P(A) X P(B) . Substituting this in the equation above, we get:
$$P(A|B) = \frac{P(A) X P(B)}{P(B)}$$Two events are said to be mutually exclusive when the two events cannot occur at the same time. For a given sample space either one or the other can occur, not both. They have their probabilities defined as: $$P(A)+P(B)=1$$ Furthermore,$$P(A∩B) = 0$$
Therfore the conditional probability for mutually exclusive events is 0
You toss a fair coin three times, write a program to compute the following:
#
# Let us first analyse the problem. We assume that the coin tosses are independent
#Part 1:Since each toss is independent, the probability of getting a head on any toss is 1/2
P1 = 0.5*0.5*0.5
#Part 2: Let us create the sample space
#S = [HHH,HHT,HTH,THH,HTT,TTH,THT,TTT] the favourable events are [HTT, THT, TTH]
P2 = 3/8
#Part 3: Let s1 be the event that you observe one head, and s2 be the event for two heads
#we have to find P(s2|s1), where P(s1) = 1 - P{TTT} = 7/8 and P(s2) = 4/8
#P(s2|s1) = P(s2 ∩ s1)/P(s1)
P3 = (4/8)*(8/7)
#print the answers:
print(P1,P2,P3)
0.125 0.375 0.5714285714285714
ref_tmp_var = False
try:
if (P1 == 0.125) and (P2 == 0.375) and (abs(P3 - 0.571) < 0.1):
ref_assert_var = True
ref_tmp_var = True
else:
ref_assert_var = False
print('Please follow the instructions given and use the same variables provided in the instructions.')
except Exception:
print('Please follow the instructions given and use the same variables provided in the instructions.')
assert ref_tmp_var
True
Named after the famous English statistician Thomas Bayes, Bayes' Theorem (or Bayes' Rule). The theorem provides a way to revise exsisting predictions or hypothesis given new or additional evidence. It is a direct application of conditional probability.
The formula is as follows:
$$P(A|B) = \frac{P(B|A)P(A)}{P(B)}$$Let us derive this equation using conditional probability. We know from conditional probabilities that:
$$P(A|B) = \frac{P(A∩B)}{P(B)}$$re-arranging the terms, we get: $$P(A∩B) = P(A|B).P(B)$$
Similarly,
$$P(B|A) = \frac{P(A∩B)}{P(A)}$$$$P(A∩B) = P(B|A).P(A)$$Now equating the above two results, we get: $$P(A|B).P(B) = P(B|A).P(A)$$
$$P(A|B) = \frac{P(B|A).P(A)}{P(B)}$$Let us better understand the theorem from a simple example
Example: It is the flu season and you visit your personal physician for a regular checkup. The doctor selects you at random to test for Bird flu. The virus is currently suspected to affect 1 in 10000 people across the globe. The test is 99% accurate, meaning that the false positive (you test positive when you do not have the flu) is 2%. The false negative is 0%. Your test result shows you tested positive. What is the probability that you have bird flu.
Solution:
Let us first breakdown the problem:
Let P(B) be the probability that you have bird flu
Let P(T) be the probability of testing positive
From the above problem statement, it is clear that we are required to find P(B|A)
As per Bayes' Theorem,
$$P(B|T) = \frac{P(T|B).P(B)}{P(T)}$$From total probability, we have: $$P(T) = P(T|B).P(B) + P(T|NB).P(NB)$$
where P(NB) is the probability of not having bird flu.
We have,
P(B) = 1/10000 = 0.0001
P(NB) = 1 - P(B) = 0.9999
P(T|B) = 1 [if you have swine flue you always test positive, false negativs is 0]
P(T|NB) = 0.02 (false posititve rate)
Therefore, P(T) = P(T|B).P(B) + P(T|NB).P(NB)
P(T) ≈ 0.02
The blue M&M was introduced in 1995. Before then, the color mix in a bag of plain M&Ms was (30% Brown, 20% Yellow, 20% Red, 10% Green, 10% Orange, 10% Tan). Afterward it was (24% Blue , 20% Green, 16% Orange, 14% Yellow, 13% Red, 13% Brown). A friend of mine has two bags of M&Ms, and he tells me that one is from 1994 and one from 1996. He won't tell me which is which, but he gives me one M&M from each bag. One is yellow and one is green. What is the probability that the yellow M&M came from the 1994 bag?
#
# Use the variable "ans" to denote the final probability
ans = (0.2*0.5)/(0.2*0.5+0.14*0.5)
print(ans)
0.5882352941176471
ref_tmp_var = False
try:
if abs(ans - 0.588) < 0.1:
ref_assert_var = True
ref_tmp_var = True
else:
ref_assert_var = False
print('Please follow the instructions given and use the same variables provided in the instructions.')
except Exception:
print('Please follow the instructions given and use the same variables provided in the instructions.')
assert ref_tmp_var
True