# Count the total marbles in the box
reds <- 54
whites <- 9
blues <- 75
total <- reds + whites + blues
# Probability that its red or blue
prob_red_or_blue <- (reds + blues) / total
print(paste0("Probability that a marble is red or blue: ", round(prob_red_or_blue, 4)))
## [1] "Probability that a marble is red or blue: 0.9348"
# Calculate the total amount of balls
green <- 19
red <- 20
blue <- 24
yellow <- 17
totals <- green + red + blue + yellow
# Calculate the probaiblity that I will end up with a red golf ball
prob_red <- red / totals
print(paste0("Probability that I will get a red golf ball: ", round(prob_red,4)))
## [1] "Probability that I will get a red golf ball: 0.25"
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.
The probability of union of two events is given by: \(P(A \cup B) = P(A) + P(B) - P(A \cap B)\)
# Find total amount
total2 <- 81 + 228 + 116 + 79 + 215 + 252 + 130 + 97 + 129 + 72
# Find probability that a customer is not male (or in other words, are female)
prob_not_male <- (228 + 79 + 252 + 97 + 72) / total2
# Find the probability that a customer does not live with parents
prob_not_parents <- (81 + 228 + 116 + 79 + 130 + 97 + 129 + 72) / total2
# Find the intersection between not_male and not_parents
prob_not_male_not_parents <- (228 + 79 + 97 + 72)/ total2
# Using the formula above to solve the problem
prob_final <- prob_not_male + prob_not_parents - prob_not_male_not_parents
print(paste0("Probability that a customer is not male or does not live with parents: ", round(prob_final, 4)))
## [1] "Probability that a customer is not male or does not live with parents: 0.8463"
Going to the gym. Losing weight.
Answer: The events are likely dependent as going to the gym will likely cause you to loose weight.
# Given that we can only use 3 different vegetables and 3 different condiments and 1 tortilla, we'll need to find all the different amount of combinations
veg_combo <- choose(8, 3)
condiment_combo <- choose(7, 3)
tortilla_combo <- choose(3, 1)
# How many different vegie wraps can be made?
wrap_combo <- veg_combo * condiment_combo * tortilla_combo
print(paste0("How many different veggie wraps can be made? ", wrap_combo))
## [1] "How many different veggie wraps can be made? 5880"
Jeff runs out of gas on the way to work. Liz watches the evening news.
Answer: These are seemingly independent events as Liz watching the news is very unlikely to influence Jeff’s gas tank on his way to work.
# Given that rank matters, we will be using permutation
candidates <- factorial(14)/(factorial(14 - 8))
print(paste0("How many different ways a candidate can be appointed: ", candidates))
## [1] "How many different ways a candidate can be appointed: 121080960"
Assume that choosing the jellybeans are independent events.
red <- 9
orange <- 4
green <- 9
total_beans <- red + orange + green
# How many different combinations exist for drawing random 4 jellybeans from the bag
# Using the choose function
jellybean_combo <- choose(total_beans, 4)
# How many ways can we get 0 reds, 1 orange and 3 greens
red_combo <- choose(red, 0)
orange_combo <- choose(orange, 1)
green_combo <- choose(green, 3)
# Calculate the probability
jellybean <- (red_combo * orange_combo * green_combo) / jellybean_combo
print(paste0("Probability drawing 4 jellybeans such that there are 0 reds, 1 orange, and 3 greens: ", round(jellybean, 4)))
## [1] "Probability drawing 4 jellybeans such that there are 0 reds, 1 orange, and 3 greens: 0.0459"
\[11!/7!\]
Let’s simplify this factorial down:
\[ 11! = 11 * 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 \] \[ 7! = 7 * 6 * 5 * 4 * 3 * 2 * 1 \] \(11!/7!\) can be reduced into \(11 * 10 * 9 * 8\) which equals to \(7920\).
# Let's double check our answer.
answer <- factorial(11)/factorial(7)
print(paste0("11!/7! = ", answer))
## [1] "11!/7! = 7920"
67% of subscribers to a fitness magazine are over the age of 34.
Complement of the event: 33% of subscribers to a fitness matazines are 34 years of age or younger.
Step 1. Find the expected value of the proposition. Round your answer to two decimal places.
# First find the probability distribution with four tosses.
total_tosses <- 2^4
no_head <- choose(4, 0)/total_tosses
one_head <- choose(4,1)/total_tosses
two_head <- choose(4,2)/total_tosses
three_head <- choose(4, 3)/total_tosses
four_head <- choose(4, 4)/total_tosses
head_prob <- c(no_head, one_head, two_head, three_head, four_head)
head_num <- 0:4
head_df <- data.frame(head_num, head_prob)
# Plot the probability distribution with the four tosses with a histogram
plot(head_df,
main = "Probability Distribution with Four Tosses (Heads)",
type = "l",
col = "blue")
# Calculate the expected value
# If I throw exactly 3 heads, I win $97
# Anything else, I lose $30
money <- c(-30,-30,-30,97, -30)
exp_value <- sum(money * head_df[,2])
print(paste0("Expected Value: ", exp_value))
## [1] "Expected Value: 1.75"
So overall, if I play this game, I would win $1.75 in the long term.
Step 2. If you played this game 559 times how much would you expect to win or lose? (Losses must be entered as negative.)
exp_win <- 559 * 1.75
print(paste0("On average, I would expect to win: $", exp_win))
## [1] "On average, I would expect to win: $978.25"
There are \(2^9\) different possibilities. To get the probability of flipping 4 tails or less, we need to take the sum of all probabilities when tails = 4, tails = 3, tails = 2 … tails = 0. To obtain each probability for each scenario, we need to use the combination formula, which is \((n!) / (k! * (n-k)!)\).
Therefore, for example, if tails is 4. There will be \((9!)/(4! * 5!) = 126\). Therefore, there is a probability of 165/(2^11). Likewise, we would peform this for tails = 3, tails = 2, etc. and take the sum.
Step 1. Find the expected value of the proposition. Round your answer to two decimal places.
n <- 9
k <- 4
temp <- 0
while (k >= 0){
temp <- temp + choose(n,k)
k <- k - 1
}
# Take the sum of all combinations and divide it by all possible combinations 2^9
total_prob_four_tails_or_less <- temp/(2^9)
print(paste0("Probability of 4 tails or less with 9 tosses: ", total_prob_four_tails_or_less))
## [1] "Probability of 4 tails or less with 9 tosses: 0.5"
# Another way to show this is through the pbinom function
Winning <- pbinom(4, size=9, prob=1/2)
print(paste0(Winning))
## [1] "0.5"
# Now to calculate the expected value(gain) from playing this game.
# Again, 4 tails or less, I win $23, otherwise, I lose $26
exp_wins <- 23*total_prob_four_tails_or_less + -26*(1 - total_prob_four_tails_or_less)
print(paste0("On average, expected value: ", exp_wins))
## [1] "On average, expected value: -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.)
# If played 994 times
win_or_lose <- 994 * exp_wins
print(paste0("After playing 994 games, I would expect to win: $", win_or_lose))
## [1] "After playing 994 games, I would expect to win: $-1491"
# Let's assume that we have 10000 subjects
subjects <- 10000
# From prior testing, 20% of individuals will lie on the screening polygraph
liars <- subjects * .20
truth_tellers <- subjects * .80
# If the sujbect is a liar, how many will the test pick up? and how many will it NOT pick up?
# And remember, sensitivity detects the probability of a liar, or in other words, the test will be positive
liars_pos_test <- 0.59 * liars
liars_neg_test <- liars - liars_pos_test
# And likewise, specificity is the probability of detecting a "truth teller" if he/she was indeed telling the truth, or in other words, the test will be negative.
truth_neg_test <- 0.90 * truth_tellers
truth_pos_test <- truth_tellers - truth_neg_test
# P(liars | POSITIVE TEST)?
prob_liars_pos <- liars_pos_test / (liars_pos_test + truth_pos_test)
print(paste0("Given that the polygraph detects as a liar (POSITIVE TEST), what is the probability that an individiual is actually a liar? ", round(prob_liars_pos, 4) * 100, "%"))
## [1] "Given that the polygraph detects as a liar (POSITIVE TEST), what is the probability that an individiual is actually a liar? 59.6%"
# P(truth_teller | NEGATIVE TEST)
prob_truth_neg <- truth_neg_test / (truth_neg_test + liars_neg_test)
print(paste0("Given that the polygraph is NEGATIVE, what is the probability that an individiual is actually a truth teller? ", round(prob_truth_neg, 4) * 100, "%"))
## [1] "Given that the polygraph is NEGATIVE, what is the probability that an individiual is actually a truth teller? 89.78%"
Recalling the formula above: \(P(A \cup B) = P(A) + P(B) - P(A \cap B)\)
# P(liar or identified_as_liar)
prob_liar_or_POS <- liars/subjects + (liars_pos_test + truth_pos_test)/subjects - (liars_pos_test) / subjects
print(paste0("What is the probability that a randomly selected individual is either a liar or was identified as a liar by the polygraph? ", round(prob_liar_or_POS, 4) * 100, "%"))
## [1] "What is the probability that a randomly selected individual is either a liar or was identified as a liar by the polygraph? 28%"
\[P(liar \cup POS) = P(liar) + P(POS) - P(liar \cap POS) = .28\]