# Generating values from copula using copula package in R

I have a bunch of questions concerning the use of the copula package in R. My overall aim is to generate synthetic values using copulas. I am analyzing a hydrological data: annual peak discharge [m³/s] and corresponding volume [m³].

I managed to apply tests on serial independence and dependence. Furthermore I identified and excluded ties and created pseudo-observations (transformation of copula values between [0,1]). Since I don’t know which copula is the best, I fitted the copula parameter first:

fg <- fitCopula(copula=gumbelCopula(), data=u) #  u is my data


I will do this for all available copulas in R. Afterwards I test the goodness of fit with the following function:

gofCopula(copula=gumbelCopula(fg@estimate), x=data[,2:3], N=1000, method="Sn",
estim.method="mpl", simulation="mult")


Using the “best” copula, I then want to create synthetic values. I found a function to create random samples, but I am not sure, if it does what I need.

random_samples <- rCopula(copula=gumbelCopula(fg@estimate), n=10000)


It seems to me that this function creates only random values, but is the dependency structure of my data set considered? There is also another function in the copula package mvdc, for the construction of multivariate distributions from copulas. What is actually the difference of mvdc and rCopula, both are generating synthetic values, aren’t they?

One last question is: Once I am able to generate my synthetic values, how can I transform them back to their real units? From reading through the documentation I understood tat I have to multiply the values for (u,v) with the inverse of their particular cdf, is this true?

One question is not answered yet, I want to render it more precisely: namely the function . According to the copula manual p. 107, it is used to "construct multivariate distributions from copulas"

For the function a copula family, as well as the distributions of the margins have to be specified, for instance:

mv.NE <- mvdc(copula=gumbelCopula(fg@estimate),margins=c("norm","norm"),paramMargins=list(list(mean=0, sd = 1),list(mean=0, sd = 1)))

(here is chose a gumbelCopula and estimated the parameter with . I assume that my marginals are both distributed "normal".)

What for do I need this function? I am slightly confused because of:

• when I create random values from my copula using I eventually yield "distributed" values when I pass the values of u and v respectively over to their particular distribution function (in this case both are distributed normal)
• so why is there a second option to create multivariate distributions from a copula.

I just don't get the difference...

• Correct, after you sample from the copula, you transform the margins individually, in the way you suggest. Mar 20 '14 at 23:42
• Yes, the random samples that are generated are not independent; they contain the dependence structure that results from the copula (and parameter estimate(s)) you supply. You can see they're dependent simply by plotting the result. Mar 20 '14 at 23:59
• Just to be clear, you do not have to multiply the values of (u,v) with their inverse marignal CDFs, but you have to pass the values (u,v) to their inverse marginal CDFs.
– Ben
Mar 21 '14 at 10:35

Thanks for your answers. Indeed, when I plot the different Copulas, it seems (based on a visual comparison) that the dependence struture is depicted in the copula.

Then my next step will be to compare the different copula families in terms of looking at their goodness of fit.

@Ben: Ok, so if the distribution of one of my marginals is the generalized extreme value distribution, my u or v will be passed to the "x" of this function, since the other parameters of this distribution are fitted before.

• You might want to interactively explore different bivariate copula families that are available in R with the shiny app copulatheque.
– Ben
Mar 21 '14 at 10:40
• You need to use the inverse cumulative distribution function (CDF) also known as quantile function and commonly abbreviated in R as "q" (e.q. qnorm, qgev, ...). This should be clear from Sklar's Theorem. Please pay careful attention to the theory of copulas, as it is very easy to mess around with them.
– Ben
Mar 24 '14 at 9:48
• Hi Ben, sorry for the delay. Thanks for that hint! I am very glad that the GEV is already coded in R. Telling from the destribution functions on link I thought it wasn't. I will use this one. Mar 26 '14 at 12:15
• You will need an extra package: "evd"
– Ben
Mar 27 '14 at 9:26
• @Ben thanks for linking to that app! It's incredibly helpful to visualize the copulas this way! Aug 4 '15 at 17:12