Solved – How to generate data from an empirical copula using Copula package in R

copularsimulation

So I have got a data set with 3 variables. Using the function C.n(u,pobs(data)), where u is a matrix containing uniform distributed random variables of dimension 3 and the same length as the data set.

However, C.n returns a list of numbers in [0,1] of only one dimension. How can I use this list to generate new data, in three dimensions?

Best Answer

Looking at the copula package's documentation, there doesn't seem to be a way to generate samples from empirical copulas. The R function that is used typically for this purpose is rCopula(), which requires a copula object datatype.

The following paper describes how to generate random samples from empirical copulas: http://www.informs-sim.org/wsc07papers/058.pdf, and this in-fact requires the empirical copula density.

If you want to stick w/ R, then I suppose you have two options:

  1. Create an empirical copula object and follow the API that the copula package requires.
  2. Implement this method described in the linked paper above, and use the built-in functionality of R to generate empirical copula densities.

If you are open to using other software packages, I have written some tools in Matlab to do this (they might work in Octave also, but I haven't tested that functionality). All the code lives in this toolbox here: Copula Matlab Toolbox

Specifically, the function you will need to call to generate random pseudo-observations from an empirical copula is empcopularnd. This function implements the method described in the paper above, and requires an empirical copula density as it's input. To generate empirical copula densities, you can use the function empcopulapdf. An example of how to put all of this together (generate empirical density and draw pseudo-samples from the density) is in the test-script test_empcopularnd.

The functions written above should work for any dimensionality, but obviously as your data grows in dimensionality the code will be slower. To speed it up, you may consider compiling the mex file empcopulapdf_c. If you do end up using this code, please PM me if you have any questions!