sides <- 6
sum1 <- 12
all_prob <- expand.grid(rep(list(1:sides), 3))
rowSums(all_prob)
## [1] 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 10 6 7 8 9 10 11 7
## [26] 8 9 10 11 12 8 9 10 11 12 13 4 5 6 7 8 9 5 6 7 8 9 10 6 7
## [51] 8 9 10 11 7 8 9 10 11 12 8 9 10 11 12 13 9 10 11 12 13 14 5 6 7
## [76] 8 9 10 6 7 8 9 10 11 7 8 9 10 11 12 8 9 10 11 12 13 9 10 11 12
## [101] 13 14 10 11 12 13 14 15 6 7 8 9 10 11 7 8 9 10 11 12 8 9 10 11 12
## [126] 13 9 10 11 12 13 14 10 11 12 13 14 15 11 12 13 14 15 16 7 8 9 10 11 12
## [151] 8 9 10 11 12 13 9 10 11 12 13 14 10 11 12 13 14 15 11 12 13 14 15 16 12
## [176] 13 14 15 16 17 8 9 10 11 12 13 9 10 11 12 13 14 10 11 12 13 14 15 11 12
## [201] 13 14 15 16 12 13 14 15 16 17 13 14 15 16 17 18
sum(rowSums(all_prob) == 12)
## [1] 25
length(rowSums(all_prob))
## [1] 216
finalprob <- (25/216)
print(finalprob, digits = 4)
## [1] 0.1157
data <- data.frame(males = c(200, 200, 100, 200, 200),
females = c(300, 100, 200, 100, 100)
)
data
## males females
## 1 200 300
## 2 200 100
## 3 100 200
## 4 200 100
## 5 200 100
colsums <- colSums(data)
total_residence <- 900 + 800
total_residence
## [1] 1700
rowSums(data)
## [1] 500 300 300 300 300
other_total <- 300
prob_mf_other <- other_total / total_residence
print(prob_mf_other, digits = 4)
## [1] 0.1765
possible_events_cards <- 52
possible_events_diamonds <- 13
possible_events_2nd_draw_cards <- 51
possible_events_2nd_draw_diamonds <- 12
prob_diamonds_2nd_draw <- possible_events_2nd_draw_diamonds / possible_events_2nd_draw_cards
print(prob_diamonds_2nd_draw, digit = 4)
## [1] 0.2353
perm_without_replacement <- function(n,r){
return(factorial(n)/factorial(n-r))
}
perm_without_replacement(20,10)
## [1] 670442572800
comb_with_replacement <- function(n, r){
return(factorial(n + r - 1) / (factorial(r) * factorial(n-1)))
}
comb_with_replacement(58, 3)
## [1] 34220
factorial(10)
## [1] 3628800
cointoss <- 2^7
diceroll <- 6^3
cardsdrawn <- choose(n=52,k=4)
total_outcomes <- cointoss*diceroll*cardsdrawn
print(total_outcomes)
## [1] 7485004800
combo_men <- factorial(4)
combo_women <- factorial(4)
combo_pairs_mw <- factorial (4)
num_ways_arrangement <- combo_men * combo_women * combo_pairs_mw
print(num_ways_arrangement)
## [1] 13824
\[ P(user \cap positive) = {P(positive \mid user) \times P(user)} \]
p_user <- .03
p_posGivenuser <- .95
p_user_and_pos <- p_user * p_posGivenuser
p_user_and_pos
## [1] 0.0285
\[ P(positive) = {P(positive \cap user) + P(positive \cap nonuser)} \]
p_nonuser <- .97
p_posGivenNonuser <- 1 - .99
p_pos_and_nonuser <- p_nonuser * p_posGivenNonuser
p_pos <- p_user_and_pos + p_pos_and_nonuser
p_pos
## [1] 0.0382
\[ P(user \mid positive) = \frac{P(positive \mid user) \times P(user)}{P(positive)} \]
p_userGivenpos <- p_user_and_pos / p_pos
p_userGivenpos
## [1] 0.7460733
\[ P(other side unseen brown \mid pancake drawn is brown) = \frac{P(other side unseen brown \cap pancake drawn is brown)}{P(pancake drawn is brown)} \]
We need to find the probability that the other unseen side is brown, given that the pancake we already drew is brown. We do this by finding the probability the other side is brown and the initially drawn pancake’s side is brown. Because at least one side has to be brown, we can ignore the pancake with two golden sides. The probability the other side is brown and the initially drawn pancake’s side is brown is 1/3, because we know one side is already brown, so there is a 1/3 chance for choosing the remaining pancake. There are two pancakes with at least one brown side, so the probability of drawing a pancake with a brown side is 2/3.
p_otherside_brown_givenfirstside_brown <- (1/3) / (2/3)
p_otherside_brown_givenfirstside_brown
## [1] 0.5