6.1.6
A die is rolled twice. Let X denote the sum of the two numbers that turn up, and Y the difference of the numbers (specifically, the number on the first roll minus the number on the second). Show that E(XY ) = E(X)E(Y ). Are X and Y independent?
library( dplyr )
#make a dataframe to hold each possible roll
die1 <- c( rep( 1,6 ), rep( 2,6 ), rep( 3,6 ), rep( 4,6 ), rep( 5,6 ), rep( 6,6 ))
die2 <- c( rep( 1:6,6 ) )
combo_df <- data.frame( 'roll1' = die1, 'roll2' = die2 )
combo_df <- combo_df %>% mutate( X = roll1 + roll2, Y = abs(roll1 - roll2), XY = X*Y )
head( combo_df )## roll1 roll2 X Y XY
## 1 1 1 2 0 0
## 2 1 2 3 1 3
## 3 1 3 4 2 8
## 4 1 4 5 3 15
## 5 1 5 6 4 24
## 6 1 6 7 5 35
find the mean of the columns…
## roll1 roll2 X Y XY
## 3.500000 3.500000 7.000000 1.944444 13.611111
Does mean( XY ) == mean(X)*mean(Y)?
## XY
## TRUE
This shows that, yes, E(XY ) = E(X)E(Y )
The code below simulates this process and finds the values X, Y and XY
#simulate the double dice roll 'n' times
n <- 10000
roll1 <- sample(1:6, n, replace=TRUE)
roll2 <- sample(1:6, n, replace=TRUE)
#use dplyr methods
die_df <- data.frame( 'roll1' = roll1, 'roll2' = roll2 )
die_df <- die_df %>% mutate( X = roll1 + roll2, Y = abs(roll1 - roll2), XY = X*Y )
head( die_df )## roll1 roll2 X Y XY
## 1 4 6 10 2 20
## 2 1 5 6 4 24
## 3 1 3 4 2 8
## 4 3 2 5 1 5
## 5 3 3 6 0 0
## 6 2 1 3 1 3
Now find the mean of the columns…
## roll1 roll2 X Y XY
## 3.4648 3.5096 6.9744 1.9468 13.5922
Does mean( XY ) == mean(X)*mean(Y)?
## XY
## 13.5922
## X
## 13.57776
…those simulated values look pretty close