0
$\begingroup$

I know that if you fit your variables with parametric margins (e.g. beta, gamma) we can easily simulate from copula using the function Mvcd and rMvcd in R.but if you want to work with no parametric margins how can I simulate. I will be thankful for any information or code in R. Edit: as I know if you want to simulate with copulas you need to follow these steps:$\\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~$ 1-Generate i.i.d. uniformly distributed random variables $U=\{u_i,i=1,...,N\}$ $~~~~~~~~~~~~~~~~~~~~~~\\$ 2-set $y_1=u_1$ $~~~~~~~~~~~~~~~~~~~\\$

3-set $u_2=C(y_2,|y_1)=C(y_2|u_1)=\frac{\partial C(y_2,u_1)}{\partial u_1}$ then $y_2=h^{-1}(u_2,y_1,\theta)$ in which the h function is defined as the conditional copula.

4-Continue until we obtain $y_N=h^{-1}(u_N,y_{N-1},\theta)$.

My question is when we do all these steps It should be noted that ${y1; y2; . . . ; yn}simulated from steps 1 to 4 are the time series in the frequency domain (i.e., marginals), and we will need to perform the one-to-one transformation to obtain the corresponding time series simulated in the real domain (e.g., through parametric distribution, empirical distribution, or kernel density based on the observed time series).

I fitted an empirical distribution to a set of time series data (Y) by following code in R: Ye=rank(Y)/(length(Y)+1)

So I need the inverse of this ecdf for transform the simulated data the original domain

$\endgroup$
12
  • $\begingroup$ The copula itself has standard uniform margins. $\endgroup$
    – Glen_b
    May 25 '20 at 14:31
  • $\begingroup$ Thank you, Glen, for your answer but can you explain more please. Because what I mean that if I didn't want to restrictive my choose of margins (by choose them by the parametric way) how can I simulate using the empirical margins and got good result $\endgroup$
    – NAAMA
    May 25 '20 at 22:54
  • 1
    $\begingroup$ You'll need to edit your question to clarify that you want to work with empirical margins. I don't think anyone would be likely to guess that from the present question. I am pretty sure that there are some questions that relate to this (though maybe not any with really satisfying answers). $\endgroup$
    – Glen_b
    May 26 '20 at 0:16
  • $\begingroup$ @Glen_b-ReinstateMonica Thank you for your kind answer. I was edited my question I will be thankful if you have any information to help me $\endgroup$
    – NAAMA
    May 26 '20 at 23:25
  • $\begingroup$ Why not just hit your marginals with the empirical probability integral transform, ecdf(marginal)(marginal)? Then you get rid of the effects of the marginals altogether, whether you fit them with parametric distributions or not. $\endgroup$
    – Dave
    May 27 '20 at 0:00
1
$\begingroup$

Now I see what you want to do. When you get simulated values from your copula, each marginal of course$^{\dagger}$ has values on $[0,1]$. These correspond to the quantiles of your original distribution.

The quantile function in R undoes the empirical probability integral transform.

So you'll simulate some x and y marginals that are of course$^{\dagger}$ on $[0,1]$. Then you'll hit x and y with quantile. Something like...

# define original x and y marginals: 
#
x_orig <- whatever it is
y_orig <- whatever it is

# Empirical probability integral transform
#
ex <- ecdf(x_orig)(x_orig)
ey <- ecdf(y_orig)(y_orig)

# Estimate your copula using ex and ey as the marginals
# Then sample from your copula: get x and y marginals

# Transform x and y back to the domains of x_orig and y_orig
#
x_simulated <- quantile(x_orig, x)
y_simulated <- quantile(y_orig, y)    

$^{\dagger}$Why "of course"?

$\endgroup$
8
  • $\begingroup$ Since Cross Validated isn't for questions about coding, I'd like to use the comments to clarify any confusing points in my post so that I can go back and edit the post. Let's start with you answering my question at the end, however :) $\endgroup$
    – Dave
    May 27 '20 at 0:32
  • $\begingroup$ Thank you so much that's really what I want, but what am not understood that the quantile function "quantile(x, prob=sec()..) " why you use x and y like probability in your code what is normal for me is to right "quantile(x,x_orig)"?! $\endgroup$
    – NAAMA
    May 27 '20 at 1:05
  • $\begingroup$ @NAAMA That’s just the way the function works in R. Other software my work the other way, though R’s order makes sense to me. If you run quantile on some data without specifying any quantiles in the second argument, it gives you the typical quantiles of interest: 0, 0.25, 0.5, 0.75, and 1. $\endgroup$
    – Dave
    May 27 '20 at 1:21
  • $\begingroup$ Thanks a lot @Dave I will try to implement this code to my data and figure out the result.can I ask you again if am I confusing about something after implementation Dave?! $\endgroup$
    – NAAMA
    May 27 '20 at 1:28
  • $\begingroup$ @NAAMA Depending on the question, it may be better for you to post a new question, but please do post implementation questions on Stack Overflow. This question is arguably borderline but perhaps should be on SO. $\endgroup$
    – Dave
    May 27 '20 at 1:31

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.