#define the possible outcomes of a singe die throw, find every combination of 3 dice throws, and find the total sample size
six_die = c(1,2,3,4,5,6)
combo = expand.grid(roll1 = six_die, roll2 = six_die, roll3 = six_die)
samplesSize <- nrow(combo)
#sum up the results of the 3 throws for each case and find how many resulted in a sum of 12
sum <- rowSums(combo)
eventSize <- length(sum[sum==12])
#divide the amount of times the sum was 12 by the total number of samples taken
eventSize/samplesSize
## [1] 0.1157407
The odds of getting a total sum of 12 when rolling 3 dice is 11.57%. Of the 216 possible outcomes, 25 of them have a sum of 12.
#create a martix to match the information from the above table.
customerData = matrix(
c(200, 300, 200, 100, 100, 200, 200, 100, 200, 100),
nrow = 5,
ncol = 2,
byrow = TRUE
)
colnames(customerData) <- c("Male", "Female")
rownames(customerData) <- c("Apartment", "Dorm", "With Parent(s)", "Sorority/Fraternity House", "Other")
customerData
## Male Female
## Apartment 200 300
## Dorm 200 100
## With Parent(s) 100 200
## Sorority/Fraternity House 200 100
## Other 200 100
#find row and column totals, bind results to matrix, and update names for clarity
customerData <- cbind(customerData, rowSums(customerData))
customerData <- rbind(customerData, colSums(customerData))
colnames(customerData) <- c("Male", "Female", "Total")
rownames(customerData) <- c("Apartment", "Dorm", "With Parent(s)", "Sorority/Fraternity House", "Other", "Total")
customerData
## Male Female Total
## Apartment 200 300 500
## Dorm 200 100 300
## With Parent(s) 100 200 300
## Sorority/Fraternity House 200 100 300
## Other 200 100 300
## Total 900 800 1700
#divide all entries by the total sample size to get the probability of each outcome
proportionalCustomerData <- customerData/customerData[6,3]
proportionalCustomerData
## Male Female Total
## Apartment 0.11764706 0.17647059 0.2941176
## Dorm 0.11764706 0.05882353 0.1764706
## With Parent(s) 0.05882353 0.11764706 0.1764706
## Sorority/Fraternity House 0.11764706 0.05882353 0.1764706
## Other 0.11764706 0.05882353 0.1764706
## Total 0.52941176 0.47058824 1.0000000
The probability that one is male and lives in other is 11.76%. The probability that one is female and lives in other is 5.88%.
We are looking for \(P(D2|D1)\), or the probability that the second card drawn is a diamond given that the first card was also a diamond. We can solve this in R with the code below.
pd1 = 13/52 # 13 diamond cards out of a total of 52
pd1
## [1] 0.25
pd2_given_d1 = 12/51 #after the initial draw, there is now 1 less diamond card in particular, and 1 less card in general
pd2_given_d1
## [1] 0.2352941
This result makes intuitive sense. If you draw a diamond card first, your odds of doing so again should be less than before.
Assuming that the coordinator cares about order, and that they would not want to repeat songs, we can use the formula \(\displaystyle \frac{n!}{(n-r)!}\) to describe the number of possible permutations. The amount of songs available is n=20; and we will take r=10 songs.
n <- 20
r <- 10
factorial(n)/factorial(n-r)
## [1] 670442572800
Now we are looking to solve for how many combinations we can make from these 3 items. Here the order does not matter, but what is sampled does. Since we are only taking 1 of each item, we know there are only 20 combinations of TVs, 20 of sound systems, and 18 of DVD players. We can find the overall number of combinations simply by multiplying these 3 values together.
tv <- 20
sound <- 20
dvd <- 18
tv*sound*dvd
## [1] 7200
Again we are trying to solve for possible permutations without reputation, so we’ll use the formula \(\displaystyle \frac{n!}{(n-r)!}\) like before.
n <- 10
r <- 10
factorial(n)/factorial(n-r)
## [1] 3628800
Here we will solve for 3 different combinations, 2 with replacement, one without, and then multiply those results by each other to get the total number of combinations. I am assuming that order does not matter for this problem, if it did then the numbers would be much higher.
\(\displaystyle \frac{(r+n-1)!}{r!(n-1)!}\) - Combinations w/repeats (used for the 7 coin flips and 3 dice rolls)
\(\displaystyle \frac{n!}{r!(n-r)!}\) - Combinations w/o repeats (used for the 4 card draws)
coin_combos <- factorial(7+2-1)/(factorial(7)*factorial(2-1))
dice_combos <- factorial(3+6-1)/(factorial(3)*factorial(6-1))
card_combos <- factorial(52)/(factorial(4)*factorial(52-4))
coin_combos*dice_combos*card_combos
## [1] 121284800
This problem comes down to a problem of permutation without replacement. However we can’t just use the basic formula due to the requirement that men and women must sit in alternate seats. We can however solve it by treating it as 8 sequential permutations each with a single sample from the alternating groups. The first 2 seat selections both can be written as:
\(\displaystyle \frac{n!}{(n-r)!} = \displaystyle \frac{4!}{(4-1)!} = 4\)
The next 2 seat selections, now pulling from a set of 3 men and 3 women can both be written as:
\(\displaystyle \frac{n!}{(n-r)!} = \displaystyle \frac{3!}{(3-1)!} = 3\)
And so on. The final result is solved in the following line of R code:
(4*4)*(3*3)*(2*2)*(1*1)
## [1] 576
Lets begin by writing out some of the given probabilities:
\(P(User) = 0.03, P(+|User) = 0.95, P(-|Not User) = 0.99, P(User|+) = ?\)
Note: We can use the information \(P(-|Not User) = 0.99\) to infer that \(P(+|Not User) = 0.01\)
We can solve this using Bayes Theorem:
\(P(User|+) = \displaystyle \frac{P(+|User)P(User)}{P(+)}\)
The numerator is easy to solve using the given values:
num <- 0.95*0.03
num
## [1] 0.0285
While the denominator \(P(+)\) is a bit more complicated. We must add up the the probability of every outcome where the test is positive.
denom <- 0.95*0.03 + 0.01*0.97
denom
## [1] 0.0382
With Bayes Theorem complete, we can solve for \(P(User|+)\)
num/denom
## [1] 0.7460733
That is to say that if you test positive for opioid use, there is still only a 74.6% chance that you are actually a user.
Note: we can write conditional probability in a more general form \(P(A|B) = \displaystyle \frac{P(A*B)}{P(B)}\)
We are looking for the conditional probability \(P(B2|B1)\). I began this problem by solving for \(P(B2*B1)\) or the chance that you pulled the pancake with 2 brown edges. We can easily see that this is 1/3rd.
p_b2_and_b1 <- 1/3
Now if we can find \(P(B1)\) we should be able to solve for the conditional probability. Thankfully this is also rather simple, as there are 3 pancake sides that are brown, and 3 that are golden, meaning that there a 50% chance of getting a brown side first.
p_b1 = 1/2
Plugging into the conditional probability formula gets us the following result:
\(\displaystyle \frac{P(B2*B1)}{P(B1)}\)
p_b2_and_b1/p_b1
## [1] 0.6666667
This makes some intuitive sense, as of the 3 brown sides in the hat, 2 of them are opposite another brown side. So if you pull one of them, you have a 2/3rds chance that the other side will be brown as well.
\(P(B2|B1) = 2/3\)