For example here! it is stated that:
$$ E(X_i^2) = \mu^2 + \sigma^2 $$
However when I try in R:
x = runif(1000000, 10, 100)*runif(1000000, 10, 100)
y = runif(1000000, 10, 100)
mean(x)
[1] 3022.713
mean(y)*mean(y)+var(y)
[1] 3703.385
mean(y)*mean(y)
[1] 3025.192
What is wrong in my attempt to see the formula in action?
Your
xdoes not correspond to $X_i^2$: you have set upxto be the product of two independent uniform distributions rather than the square of one uniform distributionThis may illustrate it:
Since the two uniforms in the constriction of
xare independent and each have mean $55$, the expected value ofxhere is $55^2=3025$, which is the same as the square of the expected value ofy. Allowing for sampling variation, this is roughly what you seeWhat you are looking for is slightly different: the expectation of the square of the uniform distribution. This is $3700$ here, and you can also simulate this (again there is sampling variation)