Homework Week 2 Conditional Probability

  1. There are 540 identical plastic chips numbered 1 through 540 in a box. What is the probability of reaching into the box and randomly drawing the chip numbered 505? Express your answer as a fraction or a decimal number rounded to four decimal places.

Answer: .0019

print(round(1/540,4))
## [1] 0.0019
  1. Write out the sample space for the given experiment. Separate your answers using commas. When deciding what you want to put into a salad for dinner at a restaurant, you will choose one of the following extra toppings: asparagus, cheese. Also, you will add one of following meats: eggs, turkey. Lastly, you will decide on one of the following dressings: French, vinaigrette. (Note: Use the following letters to indicate each choice: A for asparagus, C for cheese, E for eggs, T for turkey, F for French, and V for vinaigrette.)

Sample Space: {AEF, AEV, ATF, ATV, CEF, CEV, CTF, CTV}

Toppings <- c('A','C')
Meats <- c('E','T')
Dressings <- c('F','V')

for (t in Toppings){
  for (m in Meats){
    for (d in Dressings){
      print(paste0(t,m,d))
    }
  }
}
## [1] "AEF"
## [1] "AEV"
## [1] "ATF"
## [1] "ATV"
## [1] "CEF"
## [1] "CEV"
## [1] "CTF"
## [1] "CTV"
  1. A card is drawn from a standard deck of 52 playing cards. What is the probability that the card will be a heart and not a face card? Write your answer as a fraction or a decimal number rounded to four decimal places.

1st assumption: 13 Heart Cards. 2nd assumption: 10/13 Heart Cards are NOT Face Cards. Or in other words, 3/13 Heart Cards are Face Cards.

Answer: 10/52

print(round(10/52,4))
## [1] 0.1923
  1. A standard pair of six-sided dice is rolled. What is the probability of rolling a sum less than 6? Write your answer as a fraction or a decimal number rounded to four decimal places.

There are a total of 36 combinations that two die can roll. (Die1: 6 combinations x Die2: 6 combinations = 36 combinations). There are only 10 combinations that produce a sum less than 6.

Hence, the answer is 10/36.

Die1 <- 1:6
Die2 <- 1:6
Total <- 0
LessThan6 <- 0

for (roll in Die1){
  for (roll2 in Die2){
    if (roll + roll2 < 6){
      LessThan6 <- LessThan6 + 1
    }
    Total <- Total + 1
  }
}

print(round(LessThan6/Total,4))
## [1] 0.2778
  1. A pizza delivery company classifies its customers by gender and location of residence. The research department has gathered data from a random sample of 2001 customers. The data is summarized in the table below.

What is the probability that a customer is male? Write your answer as a fraction or a decimal number rounded to four decimal places.

P(M) = Males/Total = 964/2001.

print(round(964/2001, 4))
## [1] 0.4818
  1. Three cards are drawn with replacement from a standard deck. What is the probability that the first card will be a club, the second card will be a black card, and the third card will be a face card? Write your answer as a fraction or a decimal number rounded to four decimal places.

There are 13 club cards in a standard deck. The probability that the first card will be a Clubs card P(C1) = 13/52. There are a total of 26 black cards in a standard deck. The probability that the second card will be black P(C2) = 26/52. There are a total of 12 face cards in a standard deck. The probabiliy that the third card will be a face card P(C3) = 12/52.

Hence, the answer for the probability of all three occurring is: 13/52 * 26/52 * 12/52.

print(paste0("Probability of Clubs: ", x <- round(13/52, 4)))
## [1] "Probability of Clubs: 0.25"
print(paste0("Probability of Black Cards: ", y <- round(26/52, 4)))
## [1] "Probability of Black Cards: 0.5"
print(paste0("Probability of Face Cards: ", z <- round(12/52, 4)))
## [1] "Probability of Face Cards: 0.2308"
print(paste0("The probability that all three occurring is: ", round((x*y*z), 4)))
## [1] "The probability that all three occurring is: 0.0288"
  1. Two cards are drawn without replacement from a standard deck of 52 playing cards. What is the probability of choosing a spade for the second card drawn, if the first card, drawn without replacement, was a heart? Write your answer as a fraction or a decimal number rounded to four decimal places.

There are 13 Heart Cards in a standard deck. The probability of the 1st card being a heart is P(C1) = 13/52. If the card is not replaced, the total deck would now be 51. Again, there are 13 Spade cards in this deck. So the probability of the second card being a Spade would be P(C2) = 13/51. Therefore, the probability that P(C2 | C1) = P( C2 & C1 ) / P(C1).

