Homework2

haidingluo

2023.9.26

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.

sides <- 6
sum1 <- 12

all_prob <- expand.grid(rep(list(1:sides), 3))

sums <- rowSums(all_prob)

num_successful <- sum(sums == sum1)

total_combinations <- length(sums)


probability <- num_successful / total_combinations

print(probability)
## [1] 0.1157407

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

# Define the counts for each category
male_other <- 200
female_other <- 100
total_customers <- 1700
prob <- (male_other/total_customers) + (female_other/total_customers)
print(prob)
## [1] 0.1764706

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?
Express your answer as a decimal number only. Show your R code.

remaining <- 52-1
dimond <- 13-1
probdiamond <- dimond/remaining
print(probdiamond)
## [1] 0.2352941

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? Show your R code.

perm_without_replacement <- function(n, r){
  return(factorial(n)/factorial(n - r))
}

perm_without_replacement(20,10)
## [1] 670442572800

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?
Show your R code.

num_tvs <- 20
num_sss <- 20
num_dvd <- 18

total_combinations <- num_tvs * num_sss * num_dvd

print(total_combinations)
## [1] 7200

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

total_patients <- 10
ways <- factorial(total_patients)

print(ways)
## [1] 3628800

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

num_coin <- 7

num_die <- 3

num_cards <- 52*51*50*49

total_outcomes <- 2^num_coin * 6^num_die *num_cards 

print(total_outcomes)
## [1] 179640115200

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.
Show your R code.

num_women <- 4
num_men <- 4
total_people <- num_women + num_men
num_arrangements <- factorial(num_men - 1) * factorial(num_women) 
print(num_arrangements)
## [1] 144

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 | +)?
Show your R code

P_sens <- 0.95  
P_not_user <- 0.99  
P_user <- 0.03  
 
P_positive <- (P_sens * P_user) / (P_sens * P_user + (1 - P_not_user) * (1 - P_user))  
  
 
print(P_positive)
## [1] 0.7460733

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.

golden_both <- 1/3
golden_brown <- 1/3
brown_both <- 1/3
probabilityofoneb <- 1/3 + 1/3
print(probabilityofoneb)
## [1] 0.6666667