Running examples in ‘yuima-Ex.R’ failed
The error most likely occurred in:

> ### Name: Diagnostic.Carma
> ### Title: Diagnostic Carma model
> ### Aliases: Diagnostic.Carma
> 
> ### ** Examples
> 
> 
> mod1 <- setCarma(p = 2, q = 1, scale.par = "sig",
+           Carma.var = "y")
> 
> param1 <- list(a1 = 1.39631, a2 = 0.05029, b0 = 1,
+             b1 = 1, sig = 1)
> samp1 <- setSampling(Terminal = 100, n = 200)
Warning in yuima.warn("'delta' (re)defined.") :
  
YUIMA: 'delta' (re)defined.

> 
> set.seed(123)
> 
> sim1 <- simulate(mod1, true.parameter = param1,
+           sampling = samp1)
> 
> est1 <- qmle(sim1, start = param1)

Starting qmle for carma ... 
Warning in yuima.warn("Drift and diffusion parameters must be different. Doing\n               joint estimation, asymptotic theory may not hold true.") :
  
YUIMA: Drift and diffusion parameters must be different. Doing
               joint estimation, asymptotic theory may not hold true.

 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
yuima
 --- call from context --- 
qmle(sim1, start = param1)
 --- call from argument --- 
if (class(rrr) != "try-error") vcov <- rrr
 --- R stacktrace ---
where 1: qmle(sim1, start = param1)

 --- value of length: 2 type: logical ---
[1] TRUE TRUE
 --- function from context --- 
