I have a joint density function for two independent variables X and Y. And I now want to sample new x,y from this distribution.
What I believe I have to do is to find the joint cumulative distribution and then somehow sample from it. I kinda know how to do this in 1D, but I find it really hard to understand how to do it in 2D.
I also used the matlab function cumtrapz
to find the cumulative distribution function for the above pdf.
Just to be clear, what i want to do is to sample random values x,y from this empirical distribution.
Can someone please point me in the right direction here?!
EDIT: I have data values and I use
[pdf bins] = hist3([N Y])
I then normalize the pdf and do
cumulativeDistribution = cumtrapz(pdfNormalize)
And yes (to the comment below) X,Y are suppose to be independent.
If you know how to sample a distribution in 1D then you can extend it to 2D. Create the marginal distribution for X. Take a sample from that, say X1. Then in your 2D distribution fix one variate X=X1 and sample for Y, i.e., sample Y from 1D distribution fXY(X1, Y).
Given a joint distribution in say, two random variable X and Y, you can compute a CDF for X alone by summing over all possible values of Y, i.e. P(X<=x)=Sum[P[X=x_i and Y=y_j],{x_i<=x and all values of y_j}]. Once you have P(X<=x) in hand, there are well-known methods for sampling a value of X, let's call it a. Now that you have a, compute P(Y<=y given X=a)=Sum[P[X=a and Y=y_j],{y_j<=y}]/Sum[P[X=a and Y=y_j],{all values of y_j}]. Sample Y using the same approach that gave you X, yielding Y=b. Done.
The same approach generalizes to more that two random jointly distributed random variable.