knitr::opts_chunk$set(echo = TRUE)
library(tinytex)
library(pracma)
Source files: [https://github.com/djlofland/DATA605_S2020/tree/master/]
red <- 54
white <- 9
blue <- 75
total <- red + white + blue
prob <- red/total + blue / total
(round(prob, digits = 4))
## [1] 0.9348
green <- 19
red <- 20
blue <- 24
yellow <- 17
total <- green + red + blue + yellow
prob_red <- red/total
(round(prob_red, digits = 4))
## [1] 0.25
apt_m <- 81
apt_f <- 228
dorm_m <- 116
dorm_f <- 79
par_m <- 215
par_f <- 252
sf_m <- 130
sf_f <- 97
other_m <- 129
other_f <- 72
prob_not_m <- (apt_f + dorm_f + par_f + sf_f + other_f) / 1399
prob_not_par <- (apt_m + apt_f + dorm_m + dorm_f +sf_m+ sf_f+other_m+other_f) / 1399
prob_not_m_and_not_par <- (apt_f + dorm_f + sf_f + other_f) / 1399
prob <- prob_not_m + prob_not_par - prob_not_m_and_not_par
(round(prob, digits = 4))
## [1] 0.8463
likely dependent (working out is likely to initially decrease weight (fat), but then may increase weight (muscle mass)). However, going to the gym doesn’t mean you are applying yourself, so they could be independent for slackers.
veggie_num <- 3
cond_num <- 3
tortilla_num <- 1
veggie_types <- 8
cond_types <- 7
tortilla_types <- 3
# There are multiple solutions - do we allow customers to opt out of any given option and/or do we allow customers to double up on a given option.
# Solution 1 (no repeats and no opt out)
(everything_no_repeats <- veggie_types * (veggie_types-1) * (veggie_types-2) * cond_types * (cond_types-1) * (cond_types-2) * tortilla_types)
## [1] 211680
# Solution 2 (allow repeats - customers can get double or triple of a given veggie or condament)
(everything_allow_repeats <- veggie_types * veggie_types * veggie_types * cond_types * cond_types * cond_types * tortilla_types)
## [1] 526848
# Solution 3 (allow holding of veggies or condiments, ie don't get 3 of each, meaning "none" is an option
veggies_3_cond_3 <- veggie_types * (veggie_types-1) * (veggie_types-2) * cond_types * (cond_types-1) * (cond_types-2) * tortilla_types
veggies_2_cond_3 <- veggie_types * (veggie_types-1) * cond_types * (cond_types-1) * (cond_types-2) * tortilla_types
veggies_1_cond_3 <- veggie_types * cond_types * (cond_types-1) * (cond_types-2) * tortilla_types
veggies_0_cond_3 <- cond_types * (cond_types-1) * (cond_types-2) * tortilla_types
veggies_3_cond_2 <- veggie_types * (veggie_types-1) * (veggie_types-2) * cond_types * (cond_types-1) * tortilla_types
veggies_2_cond_2 <- veggie_types * (veggie_types-1) * cond_types * (cond_types-1) * tortilla_types
veggies_1_cond_2 <- veggie_types * cond_types * (cond_types-1) * tortilla_types
veggies_0_cond_2 <- cond_types * tortilla_types
veggies_3_cond_1 <- veggie_types * (veggie_types-1) * (veggie_types-2) * cond_types * tortilla_types
veggies_2_cond_1 <- veggie_types * (veggie_types-1) * cond_types * tortilla_types
veggies_1_cond_1 <- veggie_types * cond_types * tortilla_types
veggies_0_cond_1 <- cond_types * tortilla_types
veggies_3_cond_0 <- veggie_types * (veggie_types-1) * (veggie_types-2) * tortilla_types
veggies_2_cond_0 <- veggie_types * (veggie_types-1) *tortilla_types
veggies_1_cond_0 <- veggie_types * tortilla_types
veggies_0_cond_0 <- tortilla_types # boring!!!
(allow_skipping_options <- veggies_3_cond_3 + veggies_2_cond_3 +veggies_1_cond_3 + veggies_0_cond_3 +
veggies_3_cond_2 + veggies_2_cond_2 +veggies_1_cond_2 + veggies_0_cond_2 +
veggies_3_cond_1 + veggies_2_cond_1 + veggies_1_cond_1 + veggies_0_cond_1 +
veggies_3_cond_0 + veggies_2_cond_0 + veggies_1_cond_0 + veggies_0_cond_0)
## [1] 312675
# Solution 4 (allow skipping items with repeats)
# Note: ... just repeat the Solution 3 but don't use the -1 and -2 ... use the veggies_types and cond_types in each position
Independent unless Jeff calls Liz for a ride home, causing her to miss the evening news - in which case they could be Dependent
# By "Rank matters" I'm assuming this is permutations, not combinations
c <- 14
s <- 8
cabinets <- 1
for (spot in 1:s) {
cabinets <- cabinets * c
print(c(c,spot, cabinets))
c <- c - 1 # since no replacement and same person cannot occupy 2 positions
}
## [1] 14 1 14
## [1] 13 2 182
## [1] 12 3 2184
## [1] 11 4 24024
## [1] 10 5 240240
## [1] 9 6 2162160
## [1] 8 7 17297280
## [1] 7 8 121080960
(cabinets)
## [1] 121080960
# Note: no replacement, so each subsequent draw is dependent on the previous draw
red <- 9
orange <- 4
green <- 9
total <- (red + orange + green)
# --- possibilities: OGGG, GOGG, GGOG, GGGO
opt1 <- orange/total * green/(total-1) * (green-1)/(total-2) * (green-2)/(total-3) #OGGG
opt2 <- green/total * orange/(total-1) * (green-1)/(total-2) * (green-2)/(total-3) #GOGG
opt3 <- green/total * green/(total-1) * orange/(total-2) * (green-2)/(total-3) #GGOG
opt4 <- green/total * green/(total-1) * (green-1)/(total-2) * orange/(total-3) #GGGO
orange1_green3 <- (opt1 + opt2 + opt3 + opt4)
(round(orange1_green3, digits=4))
## [1] 0.0506
(11*10*9*8)
## [1] 7920
33% of subscribers to a fitness magazine are 34 or younger.
# wins: HHHT, HHTH, HTHH, THHH, HHHH
# total possibilities: 16
prob_heads3 <- (5/16) # Note: the 1 is because we don't care what happens with the 4th coin flip
value <- prob_heads3 * 97 - (1-prob_heads3) * 30
(round(value, digits=2))
## [1] 9.69
(win <- value * 559)
## [1] 5415.312
trials <- 9
succ_num <- 5
succ_prob = 0.5
prob = 0
for (h in succ_num:trials) {
prob <- prob + (fact(trials) / (fact(h)*fact(trials-h))) * (succ_prob^h) * (1-succ_prob)^(trials-h)
}
(value <- (prob*23) - (1-prob)*26)
## [1] -1.5
value * 994
## [1] -1491
pred_lie_true <- 0.59
pred_lie_false <- 1 - pred_lie_true
pred_truth_true <- 0.9
pred_truth_false <- 1 - pred_truth_true
will_lie <- 0.2
P(lie) = 0.20 (200/1000)
P(truth) = 0.8 (800/1000)
P(Detect Lie | Lie) = 0.59 (108/200)
P(Detect Truth | Truth) = 0.9 (720/800)
(108/188)
## [1] 0.5744681
(720/812)
## [1] 0.8866995
P(Liar) = 0.2
P(Detect_liear) = 0.59
Prob(Liar or Detected Liar) = P(Liar) + P(Detect Liar) - P(Liar and Detect)
(prob <- (200 + 188 - 108) / 1000)
## [1] 0.28