What is the probability of rolling a sum of 12 on three rolls of six-sided dice?
# assign variables
dice_sides <- 1:6
sum1 <- 12
n_rolls <- 3
# simulate 3 rolls of six sided dice
total_p <- expand.grid(rep(list(dice_sides), n_rolls))
sums <- rowSums(total_p)
# create function for num_successful & total_combinations
sums <- rowSums(total_p)
num_successful <- sum(sums == sum1)
total_combinations <- length(sums)
# determine probability of rolling a sum of 12 & print answer
probability <- num_successful / total_combinations
print(probability)
## [1] 0.1157407
# Note: Just to urther depict
table(sums)
## sums
## 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## 1 3 6 10 15 21 25 27 27 25 21 15 10 6 3 1
hist(sums, breaks = 2.5:18.5,
main="Three Dice Simulation",
xlab = "Sum of Three Dice",
ylab = "Frequency",
col = "red")
Answer: There is a 0.1157407 probability of rolling a sum of 12 on three rolls of six-sided dice.
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. What is the probability that a customer is male and lives in ‘Other’ or is female and lives in ‘Other’?
## create a matrix
data <- c(200,200,100,200,200, 300, 100, 200, 100, 100)
Gender_Residence_Customers <-matrix(data, nrow = 5, ncol = 2)
# use colnames function
colnames(Gender_Residence_Customers)<-c("Male","Female")
# use rownames function
rownames(Gender_Residence_Customers)<-c("Apartment", "Dorm", "With Parent(s)", "Sorority/Fraternity", "Other")
# determine row totals
total <- rowSums(Gender_Residence_Customers)
#
Gender_Residence_Customers <- cbind(Gender_Residence_Customers, total)
Gender_Residence_Customers
## Male Female total
## Apartment 200 300 500
## Dorm 200 100 300
## With Parent(s) 100 200 300
## Sorority/Fraternity 200 100 300
## Other 200 100 300
# assign couts to categories
m_other <- 200
f_other <- 100
# define total number of customers
total <- 1700
# probability that a customer is male in Other and is female in other
prob_other <- (m_other/total) + (f_other/total)
print(prob_other)
## [1] 0.1764706
Answer: The probability that a customer is male and lives in Other or is female and lives in Other is 0.1764706.
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?
# determine remaining cards
remaining <- 52-1
# determine probability of diamond if card 1 was diamond and not replaced
dimond <- 13-1
probdiamond <- dimond/remaining
print(probdiamond)
## [1] 0.2352941
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?
# Create factorial function
songcombo_no_repalcement <- function(n,r){
return(factorial(n)/ factorial(n-r))
}
# Dtermine # of possible combos
songcombo_no_repalcement(20,10)
## [1] 670442572800
Answer: The the total amount of possible song combinations is 670442572800
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?
# assign variables
tv <- 20
surround_sound <- 20
dvd <- 18
#determine # of home theater systems combos
total_combos <- tv * surround_sound * dvd
print(total_combos)
## [1] 7200
Answer: There are 7200 total combinations of different home theater systems you can build.
A doctor visits her patients during morning rounds. In how many ways can the doctor visit 10 patients during the morning rounds?
# assign variables & utilze factorial function
patient_count <- 10
ways <- factorial(patient_count)
# results
print(ways)
## [1] 3628800
Answer: There are 3628800 possible ways a doctor can visit her patients during morning rounds.
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?
# assign variables
coin <- 2^7
die <- 6^3
cards <- 52*51*50*49
# combine individual outcomes
coin*die*cards
## [1] 179640115200
Answer: Result indicate that there are 179640115200 different outcomes.
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
# assign variables
women <- 4
men <- 4
# combine individual varaiables
total_people <- men + women
# use factorial function
possible_combos <- factorial(men -1)* factorial(women)
# results
print(possible_combos)
## [1] 144
Answer: There are 144 possible ways a party of four women and four men could be be seated.
BAYESIAN PROBABILITY: 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. You may use a tree, table, or Bayes to answer this problem.
# assign variables
p_sensititve <- 0.95
p_not_user <- 0.99
p_user <- 0.03
# Bayes to test the probability a positive test is actually a user
p_positive <- (p_sensititve * p_user) / (p_sensititve *p_user + (1 - p_not_user ))* (1-p_user)
#results
print(p_positive)
## [1] 0.7180519
Answer: There is a .7180519 probability that a person who tests positive is actually a user.
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
# assign variables
all_golden <- 1/3
goldenbrown <- 1/3
all_brown <- 1/3
# determine the probability that the other side is brown?
probability_of_brown_side <- 1/3 + 1/3
#Results
print(probability_of_brown_side)
## [1] 0.6666667
Answer: You withdraw one pancake and see that one side is brown, the probability that the other side is brown is 0.667 as seen int the results. Similar to the classic Monty Hall problem, by withdrawing one pancake that has a brown side, you are in theory, concentrating the original probability 1/3 of fully brown pancake, into to 2/3 probability that the pancake is fully brown on both sides.