I have two random variables (say, X and Y). Each of these rv's are defined by their CDFs (CDF_X and CDF_Y). These CDFs were obtained empirically, so they are a "stair" graph. I also have a copula C representing the relation between X and Y. This copula was obtained through a kernel estimator.
I want to sample (say 10 points (X,Y)) from the bivariate distribution of X and Y (that is, respecting the dependence relation imposed by C).
How can I do such implementation in Matlab or in R? I prefer Matlab.
Answer
Suppose you have the copula C(u1,u2), then you could compute the conditional copula
cu1(u2)=∂C(u1,u2)∂u1.
Now, you can generate a pair of independent uniformly distributed random values (U,V). Let's say a particular realistation is (u,v). Then the pair
(u,c−1u(v))
will be distributed according to the copula. You only need to apply the inverse CDF's to get them distributed like (X,Y). Say X∼FX and Y∼FY, then
(F−1X(u),F−1Y(c−1u(v)))
is what you need to do in the end.
An example in Matlab for a Clayton copula
%% Simulations of Clayton copulas using conditional cdf
%Example for theta=4
n=3000;
theta=5;
u=rand(1,n);
y=rand(1,n);
v=((y.^(1/(1+theta)).*u).^(-theta)+1-u.^(-theta)).^(-1/theta);
x1=norminv(u);
x2=norminv(v);
plot(x1,x2,'.')
No comments:
Post a Comment