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(u_1,u_2)$, then you could compute the conditional copula
$$c_{u_1}(u_2)=\frac{\partial C(u_1,u_2)}{\partial u_1} \; .$$
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_u^{-1}(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\sim F_X$ and $Y\sim F_Y$, then
$$(F_X^{-1}(u),F_Y^{-1}(c_u^{-1}(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