pcompound <-
function(q, dist="exp", comp1=as.null(), comp2=as.null(), gamma=1, beta=1, theta1=1, theta2=1,lower.tail = TRUE,log.p=FALSE)
{
if(!any(dist == c("exp","gamma","lnorm","paretoII","bisa","lomax","beta","kumar","norm","logis","cauchy","gumbel"))) stop("distribution is not recognized")
if(!any(comp1 == c("EXP","EXP2","MO","MO2","SB")) & !is.null(comp1)) stop("distribution is not recognized")
if(!any(comp2 == c("EXP","EXP2","MO","MO2","SB")) & !is.null(comp2)) stop("distribution is not recognized")
if (beta<=0) stop("beta should be positive")
if(any(dist==c("gamma","paretoII","bisa","lomax","beta","kumar")) & gamma<=0) stop("gamma should be positive")
if(any(comp1 == c("EXP","EXP2","MO","MO2")) & theta1<=0) stop("theta1 should be positive")
if(any(comp2 == c("EXP","EXP2","MO","MO2")) & theta2<=0) stop("theta2 should be positive")
if(!is.null(comp1)){if(comp1=="SB" & (theta1< -1 | theta1> 1)) stop("theta1 should be between -1 and 1")}
if(!is.null(comp2)){if(comp2=="SB" & (theta2< -1 | theta2> 1)) stop("theta2 should be between -1 and 1")}
F=get(paste("p",dist,sep=""))
if(!is.null(comp2)){G2=get(paste("p",comp2,sep=""))}
if(!is.null(comp1)){G1=get(paste("p",comp1,sep=""))}
if(dist=="exp")
{
if(!is.null(comp2)) logF=G2(G1(F(q, gamma),theta1),theta2,log.p=TRUE)
if(is.null(comp2) & !is.null(comp1)) logF=G1(F(q, gamma),theta1,log.p=TRUE)
if(is.null(comp2) & is.null(comp1)) logF=F(q, gamma,log.p=TRUE)
}
if(dist!="exp")
{
if(!is.null(comp2)) logF=G2(G1(F(q, gamma, beta),theta1),theta2,log.p=TRUE)
if(is.null(comp2) & !is.null(comp1)) logF=G1(F(q, gamma, beta),theta1,log.p=TRUE)
if(is.null(comp2) & is.null(comp1)) logF=F(q, gamma, beta,log.p=TRUE)
}
if(log.p == FALSE) Fy <- exp(Fy)
if(lower.tail==FALSE) Fy<-1-Fy
Fy
}
