2
$\begingroup$

I'm new to R. My goal is to calculate and plot the probability density function of the sum of 3 correlated empirical random variables (X1+X2+X3), given the correlation matrix. I want to aggregate the 3 empirical distributions via a gaussian copula method:

> library(copula)
> set.seed(6)
> myCop <- ellipCopula(family = "normal", dim = 3, dispstr = "un",param = c(0.25, 0.50, 0.15))
> getSigma(myCop)
     [,1] [,2] [,3]
[1,] 1.00 0.25 0.50
[2,] 0.25 1.00 0.15
[3,] 0.50 0.15 1.00
> myCop
Normal copula family 
Dimension:  3 
Parameters:
   rho.1  =  0.25 
   rho.2  =  0.5 
   rho.3  =  0.15 

Each empirical distribution is given by:

h<-400
n1<-2000
set.seed(6)
n<-200000
X1 <- rep(0,n)
N <- rnbinom(n,h,h/(h+n1)) 
for (i in 1:n) {
  Z <- rlnorm(N[i],mu.z,sigma.z)
  X1[i]=sum(Z)}

And look like:

enter image description here

Using the "mvdc" package i have to code the following:

mvdc(copula=myCop, margins=, paramMargins=)

I can't figure out how to use empirical distributions as "margins".

"The characters in argument margins are used to construct density, distribution, and quantile func- tion names. For example, norm can be used to specify marginal distribution, because dnorm, pnorm, and qnorm are all available. A user-defined distribution, for example, fancy, can be used as margin provided that dfancy, pfancy, and qfancy are available."

How can i build my "fancy" user-defined distribution? Is that the only way to accomplish my goal?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.