I have seen this approach link in different places. Hence, I suppose that the following method is correct.
Let $f_{X,Y,Z}(x,y,z)=f_{X|Y,Z}(x|y,z)f_Y(y)f_Z(z)$ and I can easily sample from these 3 densities.
To sample from the marginal $f_X(x)$ we can do:
- For $j=1,\cdots,N$
- Sample $(y,z)^j=y^j \sim f_Y, z^j \sim f_Z$
- Sample $(x,y,z)^j = x^j \sim f_{X|Y,Z}(\cdot|y^j,z^j)$
- Keep only $\{x\}$
Is it correct?
My question is, can this method be used to sample from $f_{X|Y}(x|y)$ for example?