I want to sample from a univariate density $f_X$ but I only know the relationship:
$$f_X(x) = \int f_{X\vert Y}(x\vert y)f_Y(y) dy.$$
I want to avoid the use of MCMC (directly on the integral representation) and, since $f_{X\vert Y}(x\vert y)$ and $f_Y(y)$ are easy to sample from, I was thinking of using the following sampler:
- For $j=1,\dots, N$.
- Sample $y_j \sim f_Y$.
- Sample $x_j \sim f_{X\vert Y}(\cdot\vert y_j)$.
Then, I will end up with the pairs $(x_1,y_1),...,(x_N,y_N)$, and take only the marginal samples $(x_1,\dots,x_N)$. Is this correct?