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.
Answer
Solving by Random Sample selection
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.935
Solving mathematically
paste0("The probabilithy that get a red marble or blue marble from the box is: ", round(sum(red,blue)/sum(red,white,blue),4))
## [1] "The probabilithy that get a red marble or blue marble from the box is: 0.9348"
\[P(Red | Blue) = P(R) + P(B) = \frac{54}{(54+9+75)} + \frac{75}{(54+9+75)} = \frac{129}{138} = 0.9347 \]
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.
Answer
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.2497
paste0("The probability that you end up with a red golf ball is: ", round(sum(red)/sum(green,red,blue,yellow),4))
## [1] "The probability that you end up with a red golf ball is: 0.25"
\[P(Red) = P(R) = \frac{20}{(19+20+24+17)}= \frac{20}{80} = 0.2500 \]
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.
| Gender and Residence of Customers | Males | Females |
|---|---|---|
| Apartment | 81 | 228 |
| Dorm | 116 | 79 |
| With Parent(s) | 215 | 252 |
| Sorority/Fraternity House | 130 | 97 |
| Other | 129 | 72 |
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.
Answer
n <- 81 + 116 + 215 + 130 + 129 + 228 + 79 + 252 + 97 + 72
prob_not_male <- (228 + 79 + 252 + 97 + 72) / n
prob_not_parents <- (81 + 228 + 116 + 79 + 130 + 97 + 129 + 72) / n
prob_not_male_not_parents <- (228 + 79 + 97 + 72)/ n
round(prob_not_male + prob_not_parents - prob_not_male_not_parents, 4)
## [1] 0.8463
male_with_parents = 215
total_number = 81+116+215+130+129+228+79+252+97+72
paste0("The probability that a customer is not male or does not live with parents ", round(1- male_with_parents/total_number,4))
## [1] "The probability that a customer is not male or does not live with parents 0.8463"
\[P(not male OR live with parents) = 1 - P(male AND live with parents) = 1 - \frac{215}{(81+228+116+79+215+252+130+97+129+72)}= 1 - \frac{215}{1399} = 1 - 0.1537 = 0.8463 \]
Determine if the following events are independent. Going to the gym. Losing weight. Answer: A) Dependent B) Independent
Answer
\[P(Going to Gym) = P(GG) = {Yes|No} = \frac{1}{2} \] \[P(Losing Weight) = P(LW) = P(GG)*P(L) = {Yes|No}*{Yes|No} = \frac{1}{2}*\frac{1}{2} = 0.25 \]
Disclaimer: However, one can also lose weight without going to gym but doing any physical activity/workout outside the gym, with all lifestyle parameters remaining same (sendatary, diet, sleep, medication, pregnancy, stress etc)
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?
Answer
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
## [1] 5880
c8_3 <- factorial(8)/(factorial(3)*factorial(8-3))
c7_3 <- factorial(7)/(factorial(3)*factorial(7-3))
c3_1 <- factorial(3)/(factorial(1)*factorial(3-1))
var <- c8_3 * c7_3 * c3_1
cat("Answer: There are",var,"veggie wraps can be made.")
## Answer: There are 5880 veggie wraps can be made.
We need to use below combinations, because order does not matter. \[ C_{n,k} = \frac{n!}{n!(n-k)!} \] \[ C_{total} = C_{8,3} * C_{7,3} * C_{3,1} = \frac{8!}{3!(8-3)!} * \frac{7!}{3!(7-3)!} * \frac{3!}{1!(3-1)!} = 5880 \]
Determine if the following events are independent. Jeff runs out of gas on the way to work. Liz watches the evening news. Answer: A) Dependent B) Independent
Answer
\[P(Out Of Gas) = P(OOG) = {Yes|No} = \frac{1}{2} \] \[P(Watch News) = P(WN) = {Yes|No} = \frac{1}{2} \]
Jeff and Liz being two independent persons doing independent activities so the events are mutually exclusive, thus (B) Independent.
Disclaimer: Assuming Liz is watching news and learns about imminent gas supply shortage due to war/supply issues, and informs Jeff about the same who would then pro-actively fill up gas, then such cacading events would be dependent.
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?
Answer
permutation <- function(n,k){choose(n,k) * factorial(k)}
permutation(14,8) #use nPr because order is taken into consideration
## [1] 121080960
print(paste("There are",(factorial(14)/factorial(14-8)),"ways that the members of the cabinet can be appointed."))
## [1] "There are 121080960 ways that the members of the cabinet can be appointed."
\[P(Ways Of Cabinet Appointment) = \frac{No. Of Ways Of Selection Of Eligible Candidates}{No. Of Ways Of Candidates Left Out} = \frac{14!}{(14-8)!} = 121080960 \]
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.
Answer
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)
withdrawal <- choose(red.contain,red.withdraw)*choose(orange.contain,orange.withdraw)*choose(green.contain,green.withdraw)
withdrawal/choices
## [1] 0.04593301
paste("The probability of randomly withdrawing 4 jellybeans such that there are 0 red ones, 1 orange one and 3 green ones is", round(choose(9,0)*(choose(4,1)*choose(9,3) / choose((9+4+9), 4)), digits = 4))
## [1] "The probability of randomly withdrawing 4 jellybeans such that there are 0 red ones, 1 orange one and 3 green ones is 0.0459"
\[ P_{0r,1o,3g} = P(O)*P(G)*P(G)*P(G) = \frac{C^9_0 * C^4_1 * C^9_3}{C^{(9+4+9)}_{4}} = 0.0459 \]
Evaluate the following expression. \[ \frac{11!}{7!} \]
Answer
gamma(11+1)/gamma(7+1)
## [1] 7920
paste("The answer is", factorial(11)/factorial(7))
## [1] "The answer is 7920"
\[ \frac{11!}{7!} = \frac{11*10*9*8*7*6*5*4*3*2*1}{7*6*5*4*3*2*1} = 11*10*9*8 = 7920 \]
Describe the complement of the given event. 67% of subscribers to a fitness magazine are over the age of 34.
Answer
paste("The complement of the event could be expressed as:", (100-67), "% of subscribers to a fitness magazine are less than or equal to the age of 34.")
## [1] "The complement of the event could be expressed as: 33 % of subscribers to a fitness magazine are less than or equal to the age of 34."
\[P(subscribers > Age Of 34) = 67% \] \[P(subscribers \le Age Of 34) = 1 - P(> 34) = 33%\]
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.
Answer
win <- 97
p.win <- choose(4,3)/2^4
lose <- -30
p.lose <- 1 - p.win
expected.toss <- win*p.win + lose*p.lose
paste0("The expected value of the proposition is $", round(expected.toss,2))
## [1] "The expected value of the proposition is $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.)
Answer
paste0("If I played this game 559 times, I would expect to win $", round(expected.toss*559,2))
## [1] "If I played this game 559 times, I would expect to win $978.25"
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.
Answer
win <- 23
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
paste0("The expected value of the proposition is ",round(expected.flip,2))
## [1] "The expected value of the proposition is -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.)
Answer
paste0("If I played this game 994 times, I would expect to lose ", round(expected.flip*994,2))
## [1] "If I played this game 994 times, I would expect to lose -1491"
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.
sensitivity <- 0.59
specificity <- 0.90
p.liar <- 0.2
p.truth_teller <- 1 - p.liar
p.detected_liar <- sensitivity * p.liar #0.118
p.undetected_liar <- (1-sensitivity) * p.liar #0.082
p.detected_truth <- specificity * p.truth_teller #0.72
p.undetected_truth <- (1-specificity) * p.truth_teller #0.08
Answer
p.detected_liar/(p.detected_liar + p.undetected_truth)
## [1] 0.5959596
\[ P(A \cap B)=\frac{P(A|B)}{P(B)} \] \[ P(Liar|Detected) = \frac{P(L \cap D)}{P(D)} = \frac{P(D|L)*P(L)}{(P(L)*P(D|L))+(P(T)*P(D|T))} = \frac{0.59*2}{0.2*0.59+0.8*0.1} = \frac{0.118}{(0.118+.08)} = \frac{0.118}{0.198} = 0.5959 \]
Answer
p.detected_truth/(p.detected_truth + p.undetected_liar)
## [1] 0.8977556
\[ P(Truth|notDetected) = \frac{P(L^c \cap D^c)}{P(D^c)} = = \frac{P(D^c|T)*P(T)}{P(D^c)} = \frac{P(D^c|T)*P(T)}{(P(L)*P(D^c|L))+(P(T)*P(D^c|T))} = \frac{0.9*0.8}{(0.2*0.41)+(0.8*0.9)} = \frac{0.72}{0.802} = 0.8978 \]
Answer
p.liar + (p.detected_liar + p.undetected_truth) - p.detected_liar
## [1] 0.28
\[ 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 = 0.28 \]