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.

  • $\begingroup$ You need to derive a conditional copula, which you can find by taking the derivative of your copula to one of the variables. This will allow you to first sample a uniform random value, and then conditional on that one, a second uniform one from the conditional copula. Then you transform them with the inverse CDF's so that they have the appropriate marginal distributions. $\endgroup$ Feb 9, 2018 at 19:30

1 Answer 1


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


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


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


  • $\begingroup$ thank you very much. This will surely help. But ideally I need a matlab implementation... $\endgroup$
    – Pierre
    Feb 10, 2018 at 16:56
  • $\begingroup$ Maybe you should give the format of your data then. Can you update your question and add the Matlab code you already have, as well as the structure of your data? I added an example for a Clayton copula and standard normal marginal cdfs. $\endgroup$ Feb 10, 2018 at 17:14
  • $\begingroup$ If your copula results from a kernel estimator, then presumably the kernel is some known smooth function and computing the partial derivatives should not be hard. Then the conditional copula will just be a linear combination involving the partial derivatives of the kernel. $\endgroup$ Feb 10, 2018 at 17:28
  • $\begingroup$ thank you. But Matlab does not give the analytical formula when I use the ksdensity function (it gives the values of the kernel function at a finite number of points). Is there a way to get the analytical formula of the kernel in matlab, so that I can compute its derivative? $\endgroup$
    – Pierre
    Feb 15, 2018 at 17:22
  • $\begingroup$ Have you looked in the documentation of the function? $\endgroup$ Feb 15, 2018 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.