Covariance of 2 random variables

Solution 1:

Recognize that $Y|X=k \sim \text{Uniform}\{1,\dots,k-1\}$, therefore $$\mathbb{E}[Y\vert X] = X/2.$$

By the Tower Property, $$\mathbb{E}[XY]=\mathbb{E}[\mathbb{E}[XY\vert X]] = \mathbb{E}[X\mathbb{E}[Y\vert X]]=\frac{1}{2}\mathbb{E}[X^2],$$ and $$\mathbb{E}[Y]=\mathbb{E}[\mathbb{E}[Y\vert X]] = \frac{1}{2}\mathbb{E}[X],$$

so

$$\text{Cov}(X,Y)=\mathbb{E}[YX]-\mathbb{E}[Y]\mathbb{E}[X] = \frac{1}{2}\mathbb{E}[X^2]-\frac{1}{2}\mathbb{E}[X]^2 = \frac{1}{2}\text{Var}(X).$$ Marginally we have $$P(X=k) = \frac{k-1}{16}\left(\frac{3}{4}\right)^{k-2}$$ for $k\in\{2,3,\dots\}.$

You can work out what $\text{Var}(X)$ is like you did above, or recognize $X$ as having the same distribution as a (shifted) negative binomial random variable, i.e. $X=X'+2$, where $X'\sim \text{NB}(r=2, p=\frac{3}{4})$. Therefore $$\text{Cov}(X,Y)=\frac{1}{2}\text{Var}(X) = \frac{1}{2}\text{Var}(X') = \frac{1}{2}\frac{2\cdot\frac{3}{4}}{\left(1-\frac{3}{4}\right)^2}=12.$$