In: Statistics and Probability
R Exercise 1. (a) Simulate the rolling of two dice 10,000 times. (b) Identify which rolls of the dice are in the event A, the dice add up to a perfect square (4 or 9). Determine what proportion of the 10,000 rolls are in A. (c) Identify which rolls of the dice are in the event B, the dice add up to an even number. Determine what proportion of the 10,000 rolls are in B. (d) Find out which rolls are in A ∩ B. Find the proportion that are in A ∩ B. How does that compare to the proportion in A multiplied by the proportion that are in B? (e) Of the rolls in which B occurs that you identified in part (c), what proportion of those rolls are also in A. How does this compare to the proportion you computed in part (b)? (f) Do your results in this R exercise match what you would expect based on the answers you got in problem (4) of the previous sectio
(a)
Simulate the rolling of two dice 10,000 times D1 and D2 are the 10,000 results of roll of dice 1 and dice 2.
D1 = sample(c(1:6), 10000, replace = TRUE)
D2 = sample(c(1:6), 10000, replace = TRUE)
Sum = D1 + D2
(b)
The event A, the dice add up to a perfect square (4 or 9).
A = Sum[Sum == 4 | Sum ==9]
Proportion of A, P(A) = 0.189
length(A) / length(Sum)
(c)
The event B, the dice add up to an even number.
B = Sum[Sum %% 2 == 0]
Proportion of B, P(B) = 0.5049
length(B) / length(Sum)
(d)
The rolls are in A ∩ B (common to both A and B)
> intersect(A,B)
[1] 4
The proportion that are in A ∩ B is 0.0792
length(Sum[Sum == 4]) / length(Sum)
P(A) * P(B) = 0.189 * 0.5049 = 0.0954
The proportion in A multiplied by the proportion that are in B is not equal to P(A ∩ B)
(e)
Of the rolls in which B occurs, the proportion of those rolls are also in A is 0.4190476
length(Sum[Sum == 4]) / length(A)
This proportion is greater than the P(A) calculated in part (b).