If you calculate out the results, P( C2 & C1) = (13/52) * (13/51) = (13/204) So, P(C2 | C1) = P( C2 & C1 ) / P(C1) = (13/204) / (13/52) = 13/51.

print( round( ((13/52) * (13/51))/(13/52) , 4))
## [1] 0.2549
  1. Two cards are drawn without replacement from a standard deck of 52 playing cards. What is the probability of choosing a heart and then, without replacement, a red card? Write your answer as a fraction or a decimal number rounded to four decimal places.

Again, like question 7, there are 13 Heart cards. P(C1) = 13/52. If not replaced, there is 51 cards. A Heart card is always a red card, thus making a total of 25 red cards in the deck. P(C2) = 25/51.

Therefore, the answer to P(C2 & C1) = ( 13/52 * 25/51 ) = 25/204.

print( round( (13/52) * (25/51) , 4))
## [1] 0.1225
  1. There are 85 students in a basic math class. The instructor must choose two students at random.

What is the probability that a junior female and then a freshmen male are chosen at random? Write your answer as a fraction or a decimal number rounded to four decimal places.

Probability of the first student as junior female: 4/85. Probability of the second student as male freshman, if 1st student is not replaced: 12/84 Answer: (4/85) * (12/84) = (4/595)

print(round(4/595,4))
## [1] 0.0067
  1. Out of 300 applicants for a job, 141 are male and 52 are male and have a graduate degree.

Step 1. What is the probability that a randomly chosen applicant has a graduate degree, given that they are male? Enter your answer as a fraction or a decimal rounded to four decimal places.

Answer: P( Grad Degree | Male) = P (Grad Degree & Male) / P (Male) = (52/300) / (141/300) = 52/141

print(round(52/141,4))
## [1] 0.3688

Step 2. If 102 of the applicants have graduate degrees, what is the probability that a randomly chosen applicant is male, given that the applicant has a graduate degree? Enter your answer as a fraction or a decimal rounded to four decimal places.

Answer: P( Male | Grad Degree) = P( Male & Grad Degree) / P(Grad Degree) = (52/300) / (102/300) = 52/102.

print(round(52/102,4))
## [1] 0.5098
  1. A value meal package at Ron’s Subs consists of a drink, a sandwich, and a bag of chips. There are 6 types of drinks to choose from, 5 types of sandwiches, and 3 types of chips. How many different value meal packages are possible?
Drinks <- c('D1','D2','D3','D4','D5','D6')
Sandwiches <- c('S1','S2','S3','S4','S5')
Chips <- c('C1','C2','C3')

TotalCounter <- 0
for (d in Drinks){
  for (s in Sandwiches){
    for (c in Chips){
      TotalCounter <- TotalCounter +1
    }
  }
}

print(paste0("The total amount of different combinations available are: ", TotalCounter))
## [1] "The total amount of different combinations available are: 90"

Of course, the short cut would be: 6 * 5 * 3 = 90.

  1. A doctor visits her patients during morning rounds. In how many ways can the doctor visit 5 patients during the morning rounds?
print(factorial(5))
## [1] 120
  1. A coordinator will select 5 songs from a list of 8 songs to compose an event’s musical entertainment lineup. How many different lineups are possible?

A permutation function was developed with formula n! / (n-r)! Answer: 6720

Permutation <- function(n,r){
  return(factorial(n)/(factorial(n-r)))
}

print(Permutation(8,5))
## [1] 6720
  1. A person rolls a standard six-sided die 9 times. In how many ways can he get 3 fours, 5 sixes and 1 two?
print(factorial(9) / (factorial(3) * factorial(5) * factorial(1)))
## [1] 504
  1. How many ways can Rudy choose 6 pizza toppings from a menu of 14 toppings if each topping can only be chosen once?
Combination = function(n,r) {
    return(factorial(n) / (factorial(n-r) * factorial(r)))
}
Combination(14,6)
## [1] 3003
  1. 3 cards are drawn from a standard deck of 52 playing cards. How many different 3-card hands are possible if the drawing is done without replacement?
Combination(52,3)
## [1] 22100
  1. You are ordering a new home theater system that consists of a TV, surround sound system, and DVD player. You can choose from 12 different TVs, 9 types of surround sound systems, and 5 types of DVD players. How many different home theater systems can you build?

The answer is 12 * 9 * 5 = 540

  1. You need to have a password with 5 letters followed by 3 odd digits between 0 - 9 inclusively. If the characters and digits cannot be used more than once, how many choices do you have for your password?
print(Permutation(26,5) * Permutation(10,3))
## [1] 5683392000
  1. Evaluate the following expression. 9 Permutation 4.
Permutation(9,4)
## [1] 3024
  1. Evaluate the following expression. 11 Choose 8.
Combination(11,8)
## [1] 165
  1. Evaluate the following expression. (12 Permutation 8) / (12 Choose 4)
print(Permutation(12,8) / (Combination(12,4)))
## [1] 40320
  1. The newly elected president needs to decide the remaining 7 spots available in the cabinet he/she is appointing. If there are 13 eligible candidates for these positions (where rank matters), how many different ways can the members of the cabinet be appointed?
Permutation(13,7)
## [1] 8648640
  1. In how many ways can the letters in the word ‘Population’ be arranged?

Population has two ‘p’ and two ‘o’.

print(factorial(10)/(factorial(2) * factorial(2)))
## [1] 907200
  1. Consider the following data:
x <- c(5,6,7,8,9)
p.x <- c(0.1,0.2,0.3,0.2,0.2)

stats <- data.frame(x,p.x)
print(stats)
##   x p.x
## 1 5 0.1
## 2 6 0.2
## 3 7 0.3
## 4 8 0.2
## 5 9 0.2

Step 1. Find the expected value E( X ). Round your answer to one decimal place.

Expectation value is the sum of: [(each of the possible outcomes) * (the probability of the outcome occurring)].

print(sum(stats$x * stats$p.x))
## [1] 7.2

Step 2. Find the variance. Round your answer to one decimal place.

ExpectedValue <- sum(stats$x * stats$p.x)
Variance <- sum((stats$x - ExpectedValue)^2 * stats$p.x)
print(round(Variance,1))
## [1] 1.6

Step 3. Find the standard deviation. Round your answer to one decimal place.

SD <- sqrt(Variance)
print(round(SD,1))
## [1] 1.2

Step 4. Find the value of P(X ³ 9). Round your answer to one decimal place.

????????

Step 5. Find the value of P(X £ 7). Round your answer to one decimal place.

????????

  1. Suppose a basketball player has made 188 out of 376 free throws. If the player makes the next 3 free throws, I will pay you $23. Otherwise you pay me $4.

Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

The probability of the basketball player making his first shot is 188/376. Therefore, the probability of the player making the first AND second shot is (188/376)^2. And the probability of the player making the first AND second AND third shot is (188/376)^3 = (1/8).

The probability of the basketball player NOT making the first AND second AND third shot is: 1 - 1/8 = 7/8.

Therefore, the expected gain is: (Probability of making all three shots) * $23 + (Probability of NOT making all three shots) * (-\(4) = (1/8) * 23 + (7/8) * -4 = -5/8 or -\).63.

Therefore, the basketball player on average is expected to lose $.62.

print(round(((1/8*23) + (7/8)*(-4)),2))
## [1] -0.62

Step 2. If you played this game 994 times how much would you expect to win or lose? (Losses must be entered as negative.)

print(-.62 * 994)
## [1] -616.28
  1. Flip a coin 11 times. If you get 8 tails or less, I will pay you $1. Otherwise you pay me $7.

Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

There are 2^11 different possibilities. To get the probability of flipping 8 tails or less, we need to take the sum of all probabilities when tails = 8, tails = 7, tails = 6…tails = 0. To obtain each probability for each scenario, we need to use the combination formula, which is (n!) / (k! * (n-k)!).

Therefore, if tails is 8. There will be (11!)/(8! * 3!) = 165. Therefore, there is a probability of 165/(2^11). Likewise, we would peform this for tails = 7, tails = 6, etc. and take the sum.

n <- 11
k <- 8
temp <- 0

while (k >= 0){
  temp <- temp + (factorial(n) / ((factorial(k) * factorial(n-k))))
  k <- k - 1
}

# Take the sum of all combinations and divide it by all possible combinations 2^11

print(temp/(2^11))
## [1] 0.9672852
# Another way to show this is through the pbinom function

Winning <- pbinom(8, size=11, prob=1/2)
print(Winning)
## [1] 0.9672852
#Using the same method in Question 25, (Probability of getting 8 tails or less) * $1 + (Probability of getting more than 8 tails) * (-$7)
Payout <- (Winning) * 1 + (1 - Winning) * (-7)
print(round(Payout,2))
## [1] 0.74

Step 2. If you played this game 615 times how much would you expect to win or lose? (Losses must be entered as negative.)

print(round(Payout * 615, 2))
## [1] 454.04
  1. If you draw two clubs on two consecutive draws from a standard deck of cards you win $583. Otherwise you pay me $35. (Cards drawn without replacement.)

Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

The probability of drawing a club on the first draw is: 13/52. The probabiliy of drawing a club on the 1st draw AND drawing a club on the 2nd draw is: (13/52) * (12/51) = (1/17).

The probability of NOT drawing a club on the 1st AND a club on the 2nd draw is: 1 - (1/17) = 16/17.

The payout on average for this proposition is: (1/17) * (583) + (16/17) * (-35) = 23/17 = $1.35

answer <- (round( (1/17) * (583) + (16/17) * (-35), 2))
print(answer)
## [1] 1.35

Step 2. If you played this game 632 times how much would you expect to win or lose? (Losses must be entered as negative.)

print(answer * 632)
## [1] 853.2
  1. A quality control inspector has drawn a sample of 10 light bulbs from a recent production lot. If the number of defective bulbs is 2 or less, the lot passes inspection. Suppose 30% of the bulbs in the lot are defective. What is the probability that the lot will pass inspection? (Round your answer to 3 decimal places)

For each light bulb, the light bulb is either functional or defective (binomial). In a sample of 10, there are 2^10 possibilities. To pass inspection, 8 or more lightbulbs need to be functional, where 30% of the bulbs in a lot is defective or 70% are functional.

To find the combined sum of probabilities of functional lightbulbs:

Passing <- pbinom(2, size = 10, prob = .3)
print(round(Passing,3))
## [1] 0.383
  1. A quality control inspector has drawn a sample of 5 light bulbs from a recent production lot. Suppose that 30% of the bulbs in the lot are defective. What is the expected value of the number of defective bulbs in the sample? Do not round your answer.
print(5*.3)
## [1] 1.5
  1. The auto parts department of an automotive dealership sends out a mean of 5.5 special orders daily. What is the probability that, for any day, the number of special orders sent out will be more than 5? (Round your answer to 4 decimal places)

Poisson Distribution

Let’s assume that the special orders delivery on each day is independent from each other, and that the deliver daily. As noted in the question stem, the mean is 5.5 special orders daily.

Using the formula for Poisson’s distribution, P(X = k) = ((lamda)^k / k!) * e^(-lambda). Here in this question, k = 5, lambda = 5.5.

The answer is: [(5.5)^(5) / 5!] * e^(-5.5) = 0.1714 when k = 5.

However, the question asks when k > 5. Therefore, we must take the sum of Poisson’s distribution when k = 6, k = 7, k = 8 , etc. There is a function called ppois that can help come up with an answer.

print(round(ppois(5, 5.5, lower.tail = FALSE),4))
## [1] 0.4711
  1. At the Fidelity Credit Union, a mean of 5.7 customers arrive hourly at the drive-through window. What is the probability that, in any hour, more than 4 customers will arrive? (Round your answer to 4 decimal places)
print(round(ppois(4, 5.7, lower.tail = FALSE),4))
## [1] 0.6728
  1. The computer that controls a bank’s automatic teller machine crashes a mean of 0.4 times per day. What is the probability that, in any 7-day week, the computer will crash no more than 1 time? (Round your answer to 4 decimal places)

Will need to multiply 0.4 by 7 as they are asking for the probability of crashing over a 7 day period.

print(round(ppois(1, 0.4*7, lower.tail = TRUE),4))
## [1] 0.2311
  1. A town recently dismissed 8 employees in order to meet their new budget reductions. The town had 6 employees over 50 years of age and 19 under 50. If the dismissed employees were selected at random, what is the probability that more than 1 employee was over 50? Write your answer as a fraction or a decimal number rounded to three decimal places.

Using Hypergeomtric Distribution, given that there is NO replacement.

The total probability is: Sum as x = 2 approaches 6 of [ (6 choose x) * (19 choose (8 - x)) / (25 choose 8) ]

print(round(dhyper(2, m=6, n=19, 8) + dhyper(3, m=6, n=19, 8) + dhyper(4, m=6, n=19, 8) + dhyper(5, m=6, n=19, 8) + dhyper(6, m=6, n=19, 8), 3))
## [1] 0.651
  1. Unknown to a medical researcher, 10 out of 25 patients have a heart problem that will result in death if they receive the test drug. Eight patients are randomly selected to receive the drug and the rest receive a placebo. What is the probability that less than 7 patients will die? Write your answer as a fraction or a decimal number rounded to three decimal places.

Using the same concept with hypergeometric distrubtion. To figure the answer out to this question, we need to take the sum of the probabilities as x = 0 goes to x = 6. [ (10 choose x) * (15 choose (15 - x))] / (25 choose 8).

print(round(dhyper(0, m=10, n=15, 8) + dhyper(1, m=10, n=15, 8) + dhyper(2, m=10, n=15, 8) + dhyper(3, m=10, n=15, 8) + dhyper(4, m=10, n=15, 8) + dhyper(5, m=10, n=15, 8) + dhyper(6, m=10, n=15, 8), 3))
## [1] 0.998