Thoughts: With limited experience in R, the hint to use “expand.grid” was extremely helpful!
Step 1: Create a vector of all possible outcomes of a single die
(1-6) Step 2: Create a data frame of all possible outcomes of rolling
TWO dice (expand.grid)
Step 3: Count the number of rows that add up to 12 (rowSums)
Step 4: Count the total number of possible outcomes
Step 5: Calculate probability (number of 12s/total number of
outcomes)
Step 6: Calculate probability of NOT rolling a 12 (compliment)
Step 7: Calculate probability of NOT rolling a 12 on 3 rolls
Step 8: Calculate probability of rolling a 12 on 3 rolls
# All possible results rolling a single die
die <- 1:6
#Data frame expanded to include all possible combinations for 2 dice
results <- expand.grid(die1 = die, die2 = die)
#Calculate the total number of possibilities
total <- nrow(results)
#Count number of occurrences where combinations = 12
twelve <- sum(rowSums(results) == 12) #36
#Calculate the probability of rolling a 12
p_twelve_one <- twelve / total #0.03
#Probability of NOT rolling a twelve (compliment)
p_not_twelve <- 1 - p_twelve_one #0.98
#Probability of NOT rolling a 12 in 3 rolls
p_not_twelve_three <- (p_not_twelve) ^ 3 #0.92
#Probability of rolling a 12 AT LEAST once in 3 rolls
p_twelve_three <- 1 - p_not_twelve_three #0.08
print(paste("The probability of rolling a 12 AT LEAST once in 3 rolls is:", round(unname(p_twelve_three), 3)))
## [1] "The probability of rolling a 12 AT LEAST once in 3 rolls is: 0.081"
# Create the matrix
residence <- matrix(c(200, 300,
200, 100,
100, 200,
200, 100,
200, 100),
nrow = 5, byrow = TRUE)
# Add column and row labels
rownames(residence) <- c("Apartment",
"Dorm",
"Parent's",
"Sorority/Fraternity",
"Other")
colnames(residence) <- c("Males", "Females")
# Generate marginal counts
row_totals <- rowSums(residence)
col_totals <- colSums(residence)
total <- sum(residence)
# The probability of being (Male and Other) or (Female and Other)
prob_other <- row_totals["Other"] / total
# Display the result
print(paste("The probability of being (Male AND Other) OR (Female AND Other) is:", round(unname(prob_other),3)))
## [1] "The probability of being (Male AND Other) OR (Female AND Other) is: 0.176"
Thoughts:
1. Cards/Initial State: Standard deck has 52 cards (13 diamonds)
2. Once the first draw is complete, there are 51 cards remaining,
obviously
3. There are now 12 diamonds remaining
4. Probability
\[P(Diamond_2\vert Diamond_1) = \frac{12}{15} \]
#Card initial state
diamonds <- 13
full_deck <- 52
#State after drawing first diamond
remaining_diamonds <- diamonds - 1
remaining_deck <- full_deck - 1
#Probability
p_second_diamond <- remaining_diamonds / remaining_deck
#Display
print(paste("The probability of selecting a second diamond is:",
round(unname(p_second_diamond), 3)))
## [1] "The probability of selecting a second diamond is: 0.235"
Thoughts: This seems to be a simple permutation using the formula:
\[P(n,r)=\frac{n!}{(n-r)!} \]
In this case, it is a permutation of selecting 10 items from a pool of 20
#Given info
r <- 10
n <- 20
#Formula
sequence <- factorial(n) / factorial(n - r)
#Display
print(paste("The permutations of selection 10 items from a pool of 20 is:",
formatC(unname(sequence), format = "f", big.mark = ",", digits = 0)))
## [1] "The permutations of selection 10 items from a pool of 20 is: 670,442,572,800"
(Honestly, I just learned to format large numbers in a more readable format using commas.)
Thoughts:
I believe I am supposed to use the fundamental counting principle as we
have 3 sets of items and order does not matter. This allows me to simply
the 3 elements together.
#What we have
tvs <- 20
sound_systems <- 20
dvd_player <- 18
#Total combinations (using the fundamental counting principle)
total_systems <- tvs * sound_systems * dvd_player
#Display
print(paste("Total different home theater systems is: ", total_systems))
## [1] "Total different home theater systems is: 7200"
Thoughts:
We have a permutation here since we have an ordered arrangement ogf a
set of objects
\[n! = n \times (n-1) \times (n-2) \times \dots \times 1\]
#Patients
n <- 10
#Possible visits
visits <- factorial(n)
#Display
print(paste("Total number of visits possible is:", visits))
## [1] "Total number of visits possible is: 3628800"
Thoughts: We have a compound event here. 3
independent events
Step 1: Get number of options for each of the 3 events.
* Coin Toss: Since only 2 outcomes (H or T), then \(2^7\)
* Die rolled 3 times. 6 outcomes. \(6^3\) * Cards: Pick 4 cards out of 52. No
replacement. \[\binom{n}{r} =
\frac{n!}{r!(n-r)!}\]
Step 2: Total possible outcomes = \[Outcomes_{possible} = Coin_{possible} *
Die_{possible} * Cards_{possible}\]
Step 3: That’s it?
#Coin
coin_outcomes <- 2^7
#Die
die_outcomes <- 6^3
#Cards
#worked but resulted in a bizarre number when multiplied with above
#cards_outcomes <- factorial(52)/(factorial(4) * factorial(52 - 4))
#Trying the choose function from our reading
cards_outcomes <- choose(52, 4)
#Total Outcomes
total_outcomes <- coin_outcomes * die_outcomes * cards_outcomes
coin_outcomes
## [1] 128
die_outcomes
## [1] 216
cards_outcomes
## [1] 270725
print(paste("The total of all different outcomes is:" , format(total_outcomes, format = "f", big.mark = ",", digits = 1 )))
## [1] "The total of all different outcomes is: 7e+09"
Thoughts: Round table means that there is no obvious starting position? So perhaps we have to arbitrarily assign a male or female to a seat to get us out of the starting block. Let’s say M.
This took a lot of thinking as I kept trying to simply move in order around the table (ie MFMFMFMF). I could not understand how to do this.
Then I realized that if we seat the remaining 3 Males first, then we can determine that there are 6 ways to do that (4-1)!.
My brain also could not wrap itself around that I was doing math on 3 males and 4 females. I kept wanting this to be the same.
Once I “got there,” it was easy math.
#Given
men <- 4
women <- 4
#Number of ways to seat the men
men_seating <- factorial(men - 1)
women_seating <- factorial(women)
#Permutations
total <- men_seating * women_seating
#display
print(paste("The total number of ways for men and women to be seated is:", total))
## [1] "The total number of ways for men and women to be seated is: 144"
Thoughts:
Yikes!
#Given
p_positive_given_user <- 0.95 #P(+|user)
p_negative_given_not_user <- 0.99 #P(-|not user)
p_user <- 0.03 #P(user)
#Calculate some stuff
p_not_user <- 1 - p_user #P(not user)
p_positive_given_not_user <- 1 - p_negative_given_not_user #P(+|not user) "False Positive"
#Calculate P(+)
p_positive <- (p_positive_given_user * p_user) + (p_positive_given_not_user * p_not_user)
#P(user|+) = (P(+|user) * P(user))/P(+)
p_user_given_positive <- ((p_positive_given_user) * (p_user))/p_positive
#display
print(p_user_given_positive)
## [1] 0.7460733
#What we have
#pancake_golden_golden (0 ways to show brown)
#pancake_golden_brown (1 way to show brown)
#pancake_brown_brown (2 ways to show brown)
#Total ways to see a brown side
total <- 0 + 1 + 2
#Ways to see brown on one side AND brown on the other side
brown_both_sides <- 2
#Math
probability <- brown_both_sides/total
#display
#print(paste("The probability of selecting a second diamond is:",
# round(unname(p_second_diamond), 3)))
print(paste("P(other side is brown|observed brown) is:", round(unname(probability), 3) ))
## [1] "P(other side is brown|observed brown) is: 0.667"