rm(list = ls()) # Clear env
gc() # Clear unused memory
## used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 508471 27.2 1130651 60.4 644245 34.5
## Vcells 899328 6.9 8388608 64.0 1635533 12.5
cat("\f") # Clear console
require(utils)
# Create Dice
d1 <- 1:6
d2 <- 1:6
d3 <- 1:6
grid <- expand.grid(d1,d2,d3)
#print(grid)
t <- rowSums(grid)
n <- sum(t == 12)
d <- nrow(grid)
p <- round(n/d,3)
p
## [1] 0.116
The probability is 0.116
#Create table
tb <- data.frame(residence = c('Apartment','Dorm','W/ Parents','GreekLife House','Other'),
male = c(200, 200, 100, 200, 200),
female = c(300, 100, 200, 100, 100))
tb
## residence male female
## 1 Apartment 200 300
## 2 Dorm 200 100
## 3 W/ Parents 100 200
## 4 GreekLife House 200 100
## 5 Other 200 100
# Marginal Total
total <- sum(tb[2:3])
total
## [1] 1700
# Other Male
om <- with(tb, sum(male[residence == 'Other']))
om
## [1] 200
# Other Female
of <- with(tb, sum(female[residence == 'Other']))
of
## [1] 100
# Probability OM or OF
P <- round((om+of)/total,3)
P
## [1] 0.176
The probability is 0.176
deck <- 52 # num cards in deck
dmd <- 13 # num diamonds in a deck
# Remove one diamond from the deck
P = round((dmd-1)/(deck-1),3)
P
## [1] 0.235
The probability is 0.235
Making the assumption that we’re playing ten different songs because otherwise this is going to be a terrible event. Therefore order does matter
ts <- 20 # total songs
ss <- 10 # selected songs
lineups <- factorial(20)/factorial(10)
lineups
## [1] 670442572800
There are 670442572800 lineups possible
tv <- 20
ss <- 20
dp <- 18
ht <- 20*20*18
ht
## [1] 7200
There are 7200 different home theater systems possible
library(gtools)
df <- 1:10
p <- nrow(permutations(n=10,r=10,v=df))
p
## [1] 3628800
f <- factorial(10) # double check
f
## [1] 3628800
There are 3628800 possible ways to do the rounds
library(gtools)
coin <- c('heads','tails')
dice <- 1:6
deck <- 52
cards <- 4
Pcoin <- nrow(permutations(n=2,r=7,v=coin,repeats.allowed=T)) #Permutation w/ rep
Pdice <- nrow(permutations(n=6,r=3,v=dice,repeats.allowed=T)) #Permutation w/ rep
Pdeck <- (factorial(deck))/(factorial(deck-cards)) # Combination w/o rep
P = Pcoin * Pdice * Pdeck
P
## [1] 179640115200
There are 179640115200 possible outcomes
# Seat the 4 women, there are 3! ways they can sit not directly next to each other
women <- factorial(3)
# Now the men have 4! ways they can sit
men <- factorial(4)
# Seating arrangements
table <- women * men
table
## [1] 144
There are 144 ways to arrange the seating at the table
# Define variables
# Probability of a
a <- 0.03
# Probability (b | a) / Sensitivity
bGivena <- 0.95
# Probability (¬b | ¬a) / Specificity
notbGivenNota <- 0.99
# Calculate the rest of the values based upon the 3 variables above
notA <- 1 - a
notbGivena <- 1 - bGivena
bGivenNota <- 1 - notbGivenNota
# Joint Probabilities of a and B, a and notb, nota and b, nota and notb
aANDb <- a * bGivena
aANDnotb <- a * notbGivena
notaANDb <- notA * bGivenNota
notaANDnotb <- notA * notbGivenNota
# Probability of B
b <- aANDb + notaANDb
notB <- 1 - b
# Bayes theorem - probability of A | B
# Prob (a | b) = Prob (a AND b) / Prob (b)
aGivenb <- aANDb / b
round(aGivenb,3)
## [1] 0.746
The probability that person is actually a user after testing positive is 0.746
I think this answer depends on your perspective. I believe the answer is 0.5, because the question is what is the probability the other side is brown - at this point in the problem one pancake has been eliminated from the population set. There are only two options - it was the brown-golden pancake or the brown-brown. I started to calculate it with bayes and a rough tree diagram but I don’t believe that perspective is fully answer the question as it starts from scenario of 3 pancakes, when based on the phrasing of the question one possibility has been removed and is no relevant.
sessionInfo()
## R version 4.2.2 (2022-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19044)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United States.utf8
## [2] LC_CTYPE=English_United States.utf8
## [3] LC_MONETARY=English_United States.utf8
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United States.utf8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] gtools_3.9.4
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.31 R6_2.5.1 jsonlite_1.8.4 evaluate_0.20
## [5] cachem_1.0.6 rlang_1.0.6 cli_3.6.0 rstudioapi_0.14
## [9] jquerylib_0.1.4 bslib_0.4.2 rmarkdown_2.20 tools_4.2.2
## [13] xfun_0.36 yaml_2.3.7 fastmap_1.1.0 compiler_4.2.2
## [17] htmltools_0.5.4 knitr_1.42 sass_0.4.5