<- mean(sample(1:100, size = 1000000, replace = TRUE)^2)
expec print(expec)
[1] 3384.936
Francois de Ryckel
November 14, 2023
November 14, 2022
The idea behind this post is to collect various numerical methods to simulate discrete probability problems.
Question: what is the expectation if one square a number that is picked at random out of a hat (with replacement) that contains the numbers 1 to 100.
The calculated expectation should be: \[\sum_{x=1}^{100} x^2 P(X=x) = \sum_{x=1}^{100} x^2 \frac{1}{n} = \frac{101 \cdot 201}{6} = 3383.5\]
We could connect this to the Jensen’s inequality (as we are dealing with a convex function) and show that indeed the expectation of the function is greater than the function of the expectation: \(\mathbb{E}[f(X)] \geq f(\mathbb{E}[X])\)