how to simulate from joint distribution by conditioning

1.3k Views Asked by At

I have a simple question about simulation from joint distribution. Suppose $(X,Y)$ has a joint distribution $p(x,y)$, and we know the marginal of $Y$, $p(y)$, and the conditional distribution of $X$ given $Y$, $p(x|y)$. If we want to sample from $p(x,y)$ in any software, say, Matlab or R, is it true that we can just first sample a $y$ from $p(y)$ and then given this $y$ sampled, sample $x$ from conditional distribution $p(x|Y=y)$?

1

There are 1 best solutions below

2
On

Yes. By the definition of conditional distributions $p(x,y)=p(y)p(x|y)$. The two step procedure you describe first returns $Y=y$ with probability $p(y)$ and then $X=x$ with probability $p(x|y)$, and so it is returning the pair $(x,y)$ with exactly the probability of $p(x,y)$. This will be true independent of the software used.