Learn R Programming

VineCopula (version 1.4)

RVineCor2pcor: (Partial) Correlations for R-Vine Copula Models

Description

Correlations to partial correlations and vice versa for R-vines (C vine, D vine or general R vine) .

Usage

RVineCor2pcor(RVM, corMat)
RVinePcor2cor(RVM)

Arguments

RVM
RVineMatrix defining only the R-vine structure for cor2pcor and providing as well the partial correlations for pcor2cor.
corMat
correlation matrix

Value

  • RVMRVineMatrix with transformed partial correlations
  • corcorrelation matrix

Examples

Run this code
corMat <- matrix(c(1.00, 0.17, 0.15, 0.14, 0.13,
                   0.17, 1.00, 0.30, 0.28, 0.05,
                   0.15, 0.30, 1.00, 0.17, 0.05,
                   0.14, 0.28, 0.17, 1.00, 0.04,
                   0.13, 0.05, 0.05, 0.04, 1.00), 5, 5)

Matrix <- matrix(c(5, 2, 3, 1, 4,
                   0, 2, 3, 4, 1,
                   0, 0, 3, 4, 1,
                   0, 0, 0, 4, 1,
                   0, 0, 0, 0, 1), 5, 5)
family <- matrix(1, 5, 5)

par <- matrix(c(0, 0.2, 0.9, 0.5, 0.8,
                0,   0, 0.1, 0.6, 0.9,
                0,   0,   0, 0.7, 0.5,
                0,   0,   0,   0, 0.8,
                0,   0,   0,   0,   0), 5, 5)

# define RVineMatrix object
RVM <- RVineMatrix(Matrix, family, par)

# adjust the un-ordered RVine
newRVM <- RVineCor2pcor(RVM, corMat)
round(cor(qnorm(RVineSim(1000, newRVM)))-corMat, 2)

# normalise the RVine
normRVM <- RVineMatrixNormalize(RVM)

# adjust the normalised RVine
newNormRVM <- RVineCor2pcor(normRVM, corMat)

# newRVM and newNormRVM are the same vines using different names
newNormRVM$par - newRVM$par

# the variables have a different order in the correlation matrix
newNormCor <- cor(qnorm(RVineSim(1000, newNormRVM)))
round(newNormCor,2)

# permuted, they meet the initial correlation matrix up to +/- 0.01
perm <- c(1,4,3,2,5)
round(newNormCor[perm,perm]-corMat, 2)

# re-order names of the normalised RVine generating a new RVine
normRVM2 <- normRVM
normRVM2$names <- c("V1", "V2", "V3", "V4", "V5")

# adjust the normalised RVine
newNormRVM2 <- RVineCor2pcor(normRVM2, corMat)
# check whether the parameters are different beyond permutation
# (that's why permutation does not work)
newNormRVM2$par
newRVM$par

# adjust the normalised RVine
newNormRVM2 <- RVineCor2pcor(normRVM2, corMat[perm,perm])
# check whether the parameters are now identical
round(newNormRVM2$par - newRVM$par, 2)

# back and forth
RVinePcor2cor(RVineCor2pcor(RVM, corMat))-corMat
RVinePcor2cor(RVineCor2pcor(normRVM, corMat))-corMat
RVinePcor2cor(RVineCor2pcor(normRVM2, corMat))-corMat

Run the code above in your browser using DataLab