knitr::opts_chunk$set(echo = TRUE)
library(tinytex)
library(pracma)

Source files: [https://github.com/djlofland/DATA605_S2020/tree/master/]

Problem Set 1

  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
total <- red + white + blue

prob <- red/total + blue / total
(round(prob, digits = 4))
## [1] 0.9348
  1. 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
total <- green + red + blue + yellow

prob_red <- red/total
(round(prob_red, digits = 4))
## [1] 0.25
  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 1399 customers. The data is summarized in the table below.
apt_m <- 81
apt_f <- 228
dorm_m <- 116
dorm_f <- 79
par_m <- 215
par_f <- 252
sf_m <- 130
sf_f <- 97
other_m <- 129
other_f <- 72

prob_not_m <- (apt_f + dorm_f + par_f + sf_f + other_f) / 1399
prob_not_par <- (apt_m + apt_f + dorm_m + dorm_f +sf_m+ sf_f+other_m+other_f) / 1399
prob_not_m_and_not_par <- (apt_f + dorm_f + sf_f + other_f) / 1399

prob <- prob_not_m + prob_not_par - prob_not_m_and_not_par
(round(prob, digits = 4))
## [1] 0.8463
  1. Determine if the following events are independent.

likely dependent (working out is likely to initially decrease weight (fat), but then may increase weight (muscle mass)). However, going to the gym doesn’t mean you are applying yourself, so they could be independent for slackers.

  1. 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?
veggie_num <- 3
cond_num <- 3
tortilla_num <- 1

veggie_types <- 8
cond_types <- 7
tortilla_types <- 3

# There are multiple solutions - do we allow customers to opt out of any given option and/or do we allow customers to double up on a given option.

# Solution 1 (no repeats and no opt out)
(everything_no_repeats <- veggie_types * (veggie_types-1) * (veggie_types-2) * cond_types * (cond_types-1) * (cond_types-2) * tortilla_types)
## [1] 211680
# Solution 2 (allow repeats - customers can get double or triple of a given veggie or condament)
(everything_allow_repeats <- veggie_types * veggie_types * veggie_types * cond_types * cond_types * cond_types * tortilla_types)
## [1] 526848
# Solution 3 (allow holding of veggies or condiments, ie don't get 3 of each, meaning "none" is an option
veggies_3_cond_3 <- veggie_types * (veggie_types-1) * (veggie_types-2) * cond_types * (cond_types-1) * (cond_types-2) * tortilla_types
veggies_2_cond_3 <- veggie_types * (veggie_types-1) * cond_types * (cond_types-1) * (cond_types-2) * tortilla_types
veggies_1_cond_3 <- veggie_types * cond_types * (cond_types-1) * (cond_types-2) * tortilla_types
veggies_0_cond_3 <- cond_types * (cond_types-1) * (cond_types-2) * tortilla_types
veggies_3_cond_2 <- veggie_types * (veggie_types-1) * (veggie_types-2) * cond_types * (cond_types-1) * tortilla_types
veggies_2_cond_2 <- veggie_types * (veggie_types-1) * cond_types * (cond_types-1) * tortilla_types
veggies_1_cond_2 <- veggie_types * cond_types * (cond_types-1) * tortilla_types
veggies_0_cond_2 <- cond_types * tortilla_types
veggies_3_cond_1 <- veggie_types * (veggie_types-1) * (veggie_types-2) * cond_types * tortilla_types
veggies_2_cond_1 <- veggie_types * (veggie_types-1) * cond_types * tortilla_types
veggies_1_cond_1 <- veggie_types * cond_types * tortilla_types
veggies_0_cond_1 <- cond_types * tortilla_types
veggies_3_cond_0 <- veggie_types * (veggie_types-1) * (veggie_types-2) * tortilla_types
veggies_2_cond_0 <- veggie_types * (veggie_types-1) *tortilla_types
veggies_1_cond_0 <- veggie_types * tortilla_types
veggies_0_cond_0 <- tortilla_types # boring!!!

(allow_skipping_options <- veggies_3_cond_3 + veggies_2_cond_3 +veggies_1_cond_3 + veggies_0_cond_3 + 
  veggies_3_cond_2 + veggies_2_cond_2 +veggies_1_cond_2 + veggies_0_cond_2 + 
  veggies_3_cond_1 + veggies_2_cond_1 + veggies_1_cond_1 + veggies_0_cond_1 +
  veggies_3_cond_0 + veggies_2_cond_0 + veggies_1_cond_0 + veggies_0_cond_0)
## [1] 312675
# Solution 4 (allow skipping items with repeats)
# Note: ... just repeat the Solution 3 but don't use the -1 and -2 ... use the veggies_types and cond_types in each position
  1. Determine if the following events are independent: Jeff runs out of gas on the way to work. Liz watches the evening news.

Independent unless Jeff calls Liz for a ride home, causing her to miss the evening news - in which case they could be Dependent

  1. 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?
# By "Rank matters" I'm assuming this is permutations, not combinations
c <- 14
s <- 8

cabinets <- 1

for (spot in 1:s) {
  cabinets <- cabinets * c
  print(c(c,spot, cabinets))
  c <- c - 1  # since no replacement and same person cannot occupy 2 positions
}
## [1] 14  1 14
## [1]  13   2 182
## [1]   12    3 2184
## [1]    11     4 24024
## [1]     10      5 240240
## [1]       9       6 2162160
## [1]        8        7 17297280
## [1]         7         8 121080960
(cabinets)
## [1] 121080960
  1. 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.
# Note: no replacement, so each subsequent draw is dependent on the previous draw

red <- 9
orange <- 4
green <- 9
total <- (red + orange + green)

# --- possibilities: OGGG, GOGG, GGOG, GGGO
opt1 <- orange/total * green/(total-1) * (green-1)/(total-2) * (green-2)/(total-3)  #OGGG
opt2 <- green/total * orange/(total-1) * (green-1)/(total-2) * (green-2)/(total-3)  #GOGG
opt3 <- green/total * green/(total-1) * orange/(total-2) * (green-2)/(total-3)      #GGOG
opt4 <- green/total * green/(total-1) * (green-1)/(total-2) * orange/(total-3)      #GGGO

orange1_green3 <- (opt1 + opt2 + opt3 + opt4)
(round(orange1_green3, digits=4))
## [1] 0.0506
  1. Evaluate \(\frac{11!}{7!}\)
(11*10*9*8)
## [1] 7920
  1. Describe the complement of the given event. 67% of subscribers to a fitness magazine are over the age of 34.

33% of subscribers to a fitness magazine are 34 or younger.

  1. If you throw exactly three heads in four tosses of a coin you win $97. If not, you pay me $30.
  1. Step 1. Find the expected value of the proposition. Round your answer to two decimal places.
# wins: HHHT, HHTH, HTHH, THHH, HHHH
# total possibilities: 16
prob_heads3 <- (5/16) # Note: the 1 is because we don't care what happens with the 4th coin flip
value <- prob_heads3 * 97 - (1-prob_heads3) * 30
(round(value, digits=2))
## [1] 9.69
  1. Step 2. If you played this game 559 times how much would you expect to win or lose? (Losses must be entered as negative.)
(win <- value * 559)
## [1] 5415.312
  1. Flip a coin 9 times. If you get 4 tails or less, I will pay you $23. Otherwise you pay me $26.
  1. Step 1. Find the expected value of the proposition. Round your answer to two decimal places.
trials <- 9
succ_num <- 5
succ_prob = 0.5
prob = 0

for (h in succ_num:trials) {
  prob <- prob + (fact(trials) / (fact(h)*fact(trials-h))) * (succ_prob^h) * (1-succ_prob)^(trials-h)
}

(value <- (prob*23) - (1-prob)*26)
## [1] -1.5
  1. STEP 2. If you played this game 994 times how much would you expect to win or lose? (Losses must be entered as negative.)
value * 994
## [1] -1491
  1. 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.
pred_lie_true <- 0.59
pred_lie_false <- 1 - pred_lie_true
pred_truth_true <- 0.9
pred_truth_false <- 1 - pred_truth_true

will_lie <- 0.2
  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.)
        | Predict |
actual | lie | truth |
——–|——-|——–|——-
lie | 108 | 92 | 200
truth | 80 | 720 | 800
        | 188 | 812 | 1000

P(lie) = 0.20 (200/1000)
P(truth) = 0.8 (800/1000)

P(Detect Lie | Lie) = 0.59 (108/200)

P(Detect Truth | Truth) = 0.9 (720/800)

(108/188)
## [1] 0.5744681
  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.)
(720/812)
## [1] 0.8866995
  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(Liar) = 0.2

P(Detect_liear) = 0.59

Prob(Liar or Detected Liar) = P(Liar) + P(Detect Liar) - P(Liar and Detect)

(prob <- (200 + 188 - 108) / 1000)
## [1] 0.28