Let $M$ have a binomial distribution with parameters $N$ and $p$. Conditioned on $M$, the random variable $X$ has a binomial distribution with parameters $M$ and $\pi$.
(a) Determine the marginal distribution for $X$.
(b) Determine the covariance between $X$ and $Y = M - X$.
Here are my thoughts so far:
(a)
First, I will find the joint distribution of $X$ and $M$.
$f_{X,M}(X = k , M = m) = f_{X|M}(X = k | M = m) \cdot f_M(M = m)$
= $m \choose k$ $\pi^k (1-\pi)^{m-k}{N \choose m}p^m(1-p)^{N-m}$, where $0 \leq k \leq m \leq N$.
Thus, we get $f_X(X = k) = \sum_{m = k}^N {m \choose k}$ $\pi^k (1-\pi)^{m-k}{N \choose m}p^m(1-p)^{N-m}$, where $0 \leq k \leq m \leq N$.
*Is there a way to simplify the above expression for $f_X(X = k)$ ? I'd like for there not to be a summation left after simplification, if possible.
(b)
$Cov(X, M - X) = Cov(X,M) - Cov(X,X) = E[XM] - E[X]E[M] - Var(X) = E[XM] - E[X]E[M] - E[X^2] + (E[X])^2$
The terms $(E[X])^2$ and $E[X]$ can be calculated after I'm able to get the fully simplified version of the p.d.f. of $X$ in part (a). But I'd like to at least obtain $E[XM]$ and $E[M]$ , for now.
$E[M] = \sum_{k=0}^m m{m \choose k}$ $\pi^k (1-\pi)^{m-k}{N \choose m}p^m(1-p)^{N-m}$
*I run into a similar problem as $f_X(X = k)$ in part (a). How can I simplify this expression for the expectation ?
Similarly, $E[XM] = \sum_{k = 0}^{m} \sum_{m = k}^{N} km{m \choose k}$ $\pi^k (1-\pi)^{m-k}{N \choose m}p^m(1-p)^{N-m}$
*Again, I'm not sure how to simplify the above expression for something nicer.
Thanks !