1

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?

PascalIv
  • 241

1 Answers1

1

Your x does not correspond to $X_i^2$: you have set up x to be the product of two independent uniform distributions rather than the square of one uniform distribution

This may illustrate it:

set.seed(1)
n = 1000000
x = runif(n, 10, 100) * runif(n, 10, 100)
y = runif(n, 10, 100)

Since the two uniforms in the constriction of x are independent and each have mean $55$, the expected value of x here is $55^2=3025$, which is the same as the square of the expected value of y. Allowing for sampling variation, this is roughly what you see

mean(x)
# 3023.914
mean(y)*mean(y)
# 3023.477

What 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)

z = runif(n, 10, 100)^2 
mean(z)
# 3699.157
mean(y)*mean(y) + var(y)
# 3699.559
Henry
  • 169,616