You randomly choose a number from this set of $n$ numbers: $\{1, 2, \dots , n\}$. Let $X$ be the number you chose. Let $Y$ be a natural number that is chosen randomly uniformly (discrete) from this set: $\{1, \dots , X\}$ Calculate:
- $\mathbb{E}[Y]$
- $\mathbb{E}[Y^2]$
- $ \sigma(Y)$ (Standard deviation)
- $\mathbb{P}(X+Y = 2)$
My try:
I assumed $X$ is distributed uniformly as well..
$E[Y] = \frac{1+X}{2} $ (We can use the fact that if $Y \sim \text{Uniform}$ then $\mathbb{E}[Y] = \frac{a+b}{2}$
but it is not a value it depends on $X$ .. no? I am not quite sure about it..Same like 1. (maybe?) $\mathbb{E}(Y^2) = \frac{(1+X)}{2}^2$
$\text{SD}(Y) = \sqrt{V} = \sqrt{E[Y^2]-E[Y]^2} = \sqrt{\frac{(1+X)^2}{2} - \frac{1+X}{2}}$
$P(X+Y=2) = P(X=1,Y=1) = \frac{1}{n} \cdot \frac{1}{1} = \frac{1}{n}$
I got stuck on 1,2,3 I am completely unsure how to solve them... I would appreciate your help! Thank you!
The hierarchical model is $$X \sim \operatorname{DiscreteUniform}(1,n), \\ Y \mid X \sim \operatorname{DiscreteUniform}(1,X).$$ Then the law of total expectation gives us $$\operatorname{E}[Y] = \operatorname{E}[\operatorname{E}[Y \mid X]] = \operatorname{E}[(1+X)/2] = \frac{\operatorname{E}[1+X]}{2} = \frac{1 + \operatorname{E}[X]}{2} = \frac{1}{2}\left(1 + \frac{1+n}{2}\right) = \frac{3+n}{4}.$$ This is because conditioned on $X$, the variable $Y \mid X$ has expectation $\frac{1+X}{2}$; then we apply the usual rules for linearity of expectation to finish the computation. You must understand that $\operatorname{E}[Y]$ cannot be a function of $X$; it can only depend on $n$, because $X$ is itself a random variable. Only if we condition $Y$ on the outcome of $X$ can we allow $X$ to be part of the expression for the expectation.
For the second part, we do the same thing: $$\operatorname{E}[Y^2] = \operatorname{E}[\operatorname{E}[Y^2 \mid X]].$$ But here, how do we evaluate the inner expectatin? We simply apply the definition of expectation of a function of a discrete random variable: $$\operatorname{E}[Y^2 \mid X] = \sum_{y=1}^X y^2 \Pr[Y = y] = \frac{1}{X} \sum_{y=1}^X y^2 = \frac{X(X+1)(2X+1)}{6X} = \frac{(X+1)(2X+1)}{6}.$$ Then proceed as usual: $$\operatorname{E}[Y^2] = \operatorname{E}\left[\frac{(X+1)(2X+1)}{6}\right] = \frac{\operatorname{E}[X^2]}{3} + \frac{\operatorname{E}[X]}{2} + \frac{1}{6},$$ and we evaluate $\operatorname{E}[X^2]$ using the same sum of consecutive squares identity we used earlier.
For the third part, we calculate the variance $$\operatorname{Var}[Y] = \operatorname{E}[Y^2] - \operatorname{E}[Y]^2$$ from the previous parts, then take the square root to obtain the standard deviation.
It is a worthwhile exercise to consider what the marginal distribution of $Y$ actually is. That is to say, what is $\Pr[Y = y]$, for each $y \in \{1, 2, \ldots, n\}$? To find this, we employ the law of total probability: note $$\Pr[Y = y] = \sum_{x=1}^n \Pr[Y = y \mid X = x]\Pr[X = x].$$ But if $x < y$, it is impossible to observe $Y = y$, so the above sum becomes $$\Pr[Y = y] = \sum_{x=y}^n \Pr[Y = y \mid X = x]\Pr[X = x] = \sum_{x=y}^n \frac{1}{x} \frac{1}{n} = \frac{H_n - H_{y-1}}{n},$$ where $$H_m = \sum_{k=1}^m \frac{1}{k}$$ is the $m^{\rm th}$ harmonic number. So for example, for $n = 9$, we have the table $$\begin{array}{c|c} y & \Pr[Y = y] \\ \hline 1 & \frac{7129}{22680} \\ 2 & \frac{4609}{22680} \\ 3 & \frac{3349}{22680} \\ 4 & \frac{2509}{22680} \\ 5 & \frac{1879}{22680} \\ 6 & \frac{275}{4536} \\ 7 & \frac{191}{4536} \\ 8 & \frac{17}{648} \\ 9 & \frac{1}{81} \\ \end{array}$$ and you can check that the sum of the probabilities equals $1$. Notice how this result is rather complicated, and would make computing the marginal moments through direct calculation rather difficult, which illustrates the power of the law of total expectation.