chips = c("r", "r", "r", "r", "r", "b", "b", "b", "o", "o")
n = length(chips)
chips
## [1] "r" "r" "r" "r" "r" "b" "b" "b" "o" "o"
a) Suppose you draw a blue chip. If drawing without replacement, what is the probability the next is also blue?
chips2 = c("r", "r", "r", "r", "r", "b", "b", "o", "o")
x = replicate(100000, sample(chips2, length(chips2), replace= F)[1] == "b")
table(x)/100000
## x
## FALSE TRUE
## 0.77867 0.22133
By hand, the solution is (2/9)=0.2222. The TRUE value on the table is very close to our estimated value.
b) Suppose you draw a chip and it is orange, and then you draw a second chip without replacement. What is the probability this second chip is blue?
chips3 = c("r", "r", "r", "r", "r", "b", "b", "b", "o")
y = replicate(100000, sample(chips3, length(chips3), replace= F)[1] == "b")
table(y)/100000
## y
## FALSE TRUE
## 0.66433 0.33567
By hand, the solution is (3/9)=0.3333. The TRUE value on the table is very close to our estimated value.
c) If drawing without replacement, what is the probability of drawing two blue chips in a row?
chips4 = c("a", "c", "d", "e", "f", "b", "b", "b", "g", "h")
z = replicate(100000, sum(as.numeric(rle(sample(chips4, n, replace= F))$lengths == "2")))
table(z)/100000
## z
## 0 1
## 0.52953 0.47047
By hand, the solution is (3/10)×(2/9)= (3/45)= 0.067. Unfortunately, the value under the “1” category (labeled TRUE in previous examples) is not close to our estimated value. That is due to a coding error and will be remedied as soon as a solution is found.
d) When drawing without replacement, are the draws independent? Explain.
No. Not independent. For example, as seen in (a) the probability of drawing a second blue chip is 0.2222 where the probability of withdrawing a blue chip was originally (3/10)=0.3. Not replacing chips alters the probability of the other chips being chosen.