Marginal and conditional: Suppose we have a joint distribution p(x, y) for two random variables X and Y. In this problem, you will prove that the following algorithm,
1. simulate y.sim from the marginal p(y)
2. simulate x.sim from the conditional p(x|y.sim)
3. set X*=x.sim
generates a random value X* whose distribution is equal to the marginal distribution of X. Let X and Y be two discrete random variables, with X ∈ {x1, ..., xK} and Y ∈ {y1, ..., yL}. Let the joint density be denoted Pr(X = xk, Y = yl) = pxy(xk, yl).
(a) Using the rules of probability, write down the formula for the marginal density Pr(Y = y) = py(y) as a function of pxy, the marginal density Pr(X = x) = px(x) as a function of pxy, and the formula for the conditional density Pr(X = x|Y = y) = px|y(x|y) as a function of pxy and py.
(b) Suppose you randomly simulate on a computer a value Y* from the marginal py(y), and then simulate a value X* from px|y(x|Y*), i.e. the conditional distribution of X given Y = Y*. Prove that the probability that the resulting simulated value of X* is equal to xk is equal to px(xk).