.packageName <- "mlCopulaSelection"
"clibmodel" <-
function (param, x, y, model = c("CBB1", "CBB2", "CBB3", "CBB4", 
    "CBB5", "CBB6", "CBB7", "CBB8", "CBB9", "CBB10", "CMM1", 
    "CMM2", "CMM3", "CMM4", "CMM5", "CMM6", "CMM7", "CMM8", "CMM9", 
    "CMM10", "CBM1", "CBM2", "CBM3", "CBM4", "CBM5", "CBM6", 
    "CBM7", "CBM8", "CBM9", "CBM10", "CMB1", "CMB2", "CMB3", 
    "CMB4", "CMB5", "CMB6", "CMB7", "CMB8", "CMB9", "CMB10")) 
{
    model <- match.arg(model)
    switch(model, CBB1 = llbb1(param, x, y), CBB2 = llbb2(param, 
        x, y), CBB3 = llbb3(param, x, y), CBB4 = llbb4(param, 
        x, y), CBB5 = llbb5(param, x, y), CBB6 = llbb6(param, 
        x, y), CBB7 = llbb7(param, x, y), CBB8 = llbb8(param, 
        x, y), CBB9 = llbb9(param, x, y), CBB10 = llbb10(param, 
        x, y), CMM1 = llbb1(param, 1 - x, 1 - y), CMM2 = llbb2(param, 
        1 - x, 1 - y), CMM3 = llbb3(param, 1 - x, 1 - y), CMM4 = llbb4(param, 
        1 - x, 1 - y), CMM5 = llbb5(param, 1 - x, 1 - y), CMM6 = llbb6(param, 
        1 - x, 1 - y), CMM7 = llbb7(param, 1 - x, 1 - y), CMM8 = llbb8(param, 
        1 - x, 1 - y), CMM9 = llbb9(param, 1 - x, 1 - y), CMM10 = llbb10(param, 
        1 - x, 1 - y), CBM1 = llbb1(param, x, 1 - y), CBM2 = llbb2(param, 
        x, 1 - y), CBM3 = llbb3(param, x, 1 - y), CBM4 = llbb4(param, 
        x, 1 - y), CBM5 = llbb5(param, x, 1 - y), CBM6 = llbb6(param, 
        x, 1 - y), CBM7 = llbb7(param, x, 1 - y), CBM8 = llbb8(param, 
        x, 1 - y), CBM9 = llbb9(param, x, 1 - y), CBM10 = llbb10(param, 
        x, 1 - y), CMB1 = llbb1(param, 1 - x, y), CMB2 = llbb2(param, 
        1 - x, y), CMB3 = llbb3(param, 1 - x, y), CMB4 = llbb4(param, 
        1 - x, y), CMB5 = llbb5(param, 1 - x, y), CMB6 = llbb6(param, 
        1 - x, y), CMB7 = llbb7(param, 1 - x, y), CMB8 = llbb8(param, 
        1 - x, y), CMB9 = llbb9(param, 1 - x, y), CMB10 = llbb10(param, 
        1 - x, y))
}
"dcbb1" <-
function (theta, delta, u, v) 
{
    S <- u^(-theta) - 1
    T <- v^(-theta) - 1
    -10^(4)
    W <- S^(delta) + T^(delta)
    DuS <- (-theta) * u^(-theta - 1)
    DuW <- delta * S^(delta - 1) * DuS
    DvT <- (-theta) * v^(-theta - 1)
    DvW <- delta * T^(delta - 1) * DvT
    densi <- (-1/(theta * delta)) * (-1/theta - 1) * (1 + W^(1/delta))^(-1/theta - 
        2) * (1/delta) * W^(1/delta - 1) * DvW * W^(1/delta - 
        1) * DuW - (1/(theta * delta)) * (1 + W^(1/delta))^(-1/theta - 
        1) * (1/delta - 1) * W^(1/delta - 2) * DvW * DuW
}
"dcbb10" <-
function (theta, delta, u, v) 
{
    S <- 1 - u^(1/delta)
    T <- 1 - v^(1/delta)
    W <- theta * S * T
    C <- u * v * (1 - W)^(-delta)
    DuS <- (-1/delta) * u^(1/delta - 1)
    DuW <- theta * T * DuS
    DvT <- (-1/delta) * v^(1/delta - 1)
    DvW <- theta * S * DvT
    DvuW <- theta * DuS * DvT
    densi <- (1 - W)^(-delta) + v * (-delta) * (1 - W)^(-delta - 
        1) * (-1) * DvW + u * delta * (1 - W)^(-delta - 1) * 
        DuW + u * v * delta * (-delta - 1) * (1 - W)^(-delta - 
        2) * (-1) * DvW * DuW + u * v * delta * (1 - W)^(-delta - 
        1) * DvuW
}
"dcbb2" <-
function (theta, delta, u, v) 
{
    k <- exp(theta * (u^(-delta) - 1))
    t <- exp(theta * (v^(-delta) - 1))
    S <- k + t - 1
    h <- (1/theta) * log(S)
    duk <- -k * (theta * delta) * u^(-delta - 1)
    dvt <- -t * (theta * delta) * v^(-delta - 1)
    duS <- duk
    dvS <- dvt
    duh <- (1/theta) * duS/S
    dvh <- (1/theta) * dvS/S
    dvuh <- (-1/theta) * duS * dvS/S^2
    densi <- (1/delta) * (1 + 1/delta) * (1 + h)^(-2 - 1/delta) * 
        dvh * duh - (1/delta) * (1 + h)^(-1 - 1/delta) * dvuh
}
"dcbb3" <-
function (theta, delta, u, v) 
{
    W <- exp(theta * (-log(u))^(delta))
    P <- exp(theta * (-log(v))^(delta))
    S <- W + P - 1
    h <- (1/theta) * log(S)
    F <- exp(-h^(1/delta))
    duS <- exp((-log(u))^(delta) * theta) * (-theta * delta/u) * 
        (-log(u))^(delta - 1)
    dvS <- exp((-log(v))^(delta) * theta) * (-theta * delta/v) * 
        (-log(v))^(delta - 1)
    dvuh <- (-1/theta)/S^2 * duS * dvS
    duh <- (1/theta) * duS/S
    dvh <- (1/theta) * dvS/S
    densi <- F * (1/delta^2) * (h^(1/delta - 1))^2 * dvh * duh + 
        F * (-1/delta) * (1/delta - 1) * (h)^(1/delta - 2) * 
            (dvh) * (duh) + F * (-1/delta) * (h)^(1/delta - 1) * 
        dvuh
}
"dcbb4" <-
function (theta, delta, u, v) 
{
    VV <- (u^(-theta) - 1)^(-delta)
    WW <- (v^(-theta) - 1)^(-delta)
    h <- VV + WW
    S <- u^(-theta) + v^(-theta) - 1
    duh <- delta * theta * u^(-theta - 1) * (u^(-theta) - 1)^(-delta - 
        1)
    dvh <- delta * theta * v^(-theta - 1) * (v^(-theta) - 1)^(-delta - 
        1)
    duS <- (-theta) * u^(-theta - 1)
    dvS <- (-theta) * v^(-theta - 1)
    densi <- (1/theta) * (1/theta + 1) * (S - h^(-1/delta))^(-1/theta - 
        2) * (dvS + 1/delta * h^(-1/delta - 1) * dvh) * (duS + 
        1/delta * h^(-1/delta - 1) * duh) + (-1/theta) * (S - 
        h^(-1/delta))^(-1/theta - 1) * ((-1/delta) * (1/delta + 
        1) * (h)^(-1/delta - 2) * dvh * duh)
}
"dcbb5" <-
function (theta, delta, u, v) 
{
    t <- (-log(u))^(-theta * delta) + (-log(v))^(-theta * delta)
    dut <- (theta * delta/u) * (-log(u))^(-theta * delta - 1)
    dvt <- (theta * delta/v) * (-log(v))^(-theta * delta - 1)
    S <- (-log(u))^(theta) + (-log(v))^(theta)
    duS <- (-theta/u) * (-log(u))^(theta - 1)
    dvS <- (-theta/v) * (-log(v))^(theta - 1)
    h <- S - t^(-1/delta)
    duh <- duS + (1/delta) * (t)^(-1/delta - 1) * (dut)
    dvh <- dvS + (1/delta) * (t)^(-1/delta - 1) * (dvt)
    dvuh <- -1/delta * (1/delta + 1) * t^(-1/delta - 2) * dut * 
        dvt
    densi <- exp(-h^(1/theta)) * (1/theta)^2 * (h^(1/theta - 
        1))^2 * dvh * duh + exp(-h^(1/theta)) * (-1/theta) * 
        (1/theta - 1) * h^(1/theta - 2) * dvh * duh + exp(-h^(1/theta)) * 
        (-1/theta) * h^(1/theta - 1) * dvuh
}
"dcbb6" <-
function (t, d, u, v) 
{
    t19 = (d * t * (-log(-(-u + 1)^t + 1))^(d - 1) * (-log(-(-v + 
        1)^t + 1))^(d - 1) * exp(-(-log(-(-u + 1)^t + 1))^d - 
        (-log(-(-v + 1)^t + 1))^d) * exp(-(-log(-(-u + 1)^t + 
        1))^d - (-log(-(-v + 1)^t + 1))^d)^(1/d - 1) * (-u + 
        1)^(t - 1) * (-v + 1)^(t - 1) * (-exp(-(-log(-(-u + 1)^t + 
        1))^d - (-log(-(-v + 1)^t + 1))^d)^(1/d) + 1)^(1/t - 
        1))/(((-u + 1)^t - 1) * ((-v + 1)^t - 1)) - (t * (-log(-(-u + 
        1)^t + 1))^(d - 1) * (-log(-(-v + 1)^t + 1))^(d - 1) * 
        exp(-(-log(-(-u + 1)^t + 1))^d - (-log(-(-v + 1)^t + 
            1))^d)^2 * exp(-(-log(-(-u + 1)^t + 1))^d - (-log(-(-v + 
        1)^t + 1))^d)^(2/d - 2) * (-u + 1)^(t - 1) * (-v + 1)^(t - 
        1) * (1/t - 1) * (-exp(-(-log(-(-u + 1)^t + 1))^d - (-log(-(-v + 
        1)^t + 1))^d)^(1/d) + 1)^(1/t - 2))/(((-u + 1)^t - 1) * 
        ((-v + 1)^t - 1)) + (d * t * (-log(-(-u + 1)^t + 1))^(d - 
        1) * (-log(-(-v + 1)^t + 1))^(d - 1) * exp(-(-log(-(-u + 
        1)^t + 1))^d - (-log(-(-v + 1)^t + 1))^d)^2 * exp(-(-log(-(-u + 
        1)^t + 1))^d - (-log(-(-v + 1)^t + 1))^d)^(1/d - 2) * 
        (-u + 1)^(t - 1) * (-v + 1)^(t - 1) * (1/d - 1) * (-exp(-(-log(-(-u + 
        1)^t + 1))^d - (-log(-(-v + 1)^t + 1))^d)^(1/d) + 1)^(1/t - 
        1))/(((-u + 1)^t - 1) * ((-v + 1)^t - 1))
}
"dcbb7" <-
function (theta, delta, u, v) 
{
    WU <- (1 - (1 - u)^(theta))^(-delta)
    WV <- (1 - (1 - v)^(theta))^(-delta)
    duWU <- (-delta * theta) * (1 - (1 - u)^(theta))^(-delta - 
        1) * (1 - u)^(theta - 1)
    dvWV <- (-delta * theta) * (1 - (1 - v)^(theta))^(-delta - 
        1) * (1 - v)^(theta - 1)
    K <- WU + WV
    duK <- duWU
    dvK <- dvWV
    S <- K - 1
    duS <- duK
    dvS <- dvK
    h <- 1 - S^(-1/delta)
    duh <- (1/delta) * S^(-1/delta - 1) * duS
    dvh <- (1/delta) * S^(-1/delta - 1) * dvS
    dvuh <- (1/delta) * (-1/delta - 1) * (S)^(-1/delta - 2) * 
        (dvS) * (duS)
    densi <- (-1/theta) * (1/theta - 1) * h^(1/theta - 2) * dvh * 
        duh - (1/theta) * h^(1/theta - 1) * dvuh
}
"dcbb8" <-
function (theta, delta, u, v) 
{
    S <- 1 - (1 - delta * u)^(theta)
    T <- 1 - (1 - delta * v)^(theta)
    K <- (1 - (1 - delta)^(theta))^(-1)
    W <- 1 - K * S * T
    DuS <- theta * delta * (1 - delta * u)^(theta - 1)
    DuW <- -K * T * DuS
    DvT <- theta * delta * (1 - delta * v)^(theta - 1)
    DvW <- -K * S * DvT
    DvuW <- -K * DuS * DvT
    densi <- -delta^(-1) * (1/theta) * (1/theta - 1) * W^(1/theta - 
        2) * DvW * DuW - delta^(-1) * (1/theta) * W^(1/theta - 
        1) * DvuW
}
"dcbb9" <-
function (theta, delta, u, v) 
{
    S <- delta - log(u)
    T <- delta - log(v)
    W <- S^(theta) + T^(theta) - delta^(theta)
    C <- exp(-W^(1/theta) + delta)
    DuS <- -1/u
    DuW <- theta * S^(theta - 1) * DuS
    DvT <- -1/v
    DvW <- theta * T^(theta - 1) * DvT
    densi <- C * (1/theta^2) * (W^(1/theta - 1))^2 * DvW * DuW + 
        C * (-1/theta) * (1/theta - 1) * W^(1/theta - 2) * DvW * 
            DuW
}
"llbb" <-
function (param, u, v, model = c("CBB1", "CBB2", "CBB3", "CBB4", 
    "CBB5", "CBB6", "CBB7", "CBB8", "CBB9", "CBB10", "CMM1", 
    "CMM2", "CMM3", "CMM4", "CMM5", "CMM6", "CMM7", "CMM8", "CMM9", 
    "CMM10", "CBM1", "CBM2", "CBM3", "CBM4", "CBM5", "CBM6", 
    "CBM7", "CBM8", "CBM9", "CBM10", "CMB1", "CMB2", "CMB3", 
    "CMB4", "CMB5", "CMB6", "CMB7", "CMB8", "CMB9", "CMB10")) 
{
    n <- sum(u >= -1)
    ss <- c(1:n) * 0
    s <- 0
    for (i in 1:n) {
        ss[i] <- log(cbbmodel(param[1], param[2], u[i], v[i], 
            model))
    }
    res <- ss
}
"llbb1" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb1(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"llbb10" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb10(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"llbb2" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb2(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"llbb3" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb3(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"llbb4" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb4(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"llbb5" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb5(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"llbb6" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb6(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"llbb7" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb7(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"llbb8" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb8(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"llbb9" <-
function (param, u, v) 
{
    n <- sum(u >= -1)
    s <- 0
    for (i in 1:n) {
        s <- s + log(dcbb9(param[1], param[2], u[i], v[i]))
        if (is.nan(s)) {
            break
        }
    }
    if (is.finite(s)) {
        res <- s
    }
    else {
        res <- -10^(64)
    }
}
"mlcbb" <-
function (u, v, thetamin, deltamin, thetamax, deltamax, copulamodel = c("CBB1", 
    "CBB2", "CBB3", "CBB4", "CBB5", "CBB6", "CBB7", "CBB8", "CBB9", 
    "CBB10", "CMM1", "CMM2", "CMM3", "CMM4", "CMM5", "CMM6", 
    "CMM7", "CMM8", "CMM9", "CMM10", "CBM1", "CBM2", "CBM3", 
    "CBM4", "CBM5", "CBM6", "CBM7", "CBM8", "CBM9", "CBM10", 
    "CMB1", "CMB2", "CMB3", "CMB4", "CMB5", "CMB6", "CMB7", "CMB8", 
    "CMB9", "CMB10")) 
{
    PMAX <- 0
    DMAX <- 20
    TMAX <- 20
    if (missing(deltamax)) {
        deltamax <- DMAX
    }
    if (missing(thetamax)) {
        thetamax <- TMAX
    }
    if (missing(deltamin) && copulamodel == "CBB1") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CBB2") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBB3") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CBB4") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBB5") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBB6") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CBB7") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBB8") {
        deltamin <- 0.005
    }
    if (missing(deltamax) && copulamodel == "CBB8") {
        deltamax <- 0.995
    }
    if (deltamax == DMAX && copulamodel == "CBB8") {
        deltamax <- 0.995
    }
    if (missing(deltamin) && copulamodel == "CBB9") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBB10") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMM1") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CMM2") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMM3") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CMM4") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMM5") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMM6") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CMM7") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMM8") {
        deltamin <- 0.005
    }
    if (missing(deltamax) && copulamodel == "CMM8") {
        deltamax <- 0.995
    }
    if (deltamax == DMAX && copulamodel == "CMM8") {
        deltamax <- 0.995
    }
    if (missing(deltamin) && copulamodel == "CMM9") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMM10") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBM1") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CBM2") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBM3") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CBM4") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBM5") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBM6") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CBM7") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBM8") {
        deltamin <- 0.005
    }
    if (missing(deltamax) && copulamodel == "CBM8") {
        deltamax <- 0.995
    }
    if (deltamax == DMAX && copulamodel == "CBM8") {
        deltamax <- 0.995
    }
    if (missing(deltamin) && copulamodel == "CBM9") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CBM10") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMB1") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CMB2") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMB3") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CMB4") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMB5") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMB6") {
        deltamin <- 1.005
    }
    if (missing(deltamin) && copulamodel == "CMB7") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMB8") {
        deltamin <- 0.005
    }
    if (missing(deltamax) && copulamodel == "CMB8") {
        deltamax <- 0.995
    }
    if (deltamax == DMAX && copulamodel == "CMB8") {
        deltamax <- 0.995
    }
    if (missing(deltamin) && copulamodel == "CMB9") {
        deltamin <- 0.005
    }
    if (missing(deltamin) && copulamodel == "CMB10") {
        deltamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CBB1") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CBB2") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CBB3") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CBB4") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CBB5") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBB6") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBB7") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBB8") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBB9") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBB10") {
        thetamin <- 0.005
    }
    if (missing(thetamax) && copulamodel == "CBB10") {
        thetamax <- 0.995
    }
    if (thetamax == TMAX && copulamodel == "CBB10") {
        thetamax <- 0.995
    }
    if (missing(thetamin) && copulamodel == "CMM1") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CMM2") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CMM3") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CMM4") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CMM5") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMM6") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMM7") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMM8") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMM9") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMM10") {
        thetamin <- 0.005
    }
    if (missing(thetamax) && copulamodel == "CMM10") {
        thetamax <- 0.995
    }
    if (thetamax == TMAX && copulamodel == "CMM10") {
        thetamax <- 0.995
    }
    if (missing(thetamin) && copulamodel == "CBM1") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CBM2") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CBM3") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CBM4") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CBM5") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBM6") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBM7") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBM8") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBM9") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CBM10") {
        thetamin <- 0.005
    }
    if (missing(thetamax) && copulamodel == "CBM10") {
        thetamax <- 0.995
    }
    if (thetamax == TMAX && copulamodel == "CBM10") {
        thetamax <- 0.995
    }
    if (missing(thetamin) && copulamodel == "CMB1") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CMB2") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CMB3") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CMB4") {
        thetamin <- 0.005
    }
    if (missing(thetamin) && copulamodel == "CMB5") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMB6") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMB7") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMB8") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMB9") {
        thetamin <- 1.005
    }
    if (missing(thetamin) && copulamodel == "CMB10") {
        thetamin <- 0.005
    }
    if (missing(thetamax) && copulamodel == "CMB10") {
        thetamax <- 0.995
    }
    if (thetamax == TMAX && copulamodel == "CMB10") {
        thetamax <- 0.995
    }
    n <- sum(u >= -1)
    m <- 5
    inct <- (thetamax - thetamin)/(m + 1)
    incd <- (deltamax - deltamin)/(m + 1)
    PMAX <- -10^(250)
    for (tet in 1:m) {
        for (del in 1:m) {
            teta <- thetamin + tet * inct
            delta <- deltamin + del * incd
            pvalor <- clibmodel(c(teta, delta), u, v, model = copulamodel)
            if (pvalor > PMAX) {
                PMAX <- pvalor
                tlmax <- teta
                dlmax <- delta
            }
        }
    }
    result <- optim(c(tlmax, dlmax), method = "L-BFGS-B", clibmodel, 
        lower = c(thetamin, deltamin), upper = c(thetamax, deltamax), 
        control = list(fnscale = -1), x = u, y = v, model = copulamodel)
}
"mlcbbsel" <-
function (U, V) 
{
    model = c("CBB1", "CBB2", "CBB3", "CBB4", "CBB5", "CBB6", 
        "CBB7", "CBB8", "CBB9", "CBB10", "CMM1", "CMM2", "CMM3", 
        "CMM4", "CMM5", "CMM6", "CMM7", "CMM8", "CMM9", "CMM10", 
        "CBM1", "CBM2", "CBM3", "CBM4", "CBM5", "CBM6", "CBM7", 
        "CBM8", "CBM9", "CBM10", "CMB1", "CMB2", "CMB3", "CMB4", 
        "CMB5", "CMB6", "CMB7", "CMB8", "CMB9", "CMB10")
    respmodel = c("CBB1", "CBB2", "CBB3", "CBB4", "CBB5", "CBB6", 
        "CBB7", "CBB8", "CBB9", "CBB10", "180 degree rotation of CBB1", 
        "180 degree rotation of CBB2", "180 degree rotation of CBB3", 
        "180 degree rotation of CBB4", "180 degree rotation of CBB5", 
        "180 degree rotation of CBB6", "180 degree rotation of CBB7", 
        "180 degree rotation of CBB8", "180 degree rotation of CBB9", 
        "180 degree rotation of CBB10", "90 degree rotation of CBB1", 
        "90 degree rotation of CBB2", "90 degree rotation of CBB3", 
        "90 degree rotation of CBB4", "90 degree rotation of CBB5", 
        "90 degree rotation of CBB6", "90 degree rotation of CBB7", 
        "90 degree rotation of CBB8", "90 degree rotation of CBB9", 
        "90 degree rotation of CBB10", "270 degree rotation of CBB1", 
        "270 degree rotation of CBB2", "270 degree rotation of CBB3", 
        "270 degree rotation of CBB4", "270 degree rotation of CBB5", 
        "270 degree rotation of CBB6", "270 degree rotation of CBB7", 
        "270 degree rotation of CBB8", "270 degree rotation of CBB9", 
        "270 degree rotation of CBB10")
    ncop <- 1
    TODOCOP <- c(1:40)
    TODOPV <- c(1:2) * 0
    TODOTET <- c(1:2) * 0
    TODODEL <- c(1:2) * 0
    PVMAX <- -10^(100)
    pmax <- 10
    n <- sum(U != -10^200)
    for (nmodel in 1:40) {
        RES <- mlcbb(U, V, copulamodel = model[nmodel])
        PV <- RES$value
        PAR <- RES$par
        if (PV > PVMAX) {
            PVMAX <- PV
            PARMAX <- PAR
            COPMAX <- nmodel
            LLMAX <- PV
        }
        TODOPV[nmodel] <- PV
        TODOTET[nmodel] <- PAR[1]
        TODODEL[nmodel] <- PAR[2]
    }
    ORDEN <- order(TODOPV, TODOCOP, decreasing = TRUE)
    TODO <- matrix(c(1:40 * 4) * 0, 40, 4)
    TODO[, 1] <- respmodel[TODOCOP[ORDEN]]
    TODO[, 2] <- TODOPV[ORDEN]
    TODO[, 3] <- TODOTET[ORDEN]
    TODO[, 4] <- TODODEL[ORDEN]
    result <- list(todo = TODO, copmax = respmodel[COPMAX], parmax = PARMAX, 
        llmax = LLMAX)
}
