Reputation: 8940
I am trying to simulate data from a normal Copula using R's copula
package, more precisely using normalCopula
and then mvdc
. I note that the function normalCopula
wants the correlation matrix R, not the covariance S. Looking at the output, I note that while the cor
of the sample is close to the population R, the cov
of the simulated data is not close to my population S, even when rescaling by the S' variances?
So: what is the covariance of the output of mvdc(copula=normalCopula(param=P2p(cov2cor(SIG)),...)
, if it is neither R nor (rescaled) S? I suspect the output covariance is a mix of the input correlation R and the marginal variances/moments? How should I rescale my data so that it has covariance S?
library(copula)
S <- matrix(c(0.5, 0.8, 0.7, 0.8, 2, 0.2, 0.7, 0.2, 8), 3,3)
R <- cov2cor(S)
## Simulate data with cpula package
myCop <- normalCopula(param=P2p(R), dim = 3, dispstr = "un")
myMvd <- mvdc(copula=myCop, margins="gamma",
marginsIdentical=TRUE,
paramMargins=list(list(shape=2, scale=1)))
X_copula <- rMvdc(5000000, myMvd)
## check resulting cov?
cor(X_copula);R # yes, they seem to be close
#> [,1] [,2] [,3]
#> [1,] 1.0000000 0.78346901 0.32660893
#> [2,] 0.7834690 1.00000000 0.04496475
#> [3,] 0.3266089 0.04496475 1.00000000
#> [,1] [,2] [,3]
#> [1,] 1.00 0.80 0.35
#> [2,] 0.80 1.00 0.05
#> [3,] 0.35 0.05 1.00
X_copula_rescale <- X_copula%*% diag(sqrt(diag(S))) # rescale by vaariance
cov(X_copula_rescale);S # far!?
#> [,1] [,2] [,3]
#> [1,] 0.999889 1.5666511 1.3075266
#> [2,] 1.566651 3.9989791 0.3599924
#> [3,] 1.307527 0.3599924 16.0285098
#> [,1] [,2] [,3]
#> [1,] 0.5 0.8 0.7
#> [2,] 0.8 2.0 0.2
#> [3,] 0.7 0.2 8.0
cov(X_copula_rescale)/2;S
#> [,1] [,2] [,3]
#> [1,] 0.4999445 0.7833255 0.6537633
#> [2,] 0.7833255 1.9994895 0.1799962
#> [3,] 0.6537633 0.1799962 8.0142549
#> [,1] [,2] [,3]
#> [1,] 0.5 0.8 0.7
#> [2,] 0.8 2.0 0.2
#> [3,] 0.7 0.2 8.0
Created on 2023-03-13 with reprex v2.0.2
Upvotes: 2
Views: 495