The (frozen) parameters considered are as follows.
## Parametersd.<-c(2,3)# copula sector dimensionsd<-sum(d.)# copula dimensionstopifnot(d>=3)# for 3d plotsn<-777# sample size (was 1000; save space for *.html)We also implement an auxiliary function to generate the hierarchicalfrailties involved.
##' @title Generated two hierarchical frailties (V0, V01, V02)##' @param n sample size##' @param family copula family##' @param tau Kendall's tau##' @return 3-column matrix containing the hierarchical frailties##' @author Marius Hofert and Avinash PrasadrV012<-function(n, family, tau){stopifnot(n>=1,is.character(family),length(tau)==3, tau>0) cop<-getAcop(family)# corresponding AC th<-iTau(cop,tau = tau)# copula parameters V0<- cop@V0(n,theta = th[1])# sample frailties V_0 V01<- cop@V01(V0,theta0 = th[1],theta1 = th[2])# sample frailties V_01 V02<- cop@V01(V0,theta0 = th[1],theta1 = th[3])# sample frailties V_02cbind(V0 = V0,V01 = V01,V02 = V02)}And a short helper function for plotting (possibly to PDF).
In this example, we compare Archimedean copulas (ACs), Archimaxcopulas (AXCs), nested Archimedean copulas (NACs) and hierarchicalArchimax copulas (HAXCs) with hierarchical frailties only, withhierarchical frailties and hierarchical extreme-value copula (HEVC) butboth of the same hierarchical structure, and with hierarchical frailtiesand HEVC but of different hierarchical structure.
To begin with, we sample from a standard Clayton copula.
## Sample frailties (to recycle the frailties, we apply the Marshall--Olkin (MO)## algorithm manually here)tau<-0.4# Kendall's taufamily<-"Clayton"# frailty familycop<-getAcop(family)# corresponding ACth<-iTau(cop,tau = tau)# copula parameterset.seed(271)# for reproducibilityV<- cop@V0(n,theta = th)# sample frailtyE<-matrix(rexp(n* d),ncol = d)# sample Exp(1)U.AC<- cop@psi(E/V,theta = th)# MO## Plotmypairs(U.AC)Now we sample from an Archimax copula with gamma frailties (asunderlying the Clayton family; we recycle the frailties from 1.1) andGumbel EVC (parameters chosen such that Kendall’s tau equals 0.5).
## Generate Gumbel EVC sample with Exp(1) marginstau.EVC<-0.5# Kendall's taufamily.EVC<-"Gumbel"# EVC familyth.EVC<-iTau(getAcop(family.EVC),tau = tau.EVC)# EVC parametercop.EVC<-onacopulaL(family.EVC,list(th.EVC,1:d))# EVCset.seed(271)# for reproducibilityU.EVC<-rCopula(n,copula = cop.EVC)# sample EVCE.EVC<--log(U.EVC)# map the EVC to Exp(1) margins## Combine with the (same) Clayton frailties (as before)U.AXC<- cop@psi(E.EVC/V,theta = th)## Plotmypairs(U.AXC)Sampling from a NAC based on Clayton’s family with parameters suchthat Kendall’s tau equals 0.2 between the two sectors, 0.4 within thefirst sector and 0.6 within the second sector, can be done asfollows.
## Generate hierarchical frailtiestau.N<-c(0.2,0.4,0.6)# Kendall's tausfamily.N<-"Clayton"# frailty familycop.N<-getAcop(family.N)# corresponding ACth.N<-iTau(cop.N,tau = tau.N)# copula parametersset.seed(271)# for reproducibilityV.N<-rV012(n,family = family.N,tau = tau.N)# generate corresponding frailtiesV0<- V.N[,"V0"]V01<- V.N[,"V01"]V02<- V.N[,"V02"]## Combine with independent Exp(1)U.NAC<-cbind(cop.N@psi(E[,1:d.[1]]/V01,theta = th.N[2]), cop.N@psi(E[,(d.[1]+1):d]/V02,theta = th.N[3]))## Plotmypairs(U.NAC)Sampling from a NAXC based on hierarchical Clayton frailties(recycled from 1.3) and Gumbel EVC (realizations recycled from 1.2).Note that hierarchies only take place at the levels of the frailties inthis case.
## Generate samplesU.HAXC<-cbind(cop.N@psi(E.EVC[,1:d.[1]]/V01,theta = th.N[2]), cop.N@psi(E.EVC[,(d.[1]+1):d]/V02,theta = th.N[3]))## Plotmypairs(U.HAXC)After this warm-up, we can consider sampling from a HAXC based onhierarchical Clayton frailties (recycled from 1.3) and a hierarchicalGumbel EVC (with sector sizes 2 and 3 and parameters such that Kendall’stau equals 0.2 between the two sectors, 0.5 within the first sector and0.7 within the second sector). Note that there are two types ofhierarchies involved, at the level of the (hierarchical) frailties andat the level of the (hierarchical) EVC. Furthermore, their hierarchicalstructure is the same.
## Sampling from a hierarchical Gumbel copulatau.HEVC<-c(0.2,0.5,0.7)# Kendall's tausfamily.HEVC<-"Gumbel"# EVC familycop.HEVC<-getAcop(family.HEVC)# corresponding base EVCth.HEVC<-iTau(cop.HEVC,tau = tau.HEVC)# copula parameterscop.HEVC<-onacopulaL(family.HEVC,list(th.HEVC[1],NULL,list(list(th.HEVC[2],1:d.[1]),list(th.HEVC[3], (d.[1]+1):d))))# hierarchical EVCset.seed(271)# for reproducibilityU.HEVC<-rCopula(n,copula = cop.HEVC)# sample the HEVCE.HEVC<--log(U.HEVC)# map the HEVC samples to Exp(1) margins## Combine the hierarchical Gumbel EVC with Exp(1) margins with the hierarchical frailtiesU.HAXC.HEVC.same<-cbind(cop.N@psi(E.HEVC[,1:d.[1]]/V01,theta = th.N[2]), cop.N@psi(E.HEVC[,(d.[1]+1):d]/V02,theta = th.N[3]))## Plotmypairs(U.HAXC.HEVC.same)Sampling from a HAXC (recycling realizations from 1.5) for which thehierarchical structures of the hierarchical frailties (sector sizes 3and 2, respectively) and of the hierarchical Gumbel EVC (sector sizes 2and 3, respectively) differ.
## Combine the hierarchical Gumbel EVC with Exp(1) margins with the hierarchical frailties## in an 'asymmetric' way (hierarchical structures of the HEVC and the hierarchical frailties differ)d..<-rev(d.)# 3, 2U.HAXC.HEVC.dffr<-cbind(cop.N@psi(E.HEVC[,1:d..[1]]/V01,theta = th.N[2]),# first three components get V01 cop.N@psi(E.HEVC[,(d..[1]+1):d]/V02,theta = th.N[3]))# last two components get V02## Plotmypairs(U.HAXC.HEVC.dffr)Again in terms of an example, we now compare extreme-value copulas(EVCs), hierarchical extreme-value copulas (HEVCs) and hierarchicalArchimax copulas (HAXCs) with single frailty and HEVC, with hierarchicalfrailties and EVC, with hierarchical frailties and HEVC but both of thesame hierarchical structure, and with hierarchical frailties and HEVCbut of different hierarchical structure.
To begin with, we draw\(n\) samplesfrom an extremalt copula with\(\nu=3.5\) degrees of freedom andoff-diagonal entry of the correlation matrix parameter\(P\) to be 0.7.
## Correlation matrix (parameter matrix of the extremal t)P<-matrix(0.7,ncol = d,nrow = d)diag(P)<-1## Extremal t copula (EVC)nu<-3.5set.seed(271)U.EVC<-exp(-1/rmev(n,d = d,param = nu,sigma = P,model ="xstud"))# apply unit Frechet margins to get U## Plotmypairs(U.EVC)Now, we sample from an hierarchical extremalt copula withtwo sectors of sizes 2 and 3 such that the correlation matrix\(P\) has entries 0.2 for pairs belonging todifferent sectors, 0.5 for pairs belonging to the first sector and 0.7for pairs belonging to the second sector.
## Construct a hierarchical correlation matrix for the extremal tP.h<-matrix(0.2,ncol = d,nrow = d)P.h[1:d.[1],1:d.[1]]<-0.5P.h[(d-d.[2]+1):d, (d-d.[2]+1):d]<-0.7diag(P.h)<-1## Hierarchical extremal t copula (HEVC)X.et<-rmev(n,d = d,param = nu,sigma = P.h,model ="xstud")U.HEVC<-exp(-1/X.et)# apply unit Frechet margins to get U## Plotmypairs(U.HEVC)Sampling from a HAXC with Clayton frailty (recycled from 1.1) andhierarchical extremalt copula (on top of the unitexponentials; recycled from 2.2) can be done as follows.
## Construct samplesE.HEVC<--log(U.HEVC)# map to Exp(1) marginsU.AXC.HEVC<- cop@psi(E.HEVC/V,theta = th)## Plotmypairs(U.AXC.HEVC)Consider a HAXC with hierarchical Clayton frailties (recycled from1.3) and extremalt EVC (on top of the unit exponentials;recycled from 2.1).
## Construct samplesE.EVC<--log(U.EVC)U.HAXC.EVC<-cbind(cop.N@psi(E.EVC[,1:d.[1]]/V01,theta = th.N[2]), cop.N@psi(E.EVC[,(d.[1]+1):d]/V02,theta = th.N[3]))## Plotmypairs(U.HAXC.EVC)Now consider a HAXC with hierarchical Clayton frailties (recycledfrom 1.3) and hierarchical extremalt EVC (on top of the unitexponentials; recycled from 2.2 and 2.3). Note that there are two typesof hierarchies involved, at the level of the (hierarchical) frailtiesand at the level of the (hierarchical) EVC.
## Construct samplesU.NAXC.HEVC.same<-cbind(cop.N@psi(E.HEVC[,1:d.[1]]/V01,theta = th.N[2]), cop.N@psi(E.HEVC[,(d.[1]+1):d]/V02,theta = th.N[3]))## Plotmypairs(U.HAXC.HEVC.same)Sampling from a HAXC (recycling realizations from 2.5) for which thehierarchical structures of the frailties (sector sizes 3 and 2,respectively) and of the HEVC (sector sizes 2 and 3, respectively)differ in this case.
## Construct samplesU.NAXC.HEVC.dffr<-cbind(cop.N@psi(E.HEVC[,1:d..[1]]/V01,theta = th.N[2]),# first three components get V01 cop.N@psi(E.HEVC[,(d..[1]+1):d]/V02,theta = th.N[3]))# last two components get V02## Plotmypairs(U.HAXC.HEVC.dffr)