Problem 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.

r = 54
w = 9 
b = 75

total_marbles = r+w+b

prob_r_or_b = (r+b)/total_marbles
round(prob_r_or_b,digit=4)
## [1] 0.9348

Problem 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.

g = 19
r = 20
b = 24
y = 17

total_golf_balls = g+r+b+y

prob_r = r/total_golf_balls
round(prob_r,digit=4)
## [1] 0.25

Problem 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.

#P(Female OR Not Live with Parents) = P(Female) * P(Not Live with Parents) - P(Female AND Not Live with Parents)
total_pizza_customers = 1399
female = 228 + 79 + 252 + 97 + 72
not_with_parents = 1399 - 215-252
female_and_not_with_parents = 228 + 79 + 97 + 72

p_female = female / total_pizza_customers
p_not_with_parents = not_with_parents / total_pizza_customers
p_female_and_not_with_parents = female_and_not_with_parents / total_pizza_customers

round((p_female + p_not_with_parents) - p_female_and_not_with_parents,digits = 4)
## [1] 0.8463

Problem 4

Determine if the following events are independent. Going to the gym. Losing weight.
Answer: Dependent

Problem 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?

choose(8,3) * choose(7,3) * choose(3,1)
## [1] 5880

Problem 6

Jeff runs out of gas on the way to work. Liz watches the evening news. Answer: Independent I’m assuming that Liz isn’t waiting for Jeff and since Jeff has to get gas now Liz has extra time to wait around her house so she decides to watch the news.

Problem 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?

# P(n,r) = n! / (n-r)!
n = 14
r = 8

ways_to_appoint = factorial(n) / factorial(n-r)
ways_to_appoint
## [1] 121080960

Problem 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.

r = 9
o = 4
g = 9
total = r+o+g

prob_0r_1o_3g = choose(9,0)*choose(4,1)*choose(9,3)
ways_to_pick_4_jellybeans = choose(total,4)

round(prob_0r_1o_3g/ways_to_pick_4_jellybeans,digits=4)
## [1] 0.0459

Problem 9

Evaluate the following expression: \[11!/7!\]

factorial(11)/factorial(7)
## [1] 7920

Problem 10

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

Answer: 33% of subscribers to a fitness magazine are 34 years of age or younger

Problem 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.

#THHH
#HTHH
#HHTH
#HHHT

winning_combo = 4
total_combos = 2^4

prob_win = winning_combo/total_combos
print("The probability you'll win this bet is:")
## [1] "The probability you'll win this bet is:"
prob_win
## [1] 0.25
E_win = 97*prob_win
E_lose = -30*(1-prob_win)

print("The value of the proposition of throwing 3 heads in 4 tosses is:")
## [1] "The value of the proposition of throwing 3 heads in 4 tosses is:"
round(E_win + E_lose,digits=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.)

You would expect to win money 559*1.75 = 978.25

559*1.75 
## [1] 978.25
#Takes in the number of times you'll play the game and how likely you are to win,
#also what $ you will win and lose
coin_toss <- function(n,p,win,loss){
  winnings = 0
  
  while (n > 0){
    random = runif(1)
    
    if(random < p){
      #print("You won! :)")
      winnings = winnings + win
    }
    else{
      #print("You lost! :(")
      winnings = winnings + loss
    }
    n = n - 1
  }
  
  winnings
}
coin_toss(559,0.25,24.25,-22.5)
## [1] -6313

Problem 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.

winning_combo = choose(9,4) + choose(9,3) + choose(9,2) + choose(9,1) + choose(9,0)
total_combos = 2^9

prob_win = winning_combo/total_combos
print("The probability you'll win this bet is:")
## [1] "The probability you'll win this bet is:"
round(prob_win,digits = 2)
## [1] 0.5
E_win = 23*prob_win
E_lose = -26*(1-prob_win)

print("The value of the proposition of throwing 4 tails or less is winning:")
## [1] "The value of the proposition of throwing 4 tails or less is winning:"
round(E_win + E_lose,digits = 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.)

994*-1.50
## [1] -1491

You’d expect to lose money (994*-1.50 = -1491)

#Takes in the number of times you'll play the game and how likely you are to win,
#also what $ you will win and lose
coin_toss <- function(n,p,win,loss){
  winnings = 0
  
  while (n > 0){
    random = runif(1)
    
    if(random < p){
      #print("You won! :)")
      winnings = winnings + win
    }
    else{
      #print("You lost! :(")
      winnings = winnings + loss
    }
    n = n - 1
  }
  
  winnings
}
coin_toss(994,0.5,11.5,-13)
## [1] -525

Problem 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.

  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.)
#A1 = someone lies
#A2 = someone tells truth
#B1 = test is positive
#B2 = test is negative (calls them a truth teller)

p_A1 = 0.2 #someone lies
p_A2 = 0.8 #someone tells truth

p_B1_given_A1 = 0.59     #test is positive and correctly identifies a liar
p_B2_given_A1 = 1 - 0.59 #test is negative and incorreclty identifies a liar
p_B1_given_A2 = 1 - 0.90 #test is positive and incorrectly identifies a truth teller
p_B2_given_A2 = 0.9      #test is negative and correctly identifies a truth teller

#Given the test is positive, whats the probability they are lying? 
p_A1_given_B1 = p_B1_given_A1*p_A1 / (p_B1_given_A1*p_A1 + p_B1_given_A2*p_A2)
p_A1_given_B1
## [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.)
#A1 = someone lies
#A2 = someone tells truth
#B1 = test is positive
#B2 = test is negative (calls them a truth teller)

p_A1 = 0.2 #someone lies
p_A2 = 0.8 #someone tells truth

p_B1_given_A1 = 0.59     #test is positive and correctly identifies a liar
p_B2_given_A1 = 1 - 0.59 #test is negative and incorreclty identifies a liar
p_B1_given_A2 = 1 - 0.90 #test is positive and incorrectly identifies a truth teller
p_B2_given_A2 = 0.9      #test is negative and correctly identifies a truth teller

#Given the test is says the person is telling the truth, whats the probability they are truth telling? 
p_A2_given_B2 = p_B2_given_A2*p_A2 / (p_B2_given_A1*p_A1 + p_B2_given_A2*p_A2)
p_A2_given_B2
## [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.
#A1 = someone lies
#A2 = someone tells truth
#B1 = test is positive
#B2 = test is negative (calls them a truth teller)

p_A1 = 0.2 #someone lies
p_A2 = 0.8 #someone tells truth

p_B1_given_A1 = 0.59     #test is positive and correctly identifies a liar
p_B2_given_A1 = 1 - 0.59 #test is negative and incorreclty identifies a liar
p_B1_given_A2 = 1 - 0.90 #test is positive and incorrectly identifies a truth teller
p_B2_given_A2 = 0.9      #test is negative and correctly identifies a truth teller

#What's the probability that the person is a liar or test was positive
p_A1_given_B1 = 0.59

#p_B1_given_A1 = p_A1_and_B1 / p_A1
p_A1_and_B1 = p_B1_given_A1 * p_A1
#p_A1_given_B1 = p_A1_and_B1 / p_B1
p_B1 = p_A1_and_B1/p_A1_given_B1

p_A1_or_B1 = p_A1 + p_B1 - p_A1_and_B1
p_A1_or_B1
## [1] 0.282