function (yuima, start, method = "BFGS", fixed = list(), print = FALSE, 
    lower, upper, joint = FALSE, Est.Incr = "NoIncr", aggregation = TRUE, 
    threshold = NULL, rcpp = FALSE, ...) 
{
    if (Est.Incr == "Carma.Inc") {
        Est.Incr <- "Incr"
    }
    if (Est.Incr == "Carma.Par") {
        Est.Incr <- "NoIncr"
    }
    if (Est.Incr == "Carma.IncPar") {
        Est.Incr <- "IncrPar"
    }
    if (is(yuima@model, "yuima.carma")) {
        NoNeg.Noise <- FALSE
        cat("\nStarting qmle for carma ... \n")
    }
    if (is.CARMA(yuima) && length(yuima@model@info@scale.par) != 
        0) {
        method <- "L-BFGS-B"
    }
    call <- match.call()
    if (missing(yuima)) 
        yuima.stop("yuima object is missing.")
    if (is.COGARCH(yuima)) {
        if (missing(lower)) 
            lower <- list()
        if (missing(upper)) 
            upper <- list()
        res <- NULL
        if ("grideq" %in% names(as.list(call)[-(1:2)])) {
            res <- PseudoLogLik.COGARCH(yuima, start, method = method, 
                fixed = list(), lower, upper, Est.Incr, call, 
                aggregation = aggregation, ...)
        }
        else {
            res <- PseudoLogLik.COGARCH(yuima, start, method = method, 
                fixed = list(), lower, upper, Est.Incr, call, 
                grideq = FALSE, aggregation = aggregation, ...)
        }
        return(res)
    }
    if (is.PPR(yuima)) {
        if (missing(lower)) 
            lower <- list()
        if (missing(upper)) 
            upper <- list()
        res <- quasiLogLik.PPR(yuimaPPR = yuima, parLambda = start, 
            method = method, fixed = list(), lower, upper, call, 
            ...)
        return(res)
    }
    orig.fixed <- fixed
    orig.fixed.par <- names(orig.fixed)
    if (is.Poisson(yuima)) 
        threshold <- 0
    if (missing(start)) 
        yuima.stop("Starting values for the parameters are missing.")
    yuima.nobs <- as.integer(max(unlist(lapply(get.zoo.data(yuima), 
        length)) - 1, na.rm = TRUE))
    diff.par <- yuima@model@parameter@diffusion
    if (is.CARMA(yuima) && length(diff.par) == 0 && length(yuima@model@parameter@jump) != 
        0) {
        diff.par <- yuima@model@parameter@jump
    }
    if (is.CARMA(yuima) && length(yuima@model@parameter@jump) != 
        0) {
        CPlist <- c("dgamma", "dexp")
        codelist <- c("rIG", "rgamma")
        if (yuima@model@measure.type == "CP") {
            tmp <- regexpr("\\(", yuima@model@measure$df$exp)[1]
            measurefunc <- substring(yuima@model@measure$df$exp, 
                1, tmp - 1)
            if (!is.na(match(measurefunc, CPlist))) {
                yuima.warn("carma(p,q): the qmle for a carma(p,q) driven by a Compound Poisson with no-negative random size")
                NoNeg.Noise <- TRUE
                if ((yuima@model@info@q + 1) == (yuima@model@info@q + 
                  1)) {
                  start[["mean.noise"]] <- 1
                }
            }
        }
        if (yuima@model@measure.type == "code") {
            if (class(yuima@model@measure$df) == "yuima.law") {
                measurefunc <- "yuima.law"
            }
            else {
                tmp <- regexpr("\\(", yuima@model@measure$df$exp)[1]
                measurefunc <- substring(yuima@model@measure$df$exp, 
                  1, tmp - 1)
            }
            if (!is.na(match(measurefunc, codelist))) {
                yuima.warn("carma(p,q): the qmle for a carma(p,q) driven by a non-Negative Levy  will be implemented as soon as possible")
                NoNeg.Noise <- TRUE
                if ((yuima@model@info@q + 1) == (yuima@model@info@q + 
                  1)) {
                  start[["mean.noise"]] <- 1
                }
            }
        }
    }
    if (is.CARMA(yuima) && length(yuima@model@info@lin.par) > 
        0) {
        yuima.warn("carma(p,q): the case of lin.par will be implemented as soon as")
        return(NULL)
    }
    drift.par <- yuima@model@parameter@drift
    if (is.CARMA(yuima)) {
        xinit.par <- yuima@model@parameter@xinit
    }
    jump.par <- NULL
    if (is.CARMA(yuima)) {
        jump.par <- yuima@model@parameter@jump
        measure.par <- yuima@model@parameter@measure
    }
    else {
        if (length(yuima@model@parameter@jump) != 0) {
            measure.par <- unique(c(yuima@model@parameter@measure, 
                yuima@model@parameter@jump))
        }
        else {
            measure.par <- yuima@model@parameter@measure
        }
    }
    common.par <- yuima@model@parameter@common
    JointOptim <- joint
    if (is.CARMA(yuima) && length(yuima@model@parameter@jump) != 
        0) {
        if (any((match(jump.par, drift.par)))) {
            JointOptim <- TRUE
            yuima.warn("Drift and diffusion parameters must be different. Doing\n                 joint estimation, asymptotic theory may not hold true.")
        }
    }
    if (length(common.par) > 0) {
        JointOptim <- TRUE
        yuima.warn("Drift and diffusion parameters must be different. Doing\n               joint estimation, asymptotic theory may not hold true.")
    }
    if (!is.list(start)) 
        yuima.stop("Argument 'start' must be of list type.")
    fullcoef <- NULL
    if (length(diff.par) > 0) 
        fullcoef <- diff.par
    if (length(drift.par) > 0) 
        fullcoef <- c(fullcoef, drift.par)
    if (is.CARMA(yuima) && (length(yuima@model@info@loc.par) != 
        0)) {
        fullcoef <- c(fullcoef, yuima@model@info@loc.par)
    }
    if (is.CARMA(yuima) && (NoNeg.Noise == TRUE)) {
        if ((yuima@model@info@q + 1) == yuima@model@info@p) {
            mean.noise <- "mean.noise"
            fullcoef <- c(fullcoef, mean.noise)
        }
    }
    fullcoef <- c(fullcoef, measure.par)
    if (is.CARMA(yuima)) {
        if (length(yuima@model@parameter@xinit) > 1) {
            condIniCarma <- !(yuima@model@parameter@xinit %in% 
                fullcoef)
            if (sum(condIniCarma) > 0) {
                NamesInitial <- yuima@model@parameter@xinit[condIniCarma]
                start <- as.list(unlist(start)[!names(unlist(start)) %in% 
                  (NamesInitial)])
            }
        }
    }
    npar <- length(fullcoef)
    fixed.par <- names(fixed)
    fixed.carma = NULL
    if (is.CARMA(yuima) && (length(measure.par) > 0)) {
        if (!missing(fixed)) {
            if (names(fixed) %in% measure.par) {
                idx.fixed.carma <- match(names(fixed), measure.par)
                idx.fixed.carma <- idx.fixed.carma[!is.na(idx.fixed.carma)]
                if (length(idx.fixed.carma) != 0) {
                  fixed.carma <- as.numeric(fixed[measure.par[idx.fixed.carma]])
                  names(fixed.carma) <- measure.par[idx.fixed.carma]
                }
            }
        }
        upper.carma = NULL
        if (!missing(upper)) {
            if (names(upper) %in% measure.par) {
                idx.upper.carma <- match(names(upper), measure.par)
                idx.upper.carma <- idx.upper.carma[!is.na(idx.upper.carma)]
                if (length(idx.upper.carma) != 0) {
                  upper.carma <- as.numeric(upper[measure.par[idx.upper.carma]])
                  names(upper.carma) <- measure.par[idx.upper.carma]
                }
            }
        }
        lower.carma = NULL
        if (!missing(lower)) {
            if (names(lower) %in% measure.par) {
                idx.lower.carma <- match(names(lower), measure.par)
                idx.lower.carma <- idx.lower.carma[!is.na(idx.lower.carma)]
                if (length(idx.lower.carma) != 0) {
                  lower.carma <- as.numeric(lower[measure.par[idx.lower.carma]])
                  names(lower.carma) <- measure.par[idx.lower.carma]
                }
            }
        }
        for (j in c(1:length(measure.par))) {
            if (is.na(match(measure.par[j], names(fixed)))) {
                fixed.par <- c(fixed.par, measure.par[j])
                fixed[measure.par[j]] <- start[measure.par[j]]
            }
        }
    }
    if (any(!(fixed.par %in% fullcoef))) 
        yuima.stop("Some named arguments in 'fixed' are not arguments to the supplied yuima model")
    nm <- names(start)
    oo <- match(nm, fullcoef)
    if (any(is.na(oo))) 
        yuima.stop("some named arguments in 'start' are not arguments to the supplied yuima model")
    start <- start[order(oo)]
    nm <- names(start)
    idx.diff <- match(diff.par, nm)
    idx.drift <- match(drift.par, nm)
    idx.measure <- match(measure.par, nm)
    if (is.CARMA(yuima)) {
        idx.xinit <- as.integer(na.omit(match(xinit.par, nm)))
    }
    idx.fixed <- match(fixed.par, nm)
    orig.idx.fixed <- idx.fixed
    tmplower <- as.list(rep(-Inf, length(nm)))
    names(tmplower) <- nm
    if (!missing(lower)) {
        idx <- match(names(lower), names(tmplower))
        if (any(is.na(idx))) 
            yuima.stop("names in 'lower' do not match names fo parameters")
        tmplower[idx] <- lower
    }
    lower <- tmplower
    tmpupper <- as.list(rep(Inf, length(nm)))
    names(tmpupper) <- nm
    if (!missing(upper)) {
        idx <- match(names(upper), names(tmpupper))
        if (any(is.na(idx))) 
            yuima.stop("names in 'lower' do not match names fo parameters")
        tmpupper[idx] <- upper
    }
    upper <- tmpupper
    d.size <- yuima@model@equation.number
    if (is.CARMA(yuima)) {
        d.size <- 1
    }
    n <- length(yuima)[1]
    env <- new.env()
    assign("X", as.matrix(onezoo(yuima)), envir = env)
    assign("deltaX", matrix(0, n - 1, d.size), envir = env)
    assign("Cn.r", numeric(n - 1), envir = env)
    if (length(measure.par) == 0) 
        threshold <- 0
    if (is.CARMA(yuima)) {
        env$X <- as.matrix(env$X[, 1])
        env$deltaX <- as.matrix(env$deltaX[, 1])
        assign("time.obs", length(env$X), envir = env)
        assign("p", yuima@model@info@p, envir = env)
        assign("q", yuima@model@info@q, envir = env)
        assign("V_inf0", matrix(diag(rep(1, env$p)), env$p, env$p), 
            envir = env)
    }
    assign("time", as.numeric(index(yuima@data@zoo.data[[1]])), 
        envir = env)
    for (t in 1:(n - 1)) {
        env$deltaX[t, ] <- env$X[t + 1, ] - env$X[t, ]
        if (!is.CARMA(yuima)) 
            env$Cn.r[t] <- ((sqrt(env$deltaX[t, ] %*% env$deltaX[t, 
                ])) <= threshold)
    }
    if (length(measure.par) == 0) 
        env$Cn.r <- rep(1, length(env$Cn.r))
    assign("h", deltat(yuima@data@zoo.data[[1]]), envir = env)
    if (length(measure.par) > 0) {
        if (class(yuima@model@measure$df) == "yuima.law") {
            args <- yuima@model@parameter@measure
        }
        else {
            args <- unlist(strsplit(suppressWarnings(sub("^.+?\\((.+)\\)", 
                "\\1", yuima@model@measure$df$expr, perl = TRUE)), 
                ","))
        }
        idx.intensity <- numeric(0)
        for (i in 1:length(measure.par)) {
            if (sum(grepl(measure.par[i], yuima@model@measure$intensity))) 
                idx.intensity <- append(idx.intensity, i)
        }
        assign("idx.intensity", idx.intensity, envir = env)
        assign("measure.var", args[1], envir = env)
    }
    f <- function(p) {
        mycoef <- as.list(p)
        if (!is.CARMA(yuima)) {
            if (length(c(idx.fixed, idx.measure)) > 0) 
                names(mycoef) <- nm[-c(idx.fixed, idx.measure)]
            else names(mycoef) <- nm
        }
        else {
            if (length(idx.fixed) > 0) 
                names(mycoef) <- nm[-idx.fixed]
            else names(mycoef) <- nm
        }
        mycoef[fixed.par] <- fixed
        minusquasilogl(yuima = yuima, param = mycoef, print = print, 
            env, rcpp = rcpp)
    }
    fpsi <- function(p) {
        mycoef <- as.list(p)
        idx.cont <- c(idx.diff, idx.drift)
        if (length(c(idx.fixed, idx.cont)) > 0) 
            names(mycoef) <- nm[-c(idx.fixed, idx.cont)]
        else names(mycoef) <- nm
        mycoef[fixed.par] <- fixed
        minusquasipsi(yuima = yuima, param = mycoef, print = print, 
            env = env)
    }
    fj <- function(p) {
        mycoef <- as.list(p)
        if (!is.CARMA(yuima)) {
            idx.fixed <- orig.idx.fixed
            if (length(c(idx.fixed, idx.measure)) > 0) 
                names(mycoef) <- nm[-c(idx.fixed, idx.measure)]
            else names(mycoef) <- nm
        }
        else {
            names(mycoef) <- nm
            mycoef[fixed.par] <- fixed
        }
        mycoef[fixed.par] <- fixed
        minusquasilogl(yuima = yuima, param = mycoef, print = print, 
            env, rcpp = rcpp)
    }
    oout <- NULL
    HESS <- matrix(0, length(nm), length(nm))
    colnames(HESS) <- nm
    rownames(HESS) <- nm
    HaveDriftHess <- FALSE
    HaveDiffHess <- FALSE
    HaveMeasHess <- FALSE
    if (length(start)) {
        if (JointOptim) {
            old.fixed <- fixed
            new.start <- start
            old.start <- start
            if (!is.CARMA(yuima)) {
                if (length(c(idx.fixed, idx.measure)) > 0) 
                  new.start <- start[-c(idx.fixed, idx.measure)]
            }
            if (length(new.start) > 1) {
                if (is.CARMA(yuima) && (NoNeg.Noise == TRUE)) 
                  if (mean.noise %in% names(lower)) {
                    lower[mean.noise] <- 10^-7
                  }
                oout <- optim(new.start, fj, method = method, 
                  hessian = TRUE, lower = lower, upper = upper)
                if (length(fixed) > 0) 
                  oout$par[fixed.par] <- unlist(fixed)[fixed.par]
                if (is.CARMA(yuima)) {
                  HESS <- oout$hessian
                }
                else {
                  HESS[names(new.start), names(new.start)] <- oout$hessian
                }
                if (is.CARMA(yuima) && length(yuima@model@info@scale.par) != 
                  0) {
                  b0 <- paste0(yuima@model@info@ma.par, "0", 
                    collapse = "")
                  idx.b0 <- match(b0, rownames(HESS))
                  HESS <- HESS[-idx.b0, ]
                  HESS <- HESS[, -idx.b0]
                }
                if (is.CARMA(yuima) && length(fixed) > 0 && length(yuima@model@parameter@measure) == 
                  0) {
                  for (i in c(1:length(fixed.par))) {
                    indx.fixed <- match(fixed.par[i], rownames(HESS))
                    HESS <- HESS[-indx.fixed, ]
                    HESS <- HESS[, -indx.fixed]
                  }
                }
                if (is.CARMA(yuima) && length(yuima@model@parameter@measure) != 
                  0) {
                  for (i in c(1:length(fixed.par))) {
                    indx.fixed <- match(fixed.par[i], rownames(HESS))
                    HESS <- HESS[-indx.fixed, ]
                    HESS <- HESS[, -indx.fixed]
                  }
                  if (is.CARMA(yuima) && (NoNeg.Noise == TRUE)) {
                    idx.noise <- (match(mean.noise, rownames(HESS)))
                    HESS <- HESS[-idx.noise, ]
                    HESS <- HESS[, -idx.noise]
                  }
                }
                HaveDriftHess <- TRUE
                HaveDiffHess <- TRUE
            }
            else {
                opt1 <- optimize(f, ...)
                oout <- list(par = opt1$minimum, value = opt1$objective)
            }
            theta1 <- oout$par[diff.par]
            theta2 <- oout$par[drift.par]
        }
        else {
            theta1 <- NULL
            old.fixed <- fixed
            old.start <- start
            if (length(idx.diff) > 0) {
                old.fixed <- fixed
                old.start <- start
                old.fixed.par <- fixed.par
                new.start <- start[idx.diff]
                new.fixed <- fixed
                if (length(idx.drift) > 0) 
                  new.fixed[nm[idx.drift]] <- start[idx.drift]
                fixed <- new.fixed
                fixed.par <- names(fixed)
                idx.fixed <- match(fixed.par, nm)
                names(new.start) <- nm[idx.diff]
                mydots <- as.list(call)[-(1:2)]
                mydots$print <- NULL
                mydots$rcpp <- NULL
                mydots$fixed <- NULL
                mydots$fn <- as.name("f")
                mydots$start <- NULL
                mydots$par <- unlist(new.start)
                mydots$hessian <- FALSE
                mydots$upper <- as.numeric(unlist(upper[nm[idx.diff]]))
                mydots$lower <- as.numeric(unlist(lower[nm[idx.diff]]))
                mydots$joint <- NULL
                mydots$aggregation <- NULL
                mydots$threshold <- NULL
                if ((length(mydots$par) > 1) | any(is.infinite(c(mydots$upper, 
                  mydots$lower)))) {
                  oout <- do.call(optim, args = mydots)
                }
                else {
                  mydots$f <- mydots$fn
                  mydots$fn <- NULL
                  mydots$par <- NULL
                  mydots$hessian <- NULL
                  mydots$method <- NULL
                  mydots$interval <- as.numeric(c(unlist(lower[diff.par]), 
                    unlist(upper[diff.par])))
                  mydots$lower <- NULL
                  mydots$upper <- NULL
                  opt1 <- do.call(optimize, args = mydots)
                  theta1 <- opt1$minimum
                  names(theta1) <- diff.par
                  oout <- list(par = theta1, value = opt1$objective)
                }
                theta1 <- oout$par
                fixed <- old.fixed
                start <- old.start
                fixed.par <- old.fixed.par
            }
            theta2 <- NULL
            if (length(idx.drift) > 0) {
                fixed <- old.fixed
                start <- old.start
                old.fixed.par <- fixed.par
                new.start <- start[idx.drift]
                new.fixed <- fixed
                new.fixed[names(theta1)] <- theta1
                fixed <- new.fixed
                fixed.par <- names(fixed)
                idx.fixed <- match(fixed.par, nm)
                names(new.start) <- nm[idx.drift]
                mydots <- as.list(call)[-(1:2)]
                mydots$print <- NULL
                mydots$rcpp <- NULL
                mydots$fixed <- NULL
                mydots$fn <- as.name("f")
                mydots$threshold <- NULL
                mydots$start <- NULL
                mydots$par <- unlist(new.start)
                mydots$hessian <- FALSE
                mydots$upper <- unlist(upper[nm[idx.drift]])
                mydots$lower <- unlist(lower[nm[idx.drift]])
                mydots$joint <- NULL
                mydots$aggregation <- NULL
                if (length(mydots$par) > 1 | any(is.infinite(c(mydots$upper, 
                  mydots$lower)))) {
                  if (is.CARMA(yuima)) {
                    if (NoNeg.Noise == TRUE) {
                      if ((yuima@model@info@q + 1) == yuima@model@info@p) {
                        mydots$lower[names(start["NoNeg.Noise"])] <- 10^(-7)
                      }
                    }
                    if (length(yuima@model@info@scale.par) != 
                      0) {
                      name_b0 <- paste0(yuima@model@info@ma.par, 
                        "0", collapse = "")
                      index_b0 <- match(name_b0, nm)
                      mydots$lower[index_b0] <- 1
                      mydots$upper[index_b0] <- 1 + 10^(-7)
                    }
                    if (length(yuima@model@info@loc.par) != 0) {
                      mydots$upper <- unlist(upper[nm])
                      mydots$lower <- unlist(lower[nm])
                      idx.tot <- unique(c(idx.drift, idx.xinit))
                      new.start <- start[idx.tot]
                      names(new.start) <- nm[idx.tot]
                      mydots$par <- unlist(new.start)
                    }
                  }
                  oout1 <- do.call(optim, args = mydots)
                }
                else {
                  mydots$f <- mydots$fn
                  mydots$fn <- NULL
                  mydots$par <- NULL
                  mydots$hessian <- NULL
                  mydots$method <- NULL
                  mydots$interval <- as.numeric(c(lower[drift.par], 
                    upper[drift.par]))
                  opt1 <- do.call(optimize, args = mydots)
                  theta2 <- opt1$minimum
                  names(theta2) <- drift.par
                  oout1 <- list(par = theta2, value = as.numeric(opt1$objective))
                }
                theta2 <- oout1$par
                fixed <- old.fixed
                start <- old.start
                old.fixed.par <- fixed.par
            }
            oout1 <- list(par = c(theta1, theta2))
            if (!is.CARMA(yuima)) {
                if (length(c(diff.par, diff.par)) > 0) 
                  names(oout1$par) <- c(diff.par, drift.par)
            }
            oout <- oout1
        }
    }
    else {
        list(par = numeric(0L), value = f(start))
    }
    fMeas <- function(p) {
        mycoef <- as.list(p)
        minusquasipsi(yuima = yuima, param = mycoef, print = print, 
            env = env)
    }
    fDrift <- function(p) {
        mycoef <- as.list(p)
        if (!is.CARMA(yuima)) {
            names(mycoef) <- drift.par
            mycoef[diff.par] <- coef[diff.par]
        }
        minusquasilogl(yuima = yuima, param = mycoef, print = print, 
            env, rcpp = rcpp)
    }
    fDiff <- function(p) {
        mycoef <- as.list(p)
        if (!is.CARMA(yuima)) {
            names(mycoef) <- diff.par
            mycoef[drift.par] <- coef[drift.par]
        }
        minusquasilogl(yuima = yuima, param = mycoef, print = print, 
            env, rcpp = rcpp)
    }
    theta3 <- NULL
    if (length(idx.measure) > 0 & !is.CARMA(yuima)) {
        idx.cont <- c(idx.drift, idx.diff)
        fixed <- old.fixed
        start <- old.start
        old.fixed.par <- fixed.par
        new.fixed <- fixed
        new.start <- start[idx.measure]
        new.fixed <- fixed
        new.fixed[names(theta1)] <- theta1
        new.fixed[names(theta2)] <- theta2
        fixed <- new.fixed
        fixed.par <- names(fixed)
        idx.fixed <- match(fixed.par, nm)
        names(new.start) <- nm[idx.measure]
        mydots <- as.list(call)[-(1:2)]
        mydots$threshold <- NULL
        mydots$fixed <- NULL
        mydots$fn <- as.name("fpsi")
        mydots$start <- NULL
        mydots$threshold <- NULL
        mydots$par <- unlist(new.start)
        mydots$hessian <- TRUE
        mydots$joint <- NULL
        mydots$upper <- unlist(upper[nm[idx.measure]])
        mydots$lower <- unlist(lower[nm[idx.measure]])
        mydots$method <- method
        oout3 <- do.call(optim, args = mydots)
        theta3 <- oout3$par
        HESS[measure.par, measure.par] <- oout3$hessian
        HaveMeasHess <- TRUE
        fixed <- old.fixed
        start <- old.start
        fixed.par <- old.fixed.par
    }
    if (!is.CARMA(yuima)) {
        oout4 <- list(par = c(theta1, theta2, theta3))
        names(oout4$par) <- c(diff.par, drift.par, measure.par)
        oout <- oout4
    }
    coef <- oout$par
    control = list()
    par <- coef
    if (!is.CARMA(yuima)) {
        names(par) <- unique(c(diff.par, drift.par, measure.par))
        nm <- unique(c(diff.par, drift.par, measure.par))
    }
    else {
        names(par) <- unique(c(diff.par, drift.par))
        nm <- unique(c(diff.par, drift.par))
    }
    if (is.CARMA(yuima) && length(yuima@model@parameter@measure) != 
        0) {
        nm <- c(nm, measure.par)
        if ((NoNeg.Noise == TRUE)) {
            nm <- c(nm, mean.noise)
        }
        nm <- unique(nm)
    }
    if (is.CARMA(yuima) && (length(yuima@model@info@loc.par) != 
        0)) {
        nm <- unique(c(nm, yuima@model@info@loc.par))
    }
    conDrift <- list(trace = 5, fnscale = 1, parscale = rep.int(5, 
        length(drift.par)), ndeps = rep.int(0.001, length(drift.par)), 
        maxit = 100L, abstol = -Inf, reltol = sqrt(.Machine$double.eps), 
        alpha = 1, beta = 0.5, gamma = 2, REPORT = 10, type = 1, 
        lmm = 5, factr = 1e+07, pgtol = 0, tmax = 10, temp = 10)
    conDiff <- list(trace = 5, fnscale = 1, parscale = rep.int(5, 
        length(diff.par)), ndeps = rep.int(0.001, length(diff.par)), 
        maxit = 100L, abstol = -Inf, reltol = sqrt(.Machine$double.eps), 
        alpha = 1, beta = 0.5, gamma = 2, REPORT = 10, type = 1, 
        lmm = 5, factr = 1e+07, pgtol = 0, tmax = 10, temp = 10)
    conMeas <- list(trace = 5, fnscale = 1, parscale = rep.int(5, 
        length(measure.par)), ndeps = rep.int(0.001, length(measure.par)), 
        maxit = 100L, abstol = -Inf, reltol = sqrt(.Machine$double.eps), 
        alpha = 1, beta = 0.5, gamma = 2, REPORT = 10, type = 1, 
        lmm = 5, factr = 1e+07, pgtol = 0, tmax = 10, temp = 10)
    if (is.CARMA(yuima) && length(yuima@model@info@loc.par) != 
        0) {
        conDrift <- list(trace = 5, fnscale = 1, parscale = rep.int(5, 
            length(c(drift.par, yuima@model@info@loc.par))), 
            ndeps = rep.int(0.001, length(c(drift.par, yuima@model@info@loc.par))), 
            maxit = 100L, abstol = -Inf, reltol = sqrt(.Machine$double.eps), 
            alpha = 1, beta = 0.5, gamma = 2, REPORT = 10, type = 1, 
            lmm = 5, factr = 1e+07, pgtol = 0, tmax = 10, temp = 10)
        conDiff <- list(trace = 5, fnscale = 1, parscale = rep.int(5, 
            length(diff.par)), ndeps = rep.int(0.001, length(diff.par)), 
            maxit = 100L, abstol = -Inf, reltol = sqrt(.Machine$double.eps), 
            alpha = 1, beta = 0.5, gamma = 2, REPORT = 10, type = 1, 
            lmm = 5, factr = 1e+07, pgtol = 0, tmax = 10, temp = 10)
    }
    if (!HaveDriftHess & (length(drift.par) > 0)) {
        if (!is.CARMA(yuima)) {
            hess2 <- optimHess(coef[drift.par], fDrift, NULL, 
                control = conDrift)
            HESS[drift.par, drift.par] <- hess2
        }
        else {
            names(coef) <- c(drift.par, yuima@model@info@loc.par)
            hess2 <- optimHess(coef, fDrift, NULL, control = conDrift)
            HESS <- hess2
        }
        if (is.CARMA(yuima) && length(yuima@model@info@scale.par) != 
            0) {
            b0 <- paste0(yuima@model@info@ma.par, "0", collapse = "")
            idx.b0 <- match(b0, rownames(HESS))
            HESS <- HESS[-idx.b0, ]
            HESS <- HESS[, -idx.b0]
        }
    }
    if (!HaveDiffHess & (length(diff.par) > 0)) {
        hess1 <- optimHess(coef[diff.par], fDiff, NULL, control = conDiff)
        HESS[diff.par, diff.par] <- hess1
    }
    oout$hessian <- HESS
    if (!HaveMeasHess & (length(measure.par) > 0) & !is.CARMA(yuima)) {
        hess1 <- optimHess(coef[measure.par], fMeas, NULL, control = conMeas)
        oout$hessian[measure.par, measure.par] <- hess1
    }
    vcov <- matrix(NA, length(coef), length(coef))
    if (length(coef)) {
        rrr <- try(solve(oout$hessian), TRUE)
        if (class(rrr) != "try-error") 
            vcov <- rrr
    }
    mycoef <- as.list(coef)
    if (!is.CARMA(yuima)) {
        names(mycoef) <- nm
    }
    idx.fixed <- orig.idx.fixed
    mycoef.cont <- mycoef
    if (length(c(idx.fixed, idx.measure) > 0)) 
        mycoef.cont <- mycoef[-c(idx.fixed, idx.measure)]
    min.diff <- 0
    min.jump <- 0
    if (length(c(diff.par, drift.par)) > 0 & !is.CARMA(yuima)) {
        min.diff <- minusquasilogl(yuima = yuima, param = mycoef[c(diff.par, 
            drift.par)], print = print, env, rcpp = rcpp)
    }
    else {
        if (length(c(diff.par, drift.par)) > 0 & is.CARMA(yuima)) {
            min.diff <- minusquasilogl(yuima = yuima, param = mycoef, 
                print = print, env, rcpp = rcpp)
        }
    }
    if (length(c(measure.par)) > 0 & !is.CARMA(yuima)) 
        min.jump <- minusquasipsi(yuima = yuima, param = mycoef[measure.par], 
            print = print, env = env)
    min <- min.diff + min.jump
    if (min == 0) 
        min <- NA
    dummycov <- matrix(0, length(coef), length(coef))
    rownames(dummycov) <- names(coef)
    colnames(dummycov) <- names(coef)
    dummycov[rownames(vcov), colnames(vcov)] <- vcov
    vcov <- dummycov
    if (!is.CARMA(yuima)) {
        if (length(measure.par) > 0) {
            final_res <- new("yuima.CP.qmle", Jump.times = env$time[env$Cn.r == 
                0], Jump.values = env$deltaX[env$Cn.r == 0, ], 
                X.values = env$X[env$Cn.r == 0, ], model = yuima@model, 
                call = call, coef = coef, fullcoef = unlist(mycoef), 
                vcov = vcov, min = min, details = oout, minuslogl = minusquasilogl, 
                method = method, nobs = yuima.nobs, threshold = threshold)
        }
        else {
            final_res <- new("yuima.qmle", call = call, coef = coef, 
                fullcoef = unlist(mycoef), vcov = vcov, min = min, 
                details = oout, minuslogl = minusquasilogl, method = method, 
                nobs = yuima.nobs, model = yuima@model)
        }
    }
    else {
        if (Est.Incr == "IncrPar" || Est.Incr == "Incr") {
            final_res <- new("yuima.carma.qmle", call = call, 
                coef = coef, fullcoef = unlist(mycoef), vcov = vcov, 
                min = min, details = oout, minuslogl = minusquasilogl, 
                method = method, nobs = yuima.nobs, logL.Incr = NULL)
        }
        else {
            if (Est.Incr == "NoIncr") {
                final_res <- new("yuima.qmle", call = call, coef = coef, 
                  fullcoef = unlist(mycoef), vcov = vcov, min = min, 
                  details = oout, minuslogl = minusquasilogl, 
                  method = method, nobs = yuima.nobs, model = yuima@model)
                return(final_res)
            }
            else {
                yuima.warn("The variable Est.Incr is not correct. See qmle documentation for the allowed values ")
                final_res <- new("mle", call = call, coef = coef, 
                  fullcoef = unlist(mycoef), vcov = vcov, min = min, 
                  details = oout, minuslogl = minusquasilogl, 
                  method = method, nobs = yuima.nobs)
                return(final_res)
            }
        }
    }
    if (!is.CARMA(yuima)) {
        return(final_res)
    }
    else {
        param <- coef(final_res)
        observ <- yuima@data
        model <- yuima@model
        info <- model@info
        numb.ar <- info@p
        name.ar <- paste(info@ar.par, c(numb.ar:1), sep = "")
        ar.par <- param[name.ar]
        numb.ma <- info@q
        name.ma <- paste(info@ma.par, c(0:numb.ma), sep = "")
        ma.par <- param[name.ma]
        loc.par = NULL
        if (length(info@loc.par) != 0) {
            loc.par <- param[info@loc.par]
        }
        scale.par = NULL
        if (length(info@scale.par) != 0) {
            scale.par <- param[info@scale.par]
        }
        lin.par = NULL
        if (length(info@lin.par) != 0) {
            lin.par <- param[info@lin.par]
        }
        if (min(yuima.PhamBreton.Alg(ar.par[numb.ar:1])) >= 0) {
            cat("\n Stationarity condition is satisfied...\n Starting Estimation Increments ...\n")
        }
        else {
            yuima.warn("Insert constraints in Autoregressive parameters for enforcing stationarity")
            cat("\n Starting Estimation Increments ...\n")
        }
        ttt <- observ@zoo.data[[1]]
        tt <- index(ttt)
        y <- coredata(ttt)
        if (NoNeg.Noise == TRUE && (info@p == (info@q + 1))) {
            final_res@coef[mean.noise] <- mean(y)/tail(ma.par, 
                n = 1) * ar.par[1]
        }
        levy <- yuima.CarmaNoise(y, tt, ar.par, ma.par, loc.par, 
            scale.par, lin.par, NoNeg.Noise)
        inc.levy <- NULL
        if (!is.null(levy)) {
            inc.levy <- diff(t(levy))
        }
        if (Est.Incr == "Carma.Inc" || Est.Incr == "Incr") {
            inc.levy.fin <- zoo(inc.levy, tt[(1 + length(tt) - 
                length(inc.levy)):length(tt)])
            carma_final_res <- new("yuima.carma.qmle", call = call, 
                coef = coef, fullcoef = unlist(mycoef), vcov = vcov, 
                min = min, details = oout, minuslogl = minusquasilogl, 
                method = method, Incr.Lev = inc.levy.fin, model = yuima@model, 
                nobs = yuima.nobs, logL.Incr = NULL)
            return(carma_final_res)
        }
        cat("\nStarting Estimation parameter Noise ...\n")
        dummycovCarmapar <- vcov[unique(c(drift.par, diff.par)), 
            unique(c(drift.par, diff.par))]
        if (!is.null(loc.par)) {
            dummycovCarmapar <- vcov[unique(c(drift.par, diff.par, 
                info@loc.par)), unique(c(drift.par, diff.par, 
                info@loc.par))]
        }
        dummycovCarmaNoise <- vcov[unique(measure.par), unique(c(measure.par))]
        dummycoeffCarmapar <- coef[unique(c(drift.par, diff.par))]
        if (!is.null(loc.par)) {
            dummycoeffCarmapar <- coef[unique(c(drift.par, diff.par, 
                info@loc.par))]
        }
        dummycoeffCarmaNoise <- coef[unique(c(measure.par))]
        coef <- NULL
        coef <- c(dummycoeffCarmapar, dummycoeffCarmaNoise)
        names.par <- c(unique(c(drift.par, diff.par)), unique(c(measure.par)))
        if (!is.null(loc.par)) {
            names.par <- c(unique(c(drift.par, diff.par, info@loc.par)), 
                unique(c(measure.par)))
        }
        names(coef) <- names.par
        cov <- NULL
        cov <- matrix(0, length(names.par), length(names.par))
        rownames(cov) <- names.par
        colnames(cov) <- names.par
        if (is.null(loc.par)) {
            cov[unique(c(drift.par, diff.par)), unique(c(drift.par, 
                diff.par))] <- dummycovCarmapar
        }
        else {
            cov[unique(c(drift.par, diff.par, info@loc.par)), 
                unique(c(drift.par, diff.par, info@loc.par))] <- dummycovCarmapar
        }
        cov[unique(c(measure.par)), unique(c(measure.par))] <- dummycovCarmaNoise
        if (length(model@measure.type) != 0) {
            if (model@measure.type == "CP") {
                name.func.dummy <- as.character(model@measure$df$expr[1])
                name.func <- substr(name.func.dummy, 1, (nchar(name.func.dummy) - 
                  1))
                names.measpar <- as.vector(strsplit(name.func, 
                  ", "))[[1]][-1]
                valuemeasure <- as.numeric(names.measpar)
                name.int.dummy <- as.character(model@measure$intensity)
                valueintensity <- as.numeric(name.int.dummy)
                NaIdx <- which(!is.na(c(valueintensity, valuemeasure)))
                if (length(NaIdx) != 0) {
                  yuima.warn("the constrained MLE for levy increment will be implemented as soon as possible")
                  carma_final_res <- new("yuima.carma.qmle", 
                    call = call, coef = coef, fullcoef = unlist(mycoef), 
                    vcov = vcov, min = min, details = oout, minuslogl = minusquasilogl, 
                    method = method, Incr.Lev = inc.levy, model = yuima@model, 
                    logL.Incr = NULL)
                  return(carma_final_res)
                }
                if (aggregation == TRUE) {
                  if (floor(yuima@sampling@n/yuima@sampling@Terminal) != 
                    yuima@sampling@n/yuima@sampling@Terminal) {
                    yuima.stop("the n/Terminal in sampling information is not an integer. Set Aggregation=FALSE")
                  }
                  inc.levy1 <- diff(cumsum(c(0, inc.levy))[seq(from = 1, 
                    to = yuima@sampling@n[1], by = (yuima@sampling@n/yuima@sampling@Terminal)[1])])
                }
                else {
                  inc.levy1 <- inc.levy
                }
                names.measpar <- c(name.int.dummy, names.measpar)
                if (measurefunc == "dnorm") {
                  result.Lev <- yuima.Estimation.Lev(Increment.lev = inc.levy1, 
                    param0 = coef[names.measpar], fixed.carma = fixed.carma, 
                    lower.carma = lower.carma, upper.carma = upper.carma, 
                    measure = measurefunc, measure.type = model@measure.type, 
                    dt = env$h, aggregation = aggregation)
                }
                if (measurefunc == "dgamma") {
                  result.Lev <- yuima.Estimation.Lev(Increment.lev = inc.levy1, 
                    param0 = coef[names.measpar], fixed.carma = fixed.carma, 
                    lower.carma = lower.carma, upper.carma = upper.carma, 
                    measure = measurefunc, measure.type = model@measure.type, 
                    dt = env$h, aggregation = aggregation)
                }
                if (measurefunc == "dexp") {
                  result.Lev <- yuima.Estimation.Lev(Increment.lev = inc.levy1, 
                    param0 = coef[names.measpar], fixed.carma = fixed.carma, 
                    lower.carma = lower.carma, upper.carma = upper.carma, 
                    measure = measurefunc, measure.type = model@measure.type, 
                    dt = env$h, aggregation = aggregation)
                }
                Inc.Parm <- result.Lev$estLevpar
                IncVCOV <- result.Lev$covLev
                names(Inc.Parm)[NaIdx] <- measure.par
                rownames(IncVCOV)[NaIdx] <- as.character(measure.par)
                colnames(IncVCOV)[NaIdx] <- as.character(measure.par)
                coef <- NULL
                coef <- c(dummycoeffCarmapar, Inc.Parm)
                names.par <- names(coef)
                cov <- NULL
                cov <- matrix(0, length(names.par), length(names.par))
                rownames(cov) <- names.par
                colnames(cov) <- names.par
                if (is.null(loc.par)) {
                  cov[unique(c(drift.par, diff.par)), unique(c(drift.par, 
                    diff.par))] <- dummycovCarmapar
                }
                else {
                  cov[unique(c(drift.par, diff.par, info@loc.par)), 
                    unique(c(drift.par, diff.par, info@loc.par))] <- dummycovCarmapar
                }
                cov[names(Inc.Parm), names(Inc.Parm)] <- IncVCOV
            }
            if (yuima@model@measure.type == "code") {
                if (class(model@measure$df) == "yuima.law") {
                  valuemeasure <- "yuima.law"
                  NaIdx <- NULL
                }
                else {
                  name.func.dummy <- as.character(model@measure$df$expr[1])
                  name.func <- substr(name.func.dummy, 1, (nchar(name.func.dummy) - 
                    1))
                  names.measpar <- as.vector(strsplit(name.func, 
                    ", "))[[1]][-1]
                  valuemeasure <- as.numeric(names.measpar)
                  NaIdx <- which(!is.na(valuemeasure))
                }
                if (length(NaIdx) != 0) {
                  yuima.warn("the constrained MLE for levy increment will be implemented as soon as possible")
                  carma_final_res <- new("yuima.carma.qmle", 
                    call = call, coef = coef, fullcoef = unlist(mycoef), 
                    vcov = vcov, min = min, details = oout, minuslogl = minusquasilogl, 
                    method = method, Incr.Lev = inc.levy, model = yuima@model, 
                    logL.Incr = NULL)
                  return(carma_final_res)
                }
                if (aggregation == TRUE) {
                  if (all(floor(yuima@sampling@n/yuima@sampling@Terminal) != 
                    yuima@sampling@n/yuima@sampling@Terminal)) {
                    yuima.stop("the n/Terminal in sampling information is not an integer. Aggregation=FALSE is recommended")
                  }
                  inc.levy1 <- diff(cumsum(c(0, inc.levy))[seq(from = 1, 
                    to = yuima@sampling@n[1], by = (yuima@sampling@n/yuima@sampling@Terminal)[1])])
                }
                else {
                  inc.levy1 <- inc.levy
                }
                if (measurefunc == "yuima.law") {
                  dummyParMeas <- c(coef[measure.par], 1)
                  names(dummyParMeas) <- c(measure.par, yuima@model@time.variable)
                  cond <- length(dens(yuima@model@measure$df, 
                    x = as.numeric(inc.levy1), param = as.list(dummyParMeas)))
                  if (cond == 0) {
                    result.Lev <- list(estLevpar = coef[measure.par], 
                      covLev = matrix(NA, length(coef[measure.par]), 
                        length(coef[measure.par])))
                    yuima.warn("Levy measure parameters can not be estimated.")
                  }
                  else {
                    dummyMyfunMeas <- function(par, Law, Data, 
                      time, param.name, name.time) {
                      dummyParMeas <- c(par, time)
                      names(dummyParMeas) <- c(param.name, name.time)
                      v <- log(pmax(na.omit(dens(Law, x = Data, 
                        param = as.list(dummyParMeas))), 10^(-40)))
                      v1 <- v[!is.infinite(v)]
                      return(-sum(v1))
                    }
                    if (aggregation) {
                      mytime <- 1
                    }
                    else {
                      mytime <- yuima@sampling@delta
                      inc.levy1 <- as.numeric(inc.levy1)
                    }
                    prova <- optim(fn = dummyMyfunMeas, par = coef[measure.par], 
                      method = method, Law = yuima@model@measure$df, 
                      Data = inc.levy1, time = mytime, param.name = measure.par, 
                      name.time = yuima@model@time.variable)
                    Heeee <- optimHess(fn = dummyMyfunMeas, par = coef[measure.par], 
                      Law = yuima@model@measure$df, Data = inc.levy1, 
                      time = mytime, param.name = measure.par, 
                      name.time = yuima@model@time.variable)
                    result.Lev <- list(estLevpar = prova$par, 
                      covLev = solve(Heeee))
                  }
                }
                if (measurefunc == "rIG") {
                  result.Lev <- yuima.Estimation.Lev(Increment.lev = inc.levy1, 
                    param0 = coef[names.measpar], fixed.carma = fixed.carma, 
                    lower.carma = lower.carma, upper.carma = upper.carma, 
                    measure = measurefunc, measure.type = model@measure.type, 
                    dt = env$h, aggregation = aggregation)
                }
                if (measurefunc == "rNIG") {
                  result.Lev <- yuima.Estimation.Lev(Increment.lev = inc.levy1, 
                    param0 = coef[names.measpar], fixed.carma = fixed.carma, 
                    lower.carma = lower.carma, upper.carma = upper.carma, 
                    measure = measurefunc, measure.type = model@measure.type, 
                    dt = env$h, aggregation = aggregation)
                }
                if (measurefunc == "rbgamma") {
                  result.Lev <- list(estLevpar = coef[names.measpar], 
                    covLev = matrix(NA, length(coef[names.measpar]), 
                      length(coef[names.measpar])))
                }
                if (measurefunc == "rvgamma") {
                  result.Lev <- yuima.Estimation.Lev(Increment.lev = inc.levy1, 
                    param0 = coef[names.measpar], fixed.carma = fixed.carma, 
                    lower.carma = lower.carma, upper.carma = upper.carma, 
                    measure = measurefunc, measure.type = model@measure.type, 
                    dt = env$h, aggregation = aggregation)
                }
                Inc.Parm <- result.Lev$estLevpar
                IncVCOV <- result.Lev$covLev
                names(Inc.Parm)[NaIdx] <- measure.par
                rownames(IncVCOV)[NaIdx] <- as.character(measure.par)
                colnames(IncVCOV)[NaIdx] <- as.character(measure.par)
                coef <- NULL
                coef <- c(dummycoeffCarmapar, Inc.Parm)
                names.par <- names(coef)
                cov <- NULL
                cov <- matrix(0, length(names.par), length(names.par))
                rownames(cov) <- names.par
                colnames(cov) <- names.par
                if (is.null(loc.par)) {
                  cov[unique(c(drift.par, diff.par)), unique(c(drift.par, 
                    diff.par))] <- dummycovCarmapar
                }
                else {
                  cov[unique(c(drift.par, diff.par, info@loc.par)), 
                    unique(c(drift.par, diff.par, info@loc.par))] <- dummycovCarmapar
                }
                cov[names(Inc.Parm), names(Inc.Parm)] <- IncVCOV
            }
        }
        if (Est.Incr == "Carma.IncPar" || Est.Incr == "IncrPar") {
            inc.levy.fin <- zoo(inc.levy, tt[(1 + length(tt) - 
                length(inc.levy)):length(tt)])
            carma_final_res <- new("yuima.carma.qmle", call = call, 
                coef = coef, fullcoef = unlist(coef), vcov = cov, 
                min = min, details = oout, minuslogl = minusquasilogl, 
                method = method, Incr.Lev = inc.levy.fin, model = yuima@model, 
                nobs = yuima.nobs, logL.Incr = tryCatch(-result.Lev$value, 
                  error = function(theta) {
                    NULL
                  }))
        }
        else {
            if (Est.Incr == "Carma.Par" || Est.Incr == "NoIncr") {
                carma_final_res <- new("mle", call = call, coef = coef, 
                  fullcoef = unlist(coef), vcov = cov, min = min, 
                  details = oout, minuslogl = minusquasilogl, 
                  method = method, nobs = yuima.nobs)
            }
        }
        return(carma_final_res)
    }
}
<bytecode: 0x62c55f0>
<environment: namespace:yuima>
 --- function search by body ---
Function qmle in namespace yuima has this body.
 ----------- END OF FAILURE REPORT -------------- 
Error in if (class(rrr) != "try-error") vcov <- rrr : 
  the condition has length > 1
Calls: qmle
Execution halted