Say we draw a card from a standard deck. The values of the card are 2,3, .. , 10 for the "number" cards, 10 for Jack, Queen, King and 11 for the Ace. We draw cards until we have a point total of at least 17. Use simulation to find the mean number of cards drawn.
use f <- edit() > to set up the editor
function(n=10000) {
cards <- c(2:10,10,10,10,11)
z<-rep(0,n)
for(i in 1:n) {
points <- 0
for(j in 1:20) {
points <- points + sample(cards,1)
z[i] <- j
if(points>16) break
}
}
mean(z)
}
Say your first card is a 7. How many more cards will you draw?
This is also part of Bayes' Rule:
Notice that the denominator is just the law of total probability, so we could have written the formula also in this way
only usually the first form is the one that is need because of the available information.
Example: In the company above a person is randomly selected, and that person is in a managerial position. What is the probability the person is female?
Example 1: As part of the attempt to avoid further terrorist attacks on the US some people have proposed face-recognition technics for airports. Basically each person entering the security checkpoint of the airport is photographed and the digital picture is then compared to a list of pictures of known terrorist suspects. Such systems are never 100% correct, they do make an occasional mistake. Say that the system classifies an actual terrorist as ok 50% of the time (many terrorists won't be in the database because they have never been investigated). This is called a false-negative. Also say that the system wrongly classifies an ok person as a terrorist 0.1% of the time (false-positive). Say at some large airport there are 10 million passengers per year, 20 of whom are actually terrorists. What is the probability that a person classified as a terrorist by the face-recognition system actually is not a terrorist?
Let's use the following notation:
Let A1 = "person is not a terrorist", A2 = "person is a terrorist"
B = "person is classified as a terrorist"
Now
So only 1 in 1000 people "accused" by the system actually is a terrorist!
Note: in this calculation you need to carry along a lot of digits until the final answer.
Example 2: A company has received three shipments, one each from three different suppliers. The shipment from company 1 contained 37 parts, the one from company 2 had 25 parts and the one from company 3 had 20 parts. An employee randomly selected one part from each shipment and tested it. It turned out one of them was bad. Unfortunately he did not pay attention which part came from which company. From previous experience we know that a part made by company 1 is faulty with probability 0.043. For company 2 the probability is 0.033 and for company 3 it is 0.027. What is the probability that the bad part came from company 2?
Let Ai = "part was made by company i"
B = "part is bad"
then
Bayes' Rule plays a very important role in Statistics and in Science in general. It provides a natural method for updating you knowledge based on data.