Background

Combinatorics is the study of enumeration, combination, and permutation of sets of elements and the observation of mathematical relations that characterize their properties.

Conditional probability is the probability of one event occurring with some relationship to one or more other events.

For this week’s assignment, our focus is on combinatorics and conditional probability.


(1) box of marbles

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.

The probability is provided below

r <- 54
w <- 9
b <- 75

round((r+b)/ (r + w + b), 4)
## [1] 0.9348

(2) mini golf

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.

The probability is provided below

g <- 19
r <- 20
b <- 24
y <- 17

round(r / (g + r + b + y), 4)
## [1] 0.25

(3) pizza delivery

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

#Get URL, read .csv (in raw form) from github, and put into tabular form
url <- getURL("https://raw.githubusercontent.com/Magnus-PS/DATA-605/Assignment-6/pizza.csv")
data <- read.csv(text = url)
data <- as_tibble(data)

#Show what we're working with:
data
## # A tibble: 5 x 3
##   Living.Situation          Males Females
##   <chr>                     <int>   <int>
## 1 Apartment                    81     228
## 2 Dorm                        116      79
## 3 With Parent(s)              215     252
## 4 Sorority/Fraternity House   130      97
## 5 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.

Or is the keyword here. Thus, we could take the amount of males that live with their parents, all other values, and calculate the probability using just these two values as shown below:

m_w_parents <- 215
all_other <- 81 + 116 + 130 + 129 + 228 + 79 + 97 + 72
p_or <- all_other / (m_w_parents + all_other)
round(p_or, 4)
## [1] 0.8126

(4) independence

Determine if the following events are independent: (1) Going to the gym. (2) Losing weight.

Answer: A) Dependent B) Independent

A) Dependent - an independent event is an event in which the outcome is not affected by another event, whereas a dependent event is affected by the outcome of the other event. A case can be made for going to the gym, joining a healthy culture and losing weight, thus these are dependent events.

(5) veggie wrap

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?

For this situation, we can apply binomial coefficients to all ingredients that make up a veggie wrap and multiply the result.

v_choice <- factorial(8) / (factorial(5) * factorial(3))
c_choice <- factorial(7) / (factorial(4) * factorial (3))
t_choice <- factorial(3) / 2

result <- v_choice * c_choice * t_choice
result
## [1] 5880

We could have also used the choose() function above. The factorial() function was used this time to display its use. We’ll use choose(), where applicable, going forward due to its simplicity.

(6) independence

Determine if the following events are independent: (1) Jeff runs out of gas on the way to work. (2) Liz watches the evening news.

Answer: A) Dependent B) Independent

B) Independent - these two events have nothing to do with one another and thus the outcome of one does not affect the other.

(7) elected president

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?

For this situation, we can apply binomial coefficients for “14 choose 8” and calculate the combinations as shown below:

choose(14,8)
## [1] 3003

(8) jellybean bag

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.

#Calculate the number of choices for each type of jellybean then multiply the result
choice_combos <- choose(9, 0) * choose(4, 1) * choose(9, 3)
#Calculate the total number of choices within the bag "22 choose 4"
total_choices <- choose(22,4)

round(choice_combos / total_choices, 4)
## [1] 0.0459

(9) factorial

Evaluate the following expression: 11! / 7!

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

(10) event complement

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 under the age of 34.

(11) coin toss

If you throw exactly three heads in four tosses of a coin you win 97 dollars. If not, you pay me 30 dollars.

Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

Given n Bernoulli trials with probability p of success on each experiment, the probability of exactly j successes can be calculated as “n choose j” multiple by the p to the j and q to the n-j.

All (16) possibilities: {HHHH, HHHT, HHTH, HHTT, HTHH, HTHT, HTTH, HTTT, THHH, THHT, THTH, THTT, TTHH, TTHT, TTTH, TTTT}

Notice that 4/16 include (3) heads, our p value is thus 1/4, and we can calculate the expected value as shown below:

#Calculate the probability of 3 heads
p_h <- 1 / 4
q_h <- 1 - p_h

#Calculate and display the expected value
expected_value <- (p_h * 97) - (q_h * 30)
round(expected_value, 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.)

We can take our expected value (from above) and multiply it by 559 to calculate our total winnings / losses as shown below:

expected_value * 559
## [1] 978.25

(12) coin toss rd2

Flip a coin 9 times. If you get 4 tails or less, I will pay you 23 dollars. Otherwise you pay me 26 dollars.

Step 1. Find the expected value of the proposition. Round your answer to two decimal places.

Being that there are 9 flips, we won’t write out all possibilities as in the last problem (it would be too time consuming), instead we’ll lean on the Bernoulli trial equation for exactly 0, 1, 2, and 3 tails. We’ll then sum these probabilities and take this and its complement, with associate payments, and calculate the expected value as shown below:

#Calculate the probability of less than 4 tails
p_3 <- choose(9,3) * (0.5 ** 9)
p_2 <- choose(9,2) * (0.5 ** 9)
p_1 <- choose(9,1) * (0.5 ** 9)
p_0 <- choose(9,0) * (0.5 ** 9)
p_t <- p_3 + p_2 + p_1 + p_0
p_t
## [1] 0.2539062
q_t <- 1 - p_t

#Calculate and display the expected value
expected_value <- (p_t * 23) - (q_t * 26)
round(expected_value, 2)
## [1] -13.56

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

expected_value * 994
## [1] -13477.24

(13) polygraph

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

We’re given that the polygraph detected them as a liar and now we need to account for the fact that they were actually a liar. Thus, we’re finding the intersection that they were detected as a liar and actually telling a lie:

p_detect_lie <- 0.59
p_tell_lie <- 0.20
p_tell_lie * p_detect_lie
## [1] 0.118
  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.)

We’re given that the polygraph detected them as a truth-teller and need to account for the fact that they were actually a truth-teller. Thus, we’re finding the intersection that they were detected as a truth-teller and actually telling the truth:

p_detect_truth <- 0.9
p_tell_truth <- 1 - p_tell_lie
p_detect_truth * p_tell_truth
## [1] 0.72
  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.

This is an OR statement. Thus we need to find the probability that an individual was identified as a liar (even though they were a truth-teller) and add it to the probability that they were a liar:

p_wrong_liar <- p_tell_truth * (1 - p_detect_truth)
p_wrong_liar + p_tell_lie
## [1] 0.28