MSDS Spring 2018

DATA 605 Fundamentals of Computational Mathematics

Jiadi Li

HW #6 - Combinatorics(Permutations,Combinations) and Conditional Probability

1.A box contains 54 red marbles, 9 white marbles, and 75 blue marbles. If a marble is randomly selected from the box, what is the probability that it is red or blue? Express your answer as a fraction or a decimal number rounded to four decimal places.

red <- 54
white <- 9
blue <- 75

box.of.marbles <- vector()
box.of.marbles[1:54] <-"red"
box.of.marbles[55:63] <- "white"
box.of.marbles[64:138] <- "blue"

count.marble <- 0
for (i in 1:1000000) {
  selected <- sample(box.of.marbles,1,replace=TRUE)
  if (selected == "red" | selected == "blue") {
    count.marble <- count.marble + 1
  }
}

round(count.marble/1000000,4)
## [1] 0.9347

P(select either a red or blue marble) = \(\frac{number of red marble + number of blue marble}{number of total marbles}\) = \(\frac{54 + 75}{54 + 9 + 75}\) = \(\frac{129}{138}\)

round(sum(red,blue)/sum(red,white,blue),4)
## [1] 0.9348



2.You are going to play mini golf. A ball machine that contains 19 green golf balls, 20 red golf balls, 24 blue golf balls, and 17 yellow golf balls, randomly gives you your ball. What is the probability that you end up with a red golf ball? Express your answer as a simplified fraction or a decimal rounded to four decimal places.

green <- 19
red <- 20
blue <- 24
yellow <- 17

mini.golf <- vector()
mini.golf[1:19] <-"green"
mini.golf[20:39] <- "red"
mini.golf[40:63] <- "blue"
mini.golf[64:80] <- "yellow"

count.golf <- 0
for (i in 1:1000000) {
  selected.golf <- sample(mini.golf,1,replace=TRUE)
  if (selected.golf == "red") {
    count.golf <- count.golf + 1
  }
}

round(count.golf/1000000,4)
## [1] 0.2496

P(select a red golf) = \(\frac{number of red golf}{number of total golves}\) = \(\frac{20}{19 + 20 + 24 + 17}\) = \(\frac{1}{4}\)

round(sum(red)/sum(green,red,blue,yellow),4)
## [1] 0.25



3.A pizza delivery company classifies its customers by gender and location of residence. The research department has gathered data from a random sample of 1399 customers. The data is summarized in the table below.


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

\(M^c\) represents the event that a customer is not male
\(P^c\) represents the event that a customer does not live with parents
P(\(M^c\cup P^c\)) = P(\((M\cap P)^c\))
= 1 - (\(\frac{215}{1399}\) + \(\frac{1184}{1399}\))

4.Determine if the following events are independent:
Going to the gym. Losing weight.
A) Dependent B) Independent

Two events are indepedent if either 1) both events have positive probabilty and P(A|B) = P(A) and P(B|A) = P(B), or 2) at least one of the events has probability 0.
In other words, given the existence of one event, if the probability of the other event doesn’t change and vice versa, we can conclude that these two events are independent.
In this situation, given the fact of going to the gym, the probability of losing weight will be different, and therefore these two events are A) dependent.

5.A veggie wrap at City Subs is composed of 3 different vegetables and 3 different condiments wrapped up in a tortilla. If there are 8 vegetables, 7 condiments, and 3 types of tortilla available, how many different veggie wraps can be made?

veg.type <- 8
cdm.type <- 7
tor.type <- 3

veg.need <- 3
cdm.need <- 3
tor.need <- 1

n.type <- choose(veg.type,veg.need)*choose(cdm.type,cdm.need)*choose(tor.type,tor.need)
n.type #use nCr because order doesn't matter
## [1] 5880



6.Determine if the following events are independent:
Jeff runs out of gas on the way to work. Liz watches the evening news.
A) Dependent B) Independent

Assuming there is no exceptional connections between Jeff and Liz and/or between the two events, these two events should be B) independent since given the fact that Jeff runs out of gas on the way to work, Liz should watch or not watch evening news regardless.

7.The newly elected president needs to decide the remaining 8 spots available in the cabinet he/she is appointing. If there are 14 eligible candidates for these positions (where rank matters), how many different ways can the members of the cabinet be appointed?

permutation <- function(n,r){gamma(n + 1)/gamma(n - r + 1)}
permutation(14,8) #use nPr because order is taken into consideration
## [1] 121080960



8.A bag contains 9 red, 4 orange, and 9 green jellybeans. What is the probability of reaching into the bag and randomly withdrawing 4 jellybeans such that the number of red ones is 0, the number of orange ones is 1, and the number of green ones is 3? Write your answer as a fraction or a decimal number rounded to four decimal places.

