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.
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
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
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.
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.
# unordered sample
20 * 20 * 18
## [1] 7200
You can build 7200 different home theater systems.
# ordered permutation
factorial(10)
## [1] 3628800
There are 3628800 different orders in which the doctor can visit her patients.
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.
# 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.
# 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.
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.