rmixture

How to construct mixture copula in R


I want to study mixture Copula for reliability analysis.however I can't construct RVINEMatrix , Therefore, the probability integral transformation (PIT) cannot be performed、 The copula used in H-equation to convert related variables into independent variables cannot be filled with mixed copulas。 Here is my code:

    copula1 <- mixCopula(list(claytonCopula(param = 1.75,dim = 2),
                          frankCopula(param = 0.718,dim = 2),
                          gumbelCopula(param = 1.58,dim = 2)),w=c(0.4492,0.3383,0.2125))
    copula2 <- mixCopula(list(frankCopula(param = 0.69,dim = 2),
                          gumbelCopula(param = 1.48,dim = 2),
                          claytonCopula(param = 1.9,dim = 2)),w=c(0.3784,0.3093,0.3123))
    copula3 <- mixCopula(list(frankCopula(param = 7.01,dim = 2),
                          claytonCopula(param = 0.75,dim = 2),
                          gumbelCopula(param = 1.7,dim = 2)),w=c(0.4314,0.2611,0.3075))
    copula4 <- mixCopula(list(gumbelCopula(param = 1.21,dim = 2),
                          claytonCopula(param = 0.89,dim = 2),
                          frankCopula(param = 3.62,dim = 2)),w=c(0.3306,0.2618,0.4076))
     .......
    Matrix <- c (5, 4, 3, 2, 1,
            0, 4, 3, 2, 1,
            0, 0, 3, 2, 1,
            0, 0, 0, 2, 1,
            0, 0, 0, 0, 1)
    Matrix <- matrix(Matrix, 5, 5)

    family1 <- c(0,copula10,copula9,copula7, copula4,
                0, 0,  copula8,copula6,  copula3,
                0, 0, 0,  copula5, copula2,
                0, 0, 0, 0,  copula1,
                0, 0, 0, 0, 0)
    family1 <- matrix(family1, 5, 5)


    par <- c(0,  0.2, 0.5,0.32, 0.50,``
         0, 0, 0.5, 0.98, 0.5,
         0, 0, 0,  0.9 , 0.5,
         0, 0, 0, 0, 0.39,
         0, 0, 0, 0, 0)
    par <- matrix(par, 5,  5)

    par2 <- c(0, 0, 0, 0, 0,
              0, 0, 0, 0, 0,
              0, 0, 0, 0, 0,
              0, 0, 0, 0, 0,
               0, 0, 0, 0, 0)
    par2 <- matrix(par2, 5, 5)
     RVM <- RVineMatrix(Matrix = Matrix, family = family1,
                   par = par, par2 = par2,
                   names = c("V1", "V2", "V3", "V4", "V5"),check.pars = TRUE)

so could you help me to construct the rvinematrix ? or Achieve this by other means. thanks!


Solution

  • There are some points you should be aware of:

    1. You use the mixcopula from the copula package. That will provide you with a mixture model with a copula, not a mixture of R-vine copula.
    2. Then you try to fit the copula generated from the mixture of copula into the Rvine copula model. This will not work because the index for copula functions in the R-vine copula is different from the one in the copula package. So, Rvine matrix accepts only a number, where each number corresponds to a specific type of copula.

    So, to build a mixture of the R-vine copula model, you should build a mixture of R-vine densities. There exist a clustering GitHub package, called vineclust. It is designed for vine copula clustering models. By the way, for the mixture of Rvine copula, you need (for two components), two matrices of families, parameters, and Matrix.

    An example of vine mixture from vineclust is:

    dims <- 3
    obs <- c(500,500) 
    RVMs <- list()
    RVMs[[1]] <- VineCopula::RVineMatrix(Matrix=matrix(c(1,3,2,0,3,2,0,0,2),dims,dims),
                            family=matrix(c(0,3,4,0,0,14,0,0,0),dims,dims),
                            par=matrix(c(0,0.8571429,2.5,0,0,5,0,0,0),dims,dims),
                            par2=matrix(sample(0, dims*dims, replace=TRUE),dims,dims)) 
    RVMs[[2]] <- VineCopula::RVineMatrix(Matrix=matrix(c(1,3,2,0,3,2,0,0,2), dims,dims),
                            family=matrix(c(0,6,5,0,0,13,0,0,0), dims,dims),
                            par=matrix(c(0,1.443813,11.43621,0,0,2,0,0,0),dims,dims),
                            par2=matrix(sample(0, dims*dims, replace=TRUE),dims,dims))
    margin <- matrix(c('Normal', 'Gamma', 'Lognormal', 'Lognormal', 'Normal', 'Gamma'), 3, 2) 
    margin_pars <- array(0, dim=c(2, 3, 2))
    margin_pars[,1,1] <- c(1, 2)
    margin_pars[,1,2] <- c(1.5, 0.4)
    margin_pars[,2,1] <- c(1, 0.2)
    margin_pars[,2,2] <- c(18, 5)
    margin_pars[,3,1] <- c(0.8, 0.8)
    margin_pars[,3,2] <- c(1, 0.2)
    x_data <- rvcmm(dims, obs, margin, margin_pars, RVMs)