P(0 red,1 orange,3 green) = \(\frac{designated selection}{total selection}\) = \(\frac{{9\choose 0}{4\choose 1}{9\choose 3}}{9 + 4 + 9\choose 4}\) = \(\frac{336}{7315}\)

red.contain <- 9
orange.contain <- 4
green.contain <- 9

red.withdraw <- 0
orange.withdraw <- 1
green.withdraw <- 3

choices <- choose(red.contain + orange.contain + green.contain, 4)

withdrwal <- choose(red.contain,red.withdraw)*choose(orange.contain,orange.withdraw)*choose(green.contain,green.withdraw)

withdrwal/choices
## [1] 0.04593301



9.Evaluate \(\frac{11!}{7!}\).

\(\frac{11!}{7!}\) = \(\frac{11\times 10\times 9\times 8\times 7......}{7\times 6\times 5......}\) = \(11\times 10\times 9\times 8\) = 7920

gamma(11+1)/gamma(7+1)
## [1] 7920



10.Describe the complement of the given event:
67% of subscribers to a fitness magazine are over the age of 34.

P(subscribers > age of 34) = 67% P(subscribers \(\leq\) age of 34) = 1 - P(> 34) = 33%

11.If you throw exactly three heads in four tosses of a coin you win $97. If not, you pay me $30.
Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

\(E[X] = \sum_{i = 1}^{\infty}x_i p(x_i)\)

win <- 97
p.win <- choose(4,3)/2^4
lose <- -30 
p.lose <- 1 - p.win

expected.toss <- win*p.win + lose*p.lose
round(expected.toss,2)
## [1] 1.75

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

expected.559times <- expected.toss*559

expected.559times
## [1] 978.25



12.Flip a coin 9 times. If you get 4 tails or less, I will pay you $23. Otherwise you pay me $26. Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

\(E[X] = \sum_{i = 1}^{\infty}x_i p(x_i)\)

win <- 23 #calculate
p.win <- sum(choose(9,4),choose(9,3),choose(9,2),choose(9,1),choose(9,0))/2^9
lose <- -26
p.lose <- 1 - p.win

expected.flip <- win*p.win + lose*p.lose
round(expected.flip,2)
## [1] -1.5

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

expected.994times <- expected.flip*994

expected.994times
## [1] -1491



13.The sensitivity and specificity of the polygraph has been a subject of study and debate for years. A 2001 study of the use of polygraph for screening purposes suggested that the probability of detecting a liar was .59 (sensitivity) and that the probability of detecting a “truth teller” was .90 (specificity). We estimate that about 20% of individuals selected for the screening polygraph will lie.
Based on sensitivity = 0.59, specificity = 0.9, and P(liar) = 0.2, we can generate:

sensitivity = \(\frac{a}{a + c}\) = 0.59
Specificity = \(\frac{d}{b + d}\) = 0.90
P(liar) = \(\frac{a + c}{a + b + c + d}\) = 0.20

p.liar <- 0.2 #a + c in the table
p.truth_teller <- 1 - p.liar #b + d in the table

p.detected_liar <- 0.118 #a in the table, true positives, P(L and D)
p.undetected_liar <- 0.082 #c in the table, false negatives, P(L and D^c) 
p.undetected_truth <- 0.08 #b in the table,false positives, P(L^c and D)
p.detected_truth <- 0.72 #d in the table, true negative, P(L^c and D^c)

sum(p.detected_liar,p.undetected_liar,p.undetected_truth,p.detected_truth)
## [1] 1
  1. What is the probability that an individual is actually a liar given that the polygraph detected him/her as such? (Show me the table or the formulaic solution or both.)
    P(A\(\cap\)B) = P(A|B)P(B) P(Liar|Detected) = \(\frac{P(L\cap D)}{P(D)} = \frac{0.118}{0.118 + 0.08}\)
p.detected_liar/(p.detected_liar + p.undetected_truth)
## [1] 0.5959596
  1. What is the probability that an individual is actually a truth-teller given that the polygraph detected him/her as such? (Show me the table or the formulaic solution or both.)
    P(Truth-teller|not detected) = \(\frac{P(L^c\cap D^c)}{P(D^c)} = \frac{0.72}{0.082 + 0.72}\)
p.detected_truth/(p.undetected_liar + p.detected_truth)
## [1] 0.8977556
  1. What is the probability that a randomly selected individual is either a liar or was identified as a liar by the polygraph? Be sure to write the probability statement.
    P(A \(\cup\) B) = P(A) + P(B) - P(A\(\cap\) B)
    P(Liar \(\cup\) Detected) = P(L) + P(D) - P(L \(\cap\) D) = 0.2 + (0.118 + 0.08) - 0.118
p.liar + (p.detected_liar + p.undetected_truth) - p.detected_liar
## [1] 0.28