dice_grid <- expand.grid(rep(list(1:6), 3))
dice_grid$sums <- rowSums(dice_grid)
print(length(dice_grid$sums))
## [1] 216
print(sum(dice_grid$sums == 12))
## [1] 25
Out of the total number of outcomes, 216, there are 25 possible combinations that have a sum of 12, so the probability is \(\frac{25}{216} = 0.1157\)
customers <- matrix(c(200, 200, 100, 200, 200, 300, 100, 200, 100, 100), nrow = 5, ncol = 2)
total_customers <- sum(customers)
prob_males_other <- (200 + 100)/(total_customers)
print(prob_males_other)
## [1] 0.1764706
The probability that a customer is lives in ‘Other’ (being either male or female) is 0.1765.
num_cards <- 52
num_diamonds <- 13
prob <- (num_diamonds - 1)/(num_cards - 1)
print(prob)
## [1] 0.2352941
After removing a diamond, there would be one less card in the total and in the diamond supply, so the probability would be 0.2353.
library(gtools)
perm_without_replacement <- function(n, r){
return(factorial(n)/factorial(n - r))
}
perm_without_replacement(20, 10)
## [1] 670442572800
There are 670442572800 different lineups, assuming order matters.
home_theater_systems <- choose(20,1)*choose(20,1)*choose(18,1)
home_theater_systems
## [1] 7200
Since we are only selecting one of each category, and the order of the selection doesn’t matter, we can consider this a combination using the choose function without replacement.
perm_without_replacement(10,10)
## [1] 3628800
This can be treated as a permutation as order would matter. This is equivalent to just doing 10 factorial, to produce 3628800 ways.
coin_outcomes <- 2^7
die_outcomes <- 6^3
card_outcomes <- perm_without_replacement(52,4)
print(coin_outcomes*die_outcomes*card_outcomes)
## [1] 179640115200
Each group is independent of the other, each coin toss and die roll is independent, so multiplication of the total number of options will account for the coins and dice. The cards can be treated as a permutation without replacement as the order would matter.
women_options <- factorial(3)
men_options <- factorial(4)
total_options <- women_options*men_options
print(total_options)
## [1] 144
There are 3! ways for the women to be arrange, as the table is circular each offset by one seat would be identical for the women, then once the women are seated, there are 4! ways for the men to be arrange in between them.
pos_given_user <- 0.95
neg_given_nonuser <- 0.99
user <- 0.03
nonuser <- 1 - user
neg_given_user <- 1 - pos_given_user
pos_given_nonuser <- 1 - neg_given_nonuser
pos <- pos_given_nonuser*nonuser + pos_given_user*user
user_given_pos <- (pos_given_user*user)/pos
print(user_given_pos)
## [1] 0.7460733
Using Bayes Theorem the probability that a person who test positive is actually a user is 0.7461.
brown_brown <- 1/3
brown_gold <- 1/3
gold_gold <- 1/3
brown_side_given_brown_brown <- 1
brown_side_given_brown_gold <- 1/2
brown_side <- brown_brown*brown_side_given_brown_brown + brown_gold*brown_side_given_brown_gold
brown_brown_given_brown_side <- (brown_side_given_brown_brown*brown_brown)/brown_side
print(brown_brown_given_brown_side)
## [1] 0.6666667
There is a 2/3 chance that the other side is brown. This is shown by Bayes’ theorem above.