In: Statistics and Probability
Suppose you role a die twice in succession, getting X1 and X2. Then divide them, getting Y=X1X2. Thus, Y
is discrete, ranging from a minimum of 1/6 to a maximum of 6.
X1 = c(1,2,3,4,5,6) X2 = c(1,2,3,4,5,6) Y = c() for (i in X1) { for (j in X2) { Y = c(Y, i/j) } }
Find the mean of the Y.
Simulate 10,000 (or more) iid observations Yi(=Xi1Xi2)
. Draw the graph of successive average (cumulative mean) of these Ys. Discuss your observations.
R code:
x1=c(1,2,3,4,5,6)
x2=c(1,2,3,4,5,6)
y=c()
for( i in x1)
{
for (j in x2)
{
y=c(y,i/j)
}
}
y
mean(y)
n=100000
k= sample(y,n,replace= TRUE)
cummean= c()
cummean[1]=k[1]
for (i in 2:length(k))
{
cummean[i] = (i-1)/i*cummean[i-1] + k[i]/i
}
x=seq(1,n)
plot(x,cummean)
mean(y) = 1.4292
simulation is done in the variable k :
[1] 1.5000000 1.0000000 2.0000000 0.1666667 2.0000000 0.4000000
3.0000000
[8] 2.0000000 1.5000000 0.1666667 2.0000000 1.6666667 1.3333333
0.2000000
[15] 0.6000000 1.3333333 3.0000000 4.0000000 1.5000000 0.1666667
2.0000000
[22] 4.0000000 0.5000000 1.6666667 0.5000000 2.5000000 0.3333333
1.0000000
[29] 1.3333333 1.6666667 0.8333333 1.0000000 1.0000000 1.2500000
6.0000000
[36] 0.2500000 0.2000000 3.0000000 1.6666667 1.0000000 1.0000000
1.0000000
[43] 0.5000000 5.0000000 0.5000000 0.8000000 0.4000000 1.0000000
1.5000000
[50] 1.6666667 1.0000000 5.0000000 1.2000000 0.7500000 1.5000000
1.0000000.........
The plot says that, as the sample increases the cumulative mean goes to the population mean i.e. mean of y.