1. What is the probability of rolling a sum of 12 on three rolls of six-sided dice? Express your answer as a decimal number only. Show your R code.

library(probs)
## 
## Attaching package: 'probs'
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, union
round(sum(round(rowSums(rolldie(3, nsides = 6, makespace = TRUE)), digits = 0) == 12) / length(round(rowSums(rolldie(3, nsides = 6, makespace = TRUE)), digits = 0)), digits = 4)
## [1] 0.1157

The probability of rolling a sum of 12 on three rolls of a six-sided dice is 0.1157.

2. A newspaper company classifies its customers by gender and location of residence. The research department has gathered data from a random sample of customers. The data is summarized in the table below.

residence = c("Apartment", "Dorm", "With Parent(s)", "Sorority/Fraternity House", "Other")
males = c(200, 200, 100, 200, 200)
females = c(300, 100, 200, 100, 100)
prob_2_table = as.table(cbind(males, females))
colnames(prob_2_table) = c("males", "females")
rownames(prob_2_table) = residence

prob_2_table
##                           males females
## Apartment                   200     300
## Dorm                        200     100
## With Parent(s)              100     200
## Sorority/Fraternity House   200     100
## Other                       200     100

What is the probability that a customer is male and lives in ‘Other’ or is female and lives in ‘Other’? Express your answer as a decimal number only. Show your R code.

marginal_probs = prop.table(prob_2_table)
marginal_prob_males = sum(marginal_probs[ , 1])
marginal_prob_females = sum(marginal_probs[ , 2])
marginal_prob_apartment = sum(marginal_probs[1, ])
marginal_prob_dorm = sum(marginal_probs[2, ])
marginal_prob_with_parents = sum(marginal_probs[3, ])
marginal_prob_sorority_fraternity = sum(marginal_probs[4, ])
marginal_prob_other = sum(marginal_probs[5, ])

The probability that a customer is male and lives in Other is \(P(male \cap Other)\) = \(\mathrm{P}(male \mid Other)\) * \(P(Other)\), and the probability that a customer female and lives in Other is \(P(female \cap Other)\) = \(\mathrm{P}(female \mid Other)\) * \(P(Other)\). The probability that a customer is male and lives in Other or is a female and lives in Other is \(P(MO or FO)\) = \(P(MO)\) + \(P(FO)\) - \(P(MO and FO)\).

male_and_lives_in_other = round(marginal_prob_males *  marginal_prob_other, digits = 4)
female_and_lives_in_other = round(marginal_prob_females * marginal_prob_other, digits = 4)
or_prob_of_both = male_and_lives_in_other + female_and_lives_in_other - 0

3. Two cards are drawn without replacement from a standard deck of 52 playing cards. What is the probability of choosing a diamond for the second card drawn, if the first card, drawn without replacement, was a diamond?

round(((12/51) * (13/52)) / (13/52), digits = 4)
## [1] 0.2353

The probability of choosing a diamond for the second draw, given that the first card drawn was a diamond is about 0.2353.

4. A coordinator will select 10 songs from a list of 20 songs to compose an event’s musical entertainment lineup. How many different lineups are possible?

library(gtools)
# ordered sample without replacement --> n! / (n - k)!
(factorial(20)) / (factorial(20 - 10))
## [1] 670442572800
# can also use nsamp to run it easily in R and obtain the same answer
nsamp(n = 20, k = 10, replace = FALSE, ordered = TRUE)
## [1] 670442572800

670442572800 different lineups are possible.

5. You are ordering a new home theater system that consists of a TV, surround sound system, and DVD player. You can choose from 20 different TVs, 20 types of surround sound systems, and 18 types of DVD players. How many different home theater systems can you build?

# unordered sample 
20 * 20 * 18 
## [1] 7200

You can build 7200 different home theater systems.

6. A doctor visits her patients during morning rounds. In how many ways can the doctor visit 10 patients during the morning rounds?

# ordered permutation
factorial(10)
## [1] 3628800

There are 3628800 different orders in which the doctor can visit her patients.

7. If a coin is tossed 7 times, and then a standard six-sided die is rolled 3 times, and finally a group of four cards are drawn from a standard deck of 52 cards without replacement, how many different outcomes are possible?

n = c(2, 6, 52)
k = c(7, 3, 4)
r = c(TRUE, TRUE, FALSE)
 prod(nsamp(n = n, k = k, replace = r, ordered = FALSE))
## [1] 121284800

There are 121284800 different possible outcomes.

8. In how many ways may a party of four women and four men be seated at a round table if the women and men are to occupy alternate seats.

# once the first woman sits down, there are 3 other seating options for the rest of the women and four seating options for the men
factorial(3) * factorial(4)
## [1] 144

There are 144 ways the party can occupy alternate seats.

9. An opioid urinalysis test is 95% sensitive for a 30-day period, meaning that if a person has actually used opioids within 30 days, they will test positive 95% of the time P( + | User) =.95. The same test is 99% specific, meaning that if they did not use opioids within 30 days, they will test negative P( - | Not User) = .99. Assume that 3% of the population are users. Then what is the probability that a person who tests positive is actually a user P(User | +)?

# P(user | +) = P(+ | User) * P(user) / P(+ | User) * P(user) + P(+ | not user) * P(not user)

users = c(0.95, 0.05)
non_users = c(0.01, 0.99)
tests = as.table(rbind(users, non_users))
colnames(tests) = c("positive", "negative")
rownames(tests) = c("user", "non user")
tests
##          positive negative
## user         0.95     0.05
## non user     0.01     0.99
round((0.95 * 0.03) / (0.95 * 0.03 + 0.01 * 0.97), digits = 4)
## [1] 0.7461

P(user | +) = P(+ | User) * P(user) / P(+ | User) * P(user) + P(+ | not user) * P(not user) \(P(user \mid +)\) = (\(\mathrm{P}(+ \mid user)\) * \(P(user)\)) / (\(\mathrm{P}(+ \mid user)\) * \(P(user)\) + \(\mathrm{P}(+ \mid non-user)\) * \(P(non-user)\). The probability that a person who tests positive is actually a user is 0.7461.

10. You have a hat in which there are three pancakes. One is golden on both sides, one is brown on both sides, and one is golden on one side and brown on the other. You withdraw one pancake and see that one side is brown. What is the probability that the other side is brown? Explain.

Because you are holding a pancake with one brown side, you know the possibilities for the other side are brown, brown, and golden. Therefore, there are 3 possible outcomes, two of which are brown. There is a 2/3 chance that the other side of the pancake is brown.