outcomes <- expand.grid(d1 = 1:6, d2 = 1:6, d3 = 1:6)
sums <- rowSums(outcomes)
count_12 <- length(sums[sums == 12])
total <- length(sums)
prob_12 <- count_12/total
prob_12
## [1] 0.1157407
The sample space for three fair six-sided dice has 6^3 or 216 outcomes (total <- length(sums)). There are 25 outcomes where the sum = 12 (count_12 <- length(sums[sums == 12])). So:
\[ P(\text{sum}=12) = \frac{25}{216} = 0.1157 \]
counts <- matrix(c(200,200,100,200,200,
300,100,200,100,100),
nrow = 2, byrow = TRUE)
rownames(counts) <- c("Male", "Female")
colnames(counts) <- c("Apartment", "Dorm", "Parent(s)", "Sorority/Frat", "Other")
total <- sum(counts)
prob <- (counts["Male", "Other"] + counts["Female", "Other"]) / total
prob
## [1] 0.1764706
The total number of customers is 1700, and 300 of them live in “Other” (200 males, 100 females). Therefore:
\[ P(\text{Male+Other} \;\text{OR}\; \text{Female+Other}) = \frac{300}{1700} = .1765 \] 3.
tot_cards <- 52
diamonds <- 13
tot_cards_rem <- tot_cards -1
diamonds_rem <- diamonds -1
prob <- diamonds_rem/tot_cards_rem
prob
## [1] 0.2352941
Given the first card drawn is a diamond, there are 12 diamonds remaining and 51 total cards left in the deck:
\[ P(\text{2nd is Diamond} \mid \text{1st is Diamond}) = \frac{12}{51} = .2353 \] 4.
num_lnps <- choose(20,10)
num_lnps
## [1] 184756
The number of possible lineups is the number of ways to choose 10 songs from 20, where order doesn’t matter. Therefore:
\[ \binom{20}{10} = 184,756 \] 5.
num_sys <- 20*20*18
num_sys
## [1] 7200
The total number of possible home theater systems is found by multiplying the number of choices for each component, so:
\[ 20 \times 20 \times 18 = 7200 \]
num_ord <- factorial(10)
num_ord
## [1] 3628800
Since the order in which the doctor visits the patients matters, this is a permutations problem, which invites the use of the factorial command:
\[ 10! = 3,628,800 \]
coin_oc <- 2^7
die_oc <- 6^3
card_oc <- choose(52,4)
total_oc <- coin_oc*die_oc*card_oc
total_oc
## [1] 7485004800
The total number of outcomes is the product of the outcomes from each stage: coin tosses, die rolls, and card draws:
\[ 2^7 \times 6^3 \times \binom{52}{4} = 7,485,004,800 \] 8.
num_seats <- factorial(4-1)*factorial(4)
num_seats
## [1] 144
Seat the 4 women around the table first (as is polite): (4-1)! ways because rotations are the same. Then seat the 4 men int he remaining 4 alternate seats: 4! ways -
\[ (4-1)!\times 4! = 3!\times 24 = 144 \]
p_user <- .03
p_not <- 1 - p_user
ppos_user <- .95
pneg_not <- .99
ppos_not <- 1 - pneg_not
bayes <- function(prior, likelihood) {
evidence <- sum(prior*likelihood)
posterior <- (prior*likelihood)/evidence
posterior
}
prior <- c(User = p_user, NotUser = p_not)
lpos <- c(ppos_user, ppos_not)
post <- bayes(prior, lpos)
post_user_given_pos <- post["User"]
post_user_given_pos
## User
## 0.7460733
Even with a strong test (95% sensitivity, 99% specificity), the base rate of opioid use is low (3%). After a positive result, the probability the person is actually a user is:
\[ P(\text{User}\mid +)= \frac{P(+\mid \text {User})P(\text{User})} {P(+\mid \text{User})P(\text{User})+P(+\mid \text{Not User})P(\text{Not User})} = \frac{0.95\cdot 0.03}{.95\cdot 0.03 + 0.01\cdot 0.97} = .7461 \]
library(DiagrammeR)
## Warning: package 'DiagrammeR' was built under R version 4.4.3
grViz("
digraph tree {
graph [rankdir = LR]
node [shape = box]
Start -> User [label = 'P(User)=0.03']
Start -> NotUser [label = 'P(Not)=0.97']
User -> Pos1 [label = 'P(+|User)=0.95']
User -> Neg1 [label = '0.05']
NotUser -> Pos2 [label = 'P(+|Not)=0.01']
NotUser -> Neg2 [label = '0.99']
Start [label = 'Person']
User [label = 'User']
NotUser [label = 'Not user']
Pos1 [label = '+']
Neg1 [label = '-']
Pos2 [label = '+']
Neg2 [label = '-']
}
")
total_brown_sides <-3
brown_both_sides <-2
prob <- brown_both_sides/total_brown_sides
prob
## [1] 0.6666667
There are three equally likely ways to observe a brown side: two come from the brown-brown pancake and one comes from the golden-brown pancake. In two of the three cases, the other side is also brown. Therefore, the probability that the other side is brown is two thirds.
\[ P(\text{Other side is brown} \mid \text{Observed brown}) = \frac{2}{3} \approx 0.6667 \]