Sampling a Bivariate Distribution from a Copula and Empirical Marginals
Summary
The document describes how to generate paired observations with specified marginal distributions and dependence structure. Given a bivariate copula, it forms a conditional distribution by differentiating the copula with respect to its first argument. Independent uniform draws provide inputs: keep the first uniform variate and transform the second through the inverse conditional distribution. Applying the inverse marginal CDFs then maps the resulting uniform pair into observations on the original variables’ scales.
A MATLAB illustration uses a Clayton copula and normal inverse CDFs to plot simulated pairs. The procedure expresses the inverse transform method for copula sampling, while the question’s empirical marginal CDFs would require suitable generalized inverses, especially where the stepwise CDF has flat sections or jumps. The example is specific to a parametric copula and does not explain numerical differentiation or inversion for a kernel-estimated copula. Those implementation details can affect whether the simulated samples faithfully reproduce the intended dependence.
Key ideas
- A copula separates dependence modeling from the marginal distributions.
- A conditional copula CDF can transform independent uniform draws into dependent uniform variates.
- Inverse marginal CDFs map the dependent uniform samples onto the variables’ scales.
- Empirical step CDFs and kernel-estimated copulas may require careful numerical inversion.
Tags
Full text
# How to sample from a copula in matlab
# How to sample from a copula in matlab
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 by Raskolnikov (score 3, accepted)
https://quant.stackexchange.com/a/38164
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,'.')
```Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.