Running examples in 'MARSS-Ex.R' failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: CSEGriskfigure
> ### Title: Plot Extinction Risk Metrics
> ### Aliases: CSEGriskfigure
> ### Keywords: hplot
> 
> ### ** Examples
> 
> d <- harborSeal[,1:2]
> kem <- CSEGriskfigure(d,  datalogged = TRUE)
Analysis assumes that data and threshold are already logged
Using an percentage threshold for the extinction threshold
Threshold is 90 percent decline
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
MARSS
 --- call from context --- 
MARSSkfss(MLEobj.test)
 --- call from argument --- 
if (class(siginv) == "try-error") {
    if (any(diag.siginv1 != 0)) {
        Ck1 = try(kappa(siginv1[diag.siginv1 != 0, diag.siginv1 != 
            0, drop = FALSE]))
        Ck1 = ifelse(class(Ck1) == "try-error", "Inf", round(Ck1))
        msg1 = paste("Condition num. of siginv1[t=", t, "] = ", 
            Ck1, " ", sep = "")
    }
    msg2 = ""
    if (any(diag.R != 0) & (t == 1 || "R" %in% time.varying)) {
        Ck4 = try(kappa((diag(1, n)[diag.R != 0, ]) %*% R %*% 
            t(diag(1, n)[diag.R != 0, ])))
        Ck4 = ifelse(class(Ck4) == "try-error", "Inf", round(Ck4))
        msg2 = paste("Condition num. of R = ", Ck4, " ", sep = "")
    }
    return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: chol(Z%*%Vtt1[,,", 
        t, "]%*%t(Z)+R) error. ", msg1, " ", msg2, "\n", sep = "")))
}
 --- R stacktrace ---
where 1: MARSSkfss(MLEobj.test)
where 2: doTryCatch(return(expr), name, parentenv, handler)
where 3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
where 4: tryCatchList(expr, classes, parentenv, handlers)
where 5: tryCatch(expr, error = function(e) {
    call <- conditionCall(e)
    if (!is.null(call)) {
        if (identical(call[[1L]], quote(doTryCatch))) 
            call <- sys.call(-4L)
        dcall <- deparse(call)[1L]
        prefix <- paste("Error in", dcall, ": ")
        LONG <- 75L
        sm <- strsplit(conditionMessage(e), "\n")[[1L]]
        w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")
        if (is.na(w)) 
            w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], 
                type = "b")
        if (w > LONG) 
            prefix <- paste0(prefix, "\n  ")
    }
    else prefix <- "Error : "
    msg <- paste0(prefix, conditionMessage(e), "\n")
    .Internal(seterrmessage(msg[1L]))
    if (!silent && isTRUE(getOption("show.error.messages"))) {
        cat(msg, file = outFile)
        .Internal(printDeferredWarnings())
    }
    invisible(structure(msg, class = "try-error", condition = e))
})
where 6: try(MARSSkfss(MLEobj.test), silent = TRUE)
where 7: MARSS(dat, model = list(U = matrix("U")), silent = TRUE)
where 8: CSEGriskfigure(d, datalogged = TRUE)

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (MLEobj) 
{
    condition.limit = 1e+10
    condition.limit.Ft = 1e+05
    MODELobj = MLEobj$marss
    debugkf = MLEobj$control$trace
    n = dim(MODELobj$data)[1]
    TT = dim(MODELobj$data)[2]
    m = dim(MODELobj$fixed$x0)[1]
    YM = matrix(as.numeric(!is.na(MODELobj$data)), n, TT)
    y = MODELobj$data
    y[YM == 0] = 0
    if (MODELobj$tinitx == 1) {
        init.state = "x10"
    }
    else {
        init.state = "x00"
    }
    msg = NULL
    I.m = diag(1, m)
    I.n = diag(1, n)
    Vtt = Vtt1 = VtT = Vtt1T = J = array(0, dim = c(m, m, TT))
    xtt = xtt1 = xtT = matrix(0, m, TT)
    vt = matrix(0, n, TT)
    Ft = array(0, dim = c(n, n, TT))
    Kt = array(0, dim = c(m, n, TT))
    model.elem = names(MODELobj$fixed)
    time.varying = c()
    for (elem in model.elem) {
        if ((dim(MODELobj$free[[elem]])[3] != 1) | (dim(MODELobj$fixed[[elem]])[3] != 
            1)) 
            time.varying = c(time.varying, elem)
    }
    pari = parmat(MLEobj, t = 1)
    Z = pari$Z
    A = pari$A
    B = pari$B
    U = pari$U
    x0 = pari$x0
    R = tcrossprod(pari$H %*% pari$R, pari$H)
    Q = tcrossprod(pari$G %*% pari$Q, pari$G)
    V0 = tcrossprod(pari$L %*% pari$V0, pari$L)
    if (n == 1) {
        diag.R = unname(R)
    }
    else {
        diag.R = unname(R)[1 + 0:(n - 1) * (n + 1)]
    }
    OmgRVtt = I.m
    diag.OmgRVtt = rep(1, m)
    if (any(diag.R == 0)) {
        Z.R0 = Z[diag.R == 0, , drop = FALSE]
        Z.R0.n0 = Z.R0[, colSums(Z.R0) != 0, drop = FALSE]
        if (dim(Z.R0.n0)[1] == dim(Z.R0.n0)[2]) {
            Ck = try(solve(Z.R0.n0))
            if (class(Ck) == "try-error") {
                return(list(ok = FALSE, errors = "Some R diagonal elements are 0, but Z is such that model is indeterminate in this case."))
            }
            else {
                OmgRVtt = diag(ifelse(colSums(Z.R0) != 0, 0, 
                  1), m)
            }
        }
        else {
            if (dim(Z.R0.n0)[1] > dim(Z.R0.n0)[2]) {
                return(list(ok = FALSE, errors = "Some R diagonal elements are 0, and Z is such that model is over-determined."))
            }
            else {
                OmgRVtt = diag(ifelse(colSums(Z.R0) != 0, 0, 
                  1), m)
            }
        }
        diag.OmgRVtt = takediag(OmgRVtt)
    }
    if (m == 1) {
        diag.Q = unname(Q)
    }
    else {
        diag.Q = unname(Q)[1 + 0:(m - 1) * (m + 1)]
    }
    t.B = matrix(B, m, m, byrow = TRUE)
    for (t in 1:TT) {
        if (length(time.varying) != 0) {
            pari[time.varying] = parmat(MLEobj, time.varying, 
                t = t)
            Z = pari$Z
            A = pari$A
            B = pari$B
            U = pari$U
            if ("R" %in% time.varying | "H" %in% time.varying) {
                R = tcrossprod(pari$H %*% pari$R, pari$H)
                if (n == 1) {
                  diag.R = unname(R)
                }
                else {
                  diag.R = unname(R)[1 + 0:(n - 1) * (n + 1)]
                }
                OmgRVtt = I.m
                diag.OmgRVtt = rep(1, m)
                if (any(diag.R == 0)) {
                  Z.R0 = Z[diag.R == 0, , drop = FALSE]
                  Z.R0.n0 = Z.R0[, colSums(Z.R0) != 0, drop = FALSE]
                  if (dim(Z.R0.n0)[1] == dim(Z.R0.n0)[2]) {
                    Ck = try(solve(Z.R0.n0))
                    if (class(Ck) == "try-error") {
                      return(list(ok = FALSE, errors = "Some R diagonal elements are 0, but Z is such that model is indeterminate in this case."))
                    }
                    else {
                      OmgRVtt = diag(ifelse(colSums(Z.R0) != 
                        0, 0, 1), m)
                    }
                  }
                  else {
                    if (dim(Z.R0.n0)[1] > dim(Z.R0.n0)[2]) {
                      return(list(ok = FALSE, errors = "Some R diagonal elements are 0, and Z is such that model is over-determined."))
                    }
                  }
                  diag.OmgRVtt = takediag(OmgRVtt)
                }
            }
            if ("Q" %in% time.varying | "G" %in% time.varying) {
                Q = tcrossprod(pari$G %*% pari$Q, pari$G)
                if (m == 1) {
                  diag.Q = unname(Q)
                }
                else {
                  diag.Q = unname(Q)[1 + 0:(m - 1) * (m + 1)]
                }
            }
            if ("B" %in% time.varying) 
                t.B = matrix(B, m, m, byrow = TRUE)
        }
        if (any(YM[, t] == 0)) {
            Mt = I.n
            Mt[YM[, t] == 0, ] = 0
            I.2 = I.n - Mt
            Zt = Mt %*% Z
            At = Mt %*% A
            Omg1 = I.n[YM[, t] == 1, , drop = FALSE]
            t.Omg1 = I.n[, YM[, t] == 1, drop = FALSE]
            Rt = Mt %*% R %*% Mt + I.2 %*% R %*% I.2
        }
        else {
            Zt = Z
            Rt = R
            At = A
            Omg1 = I.n
            t.Omg1 = I.n
            Mt = I.n
        }
        if (m * n == 1) 
            t.Zt = Zt
        else t.Zt = matrix(Zt, m, n, byrow = TRUE)
        if (t == 1) {
            if (init.state == "x00") {
                xtt1[, 1] = B %*% x0 + U
                Vtt1[, , 1] = B %*% V0 %*% t.B + Q
            }
            if (init.state == "x10") {
                xtt1[, 1] = x0
                Vtt1[, , 1] = V0
            }
        }
        else {
            xtt1[, t] = B %*% xtt[, t - 1, drop = FALSE] + U
            Vtt1[, , t] = B %*% Vtt[, , t - 1] %*% t.B + Q
        }
        if (m != 1) 
            Vtt1[, , t] = symm(Vtt1[, , t])
        siginv1 = Zt %*% Vtt1[, , t] %*% t.Zt + Rt
        if (debugkf == -1) {
            siginv = pcholinv(siginv1)
        }
        else {
            siginv = try(pcholinv(siginv1), silent = TRUE)
            if (n == 1) 
                diag.siginv1 = unname(siginv1)
            else diag.siginv1 = unname(siginv1)[1 + 0:(n - 1) * 
                (n + 1)]
            if (class(siginv) == "try-error") {
                if (any(diag.siginv1 != 0)) {
                  Ck1 = try(kappa(siginv1[diag.siginv1 != 0, 
                    diag.siginv1 != 0, drop = FALSE]))
                  Ck1 = ifelse(class(Ck1) == "try-error", "Inf", 
                    round(Ck1))
                  msg1 = paste("Condition num. of siginv1[t=", 
                    t, "] = ", Ck1, " ", sep = "")
                }
                msg2 = ""
                if (any(diag.R != 0) & (t == 1 || "R" %in% time.varying)) {
                  Ck4 = try(kappa((diag(1, n)[diag.R != 0, ]) %*% 
                    R %*% t(diag(1, n)[diag.R != 0, ])))
                  Ck4 = ifelse(class(Ck4) == "try-error", "Inf", 
                    round(Ck4))
                  msg2 = paste("Condition num. of R = ", Ck4, 
                    " ", sep = "")
                }
                return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: chol(Z%*%Vtt1[,,", 
                  t, "]%*%t(Z)+R) error. ", msg1, " ", msg2, 
                  "\n", sep = "")))
            }
        }
        if (n != 1) 
            siginv = symm(siginv)
        Kt[, , t] = Vtt1[, , t] %*% t.Zt %*% siginv
        Kt.tmp = sub3D(Kt, t = t)
        vt[, t] = y[, t, drop = FALSE] - (Zt %*% xtt1[, t, drop = FALSE] + 
            At)
        xtt[, t] = xtt1[, t, drop = FALSE] + Kt.tmp %*% vt[, 
            t, drop = FALSE]
        Vtt[, , t] = Vtt1[, , t] - Kt.tmp %*% Zt %*% Vtt1[, , 
            t]
        if (m != 1) 
            Vtt[, , t] = symm(Vtt[, , t])
        OmgRVtt.t = OmgRVtt
        if (any(diag.OmgRVtt == 0)) 
            diag(OmgRVtt.t) = diag.OmgRVtt + t(!(Z == 0)) %*% 
                (diag.R == 0 & YM[, t] == 0)
        Vtt[, , t] = OmgRVtt.t %*% Vtt[, , t] %*% OmgRVtt.t
        R_mod = (I.n - Mt) + Mt %*% R %*% Mt
        Ft[, , t] = Zt %*% Vtt1[, , t] %*% t.Zt + R_mod
        if (n != 1) 
            Ft[, , t] = symm(Ft[, , t])
        if (debugkf > 0) {
            Ck1 = Ck2 = Ck3 = Ck4 = 1
            if (!all(diag.siginv1 == 0)) 
                Ck1 = kappa(siginv1[diag.siginv1 != 0, diag.siginv1 != 
                  0, drop = FALSE])
            if (!all(diag.Q == 0)) 
                Ck2 = kappa(Vtt1[diag.Q != 0, diag.Q != 0, t])
            if (!all(diag.R == 0) & t > 1) 
                Ck3 = kappa(Ft[diag.R != 0, diag.R != 0, t])
            if (Ck1 > condition.limit && !all(Kt[, , t] == 0)) 
                msg = rbind(msg, paste("MARSSkfss: solution is becoming unstable.  Condition num. of siginv1[t=", 
                  t, "] = ", round(Ck1), "\n", sep = ""))
            if (Ck2 > condition.limit && t > 1) 
                msg = rbind(msg, paste("MARSSkfss: solution is becoming unstable.  Condition num. of Vtt1[t=", 
                  t, "] = ", round(Ck2), "\n", sep = ""))
            if (Ck3 > condition.limit.Ft) {
                if (!all(diag.R == 0)) 
                  Ck4 = kappa(R[diag.R != 0, diag.R != 0])
                msg = rbind(msg, paste("MARSSkfss: logLik computation is becoming unstable.  Condition num. of Sigma[t=", 
                  t, "] = ", round(Ck3), " and of R = ", round(Ck4), 
                  ".\n", sep = ""))
            }
        }
        if (m == 1) 
            diag.Vtt = unname(Vtt[, , t])
        else diag.Vtt = unname(Vtt[, , t])[1 + 0:(m - 1) * (m + 
            1)]
        if (any(diag.Vtt < 0)) {
            return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: soln became unstable and negative values appeared on the diagonal of Vtt at t=", 
                t, ".\n", sep = "")))
        }
    }
    xtT[, TT] = xtt[, TT, drop = FALSE]
    VtT[, , TT] = Vtt[, , TT]
    s = seq(TT, 2)
    for (i in 1:(TT - 1)) {
        t = s[i]
        if ("B" %in% time.varying) {
            B = parmat(MLEobj, "B", t = t)$B
            if (m == 1) 
                t.B = B
            else t.B = matrix(B, m, m, byrow = TRUE)
        }
        if ("Q" %in% time.varying | "G" %in% time.varying) {
            Q = parmat(MLEobj, "Q", t = t)$Q
            G = parmat(MLEobj, "G", t = t)$G
            Q = tcrossprod(G %*% Q, G)
            if (m == 1) {
                diag.Q = unname(Q)
            }
            else {
                diag.Q = unname(Q)[1 + 0:(m - 1) * (m + 1)]
            }
        }
        if (m == 1) 
            diag.Vtt1 = unname(Vtt1[, , t])
        else diag.Vtt1 = unname(Vtt1[, , t])[1 + 0:(m - 1) * 
            (m + 1)]
        if (any(diag.Vtt1 < 0)) 
            return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: soln became unstable and negative values appeared on the diagonal of Vtt1.\n")))
        if (debugkf != -1 & any(diag.Vtt1 == 0)) {
            Q0s = all(which(diag.Vtt1 == 0) %in% which(diag.Q == 
                0))
            if (!Q0s && (init.state == "x00" || (init.state == 
                "x10" && t > 1))) {
                return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: soln became unstable when zeros appeared on the diagonal of Vtt1 at t=", 
                  t, ".\n")))
            }
        }
        if (m == 1) {
            Vinv = pcholinv(matrix(Vtt1[, , t], 1, 1))
        }
        else {
            Vinv = pcholinv(Vtt1[, , t])
            Vinv = symm(Vinv)
        }
        J[, , t - 1] = Vtt[, , t - 1] %*% t.B %*% Vinv
        xtT[, t - 1] = xtt[, t - 1, drop = FALSE] + J[, , t - 
            1] %*% (xtT[, t, drop = FALSE] - xtt1[, t, drop = FALSE])
        if (m == 1) 
            t.J = J[, , t - 1]
        else t.J = matrix(J[, , t - 1], m, m, byrow = TRUE)
        VtT[, , t - 1] = Vtt[, , t - 1] + J[, , t - 1] %*% (VtT[, 
            , t] - Vtt1[, , t]) %*% t.J
    }
    if (init.state == "x00") {
        if ("B" %in% time.varying) {
            B = parmat(MLEobj, "B", t = 1)$B
            if (m == 1) 
                t.B = B
            else t.B = matrix(B, m, m, byrow = TRUE)
        }
        if ("Q" %in% time.varying) {
            Q = parmat(MLEobj, "Q", t = 1)$Q
            if (m == 1) {
                diag.Q = unname(Q)
            }
            else {
                diag.Q = takediag(unname(Q))
            }
        }
        diag.Vtt1 = unname(Vtt1[, , 1])
        diag.Vtt1 = diag.Vtt1[1 + 0:(m - 1) * (m + 1)]
        if (debugkf != -1 & any(diag.Vtt1 == 0)) {
            Q0s = identical(which(diag.Q == 0), which(diag.Vtt1 == 
                0))
            if (!Q0s && (init.state == "x00" || (init.state == 
                "x10" && t > 1))) {
                return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: soln became unstable when zeros appeared on the diagonal of Vtt1 at t=1.\n")))
            }
        }
        if (m == 1) {
            Vinv = pcholinv(matrix(Vtt1[, , 1], 1, 1))
        }
        else {
            Vinv = pcholinv(Vtt1[, , 1])
            Vinv = symm(Vinv)
        }
        J0 = V0 %*% t.B %*% Vinv
        x0T = x0 + J0 %*% (xtT[, 1, drop = FALSE] - xtt1[, 1, 
            drop = FALSE])
        V0T = V0 + J0 %*% (VtT[, , 1] - Vtt1[, , 1]) %*% t(J0)
        V0T = symm(V0T)
    }
    if (init.state == "x10") {
        if (m == 1) 
            J0 = matrix(J[, , 1], 1, 1)
        else J0 = J[, , 1]
        x0T = xtT[, 1, drop = FALSE]
        if (m == 1) 
            V0T = matrix(VtT[, , 1], 1, 1)
        else V0T = VtT[, , 1]
    }
    if ("Z" %in% time.varying) {
        Z = parmat(MLEobj, "Z", t = TT)$Z
    }
    Zt = Z
    Zt[YM[, TT] == 0, ] = 0
    if ("B" %in% time.varying) {
        B = parmat(MLEobj, "B", t = TT)$B
    }
    KT = matrix(Kt[, , TT], m, n)
    Vtt1T[, , TT] = (I.m - KT %*% Zt) %*% B %*% Vtt[, , TT - 
        1]
    s = seq(TT, 3)
    for (i in 1:(TT - 2)) {
        t = s[i]
        if ("B" %in% time.varying) {
            B = parmat(MLEobj, "B", t = t)$B
        }
        if (m == 1) 
            t.J = J[, , t - 2]
        else t.J = matrix(J[, , t - 2], m, m, byrow = TRUE)
        Vtt1T[, , t - 1] = Vtt[, , t - 1] %*% t.J + J[, , t - 
            1] %*% (Vtt1T[, , t] - B %*% Vtt[, , t - 1]) %*% 
            t.J
    }
    if (init.state == "x00") {
        if ("B" %in% time.varying) {
            B = parmat(MLEobj, "B", t = 2)$B
        }
        Vtt1T[, , 1] = Vtt[, , 1] %*% t(J0) + J[, , 1] %*% (Vtt1T[, 
            , 2] - B %*% Vtt[, , 1]) %*% t(J0)
    }
    if (init.state == "x10") 
        Vtt1T[, , 1] = NA
    rtn.list = list(xtT = xtT, VtT = VtT, Vtt1T = Vtt1T, x0T = x0T, 
        V0T = V0T, Vtt = Vtt, Vtt1 = Vtt1, J = J, J0 = J0, Kt = Kt, 
        xtt1 = xtt1, xtt = xtt, Innov = vt, Sigma = Ft)
    loglike = -sum(YM)/2 * log(2 * base::pi)
    for (t in 1:TT) {
        if (n == 1) 
            diag.Ft = Ft[, , t]
        else diag.Ft = unname(Ft[, , t])[1 + 0:(n - 1) * (n + 
            1)]
        if (any(diag.Ft == 0)) {
            if (t > 1 || (t == 1 & init.state == "x00")) {
                return(c(rtn.list, list(ok = FALSE, logLik = NaN, 
                  errors = paste("One of the diagonal elements of Sigma[,,", 
                    t, "]=0. That should never happen when t>1 or t=1 and tinitx=0.  \n Are both Q[i,i] and R[i,i] being set to 0?\n", 
                    sep = ""))))
            }
            else {
                OmgF1 = makediag(1, n)[diag.Ft != 0, , drop = FALSE]
                loglike = loglike + sum(diag.Ft == 0 & YM[, 1] != 
                  0)/2 * log(2 * base::pi)
                if (dim(OmgF1)[1] == 0) {
                  detFt = 1
                }
                else {
                  if (length(OmgF1 %*% Ft[, , t] %*% t(OmgF1)) == 
                    1) 
                    detFt = OmgF1 %*% Ft[, , t] %*% t(OmgF1)
                  else detFt = det(OmgF1 %*% Ft[, , t] %*% t(OmgF1))
                }
                if (n == 1) {
                  Ftinv = pcholinv(matrix(Ft[, , t], 1, 1))
                }
                else {
                  Ftinv = pcholinv(Ft[, , t])
                  Ftinv = symm(Ftinv)
                }
            }
        }
        else {
            if (n == 1) {
                detFt = Ft[, , t]
                Ftinv = 1/Ft[, , t]
            }
            else {
                detFt = det(Ft[, , t])
                Ftinv = chol2inv(chol(Ft[, , t]))
                Ftinv = symm(Ftinv)
            }
        }
        if (detFt < 0 || !is.finite(log(detFt))) 
            return(c(rtn.list, list(ok = FALSE, logLik = NaN, 
                Sigma = Ft, errors = paste("Stopped in MARSSkfss: log(det(Ft[,,", 
                  t, "]))=NA.\n", sep = ""))))
        loglike = loglike - (1/2) %*% matrix(vt[, t], 1, n) %*% 
            Ftinv %*% vt[, t, drop = FALSE] - (1/2) * log(detFt)
        loglike = as.vector(loglike)
    }
    if (!is.finite(loglike)) 
        return(c(rtn.list, list(ok = FALSE, errors = paste("Stopped in MARSSkfss: loglike computed to NA.\n"))))
    return(c(rtn.list, list(logLik = loglike, ok = TRUE, errors = msg)))
}
<bytecode: 0xc99e60>
<environment: namespace:MARSS>
 --- function search by body ---
Function MARSSkfss in namespace MARSS has this body.
 ----------- END OF FAILURE REPORT -------------- 
Error: Stopped in MARSS() before fitting because MARSSkfss stopped.  Something is wrong with 
 the model structure that prevents Kalman filter running.
 Try using control$trace=-1 and fit=FALSE and then look at the model that MARSS is trying to fit.
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
MARSS
 --- call from context --- 
MARSSkfss(MLEobj)
 --- call from argument --- 
if (class(siginv) == "try-error") {
    if (any(diag.siginv1 != 0)) {
        Ck1 = try(kappa(siginv1[diag.siginv1 != 0, diag.siginv1 != 
            0, drop = FALSE]))
        Ck1 = ifelse(class(Ck1) == "try-error", "Inf", round(Ck1))
        msg1 = paste("Condition num. of siginv1[t=", t, "] = ", 
            Ck1, " ", sep = "")
    }
    msg2 = ""
    if (any(diag.R != 0) & (t == 1 || "R" %in% time.varying)) {
        Ck4 = try(kappa((diag(1, n)[diag.R != 0, ]) %*% R %*% 
            t(diag(1, n)[diag.R != 0, ])))
        Ck4 = ifelse(class(Ck4) == "try-error", "Inf", round(Ck4))
        msg2 = paste("Condition num. of R = ", Ck4, " ", sep = "")
    }
    return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: chol(Z%*%Vtt1[,,", 
        t, "]%*%t(Z)+R) error. ", msg1, " ", msg2, "\n", sep = "")))
}
 --- R stacktrace ---
where 1: MARSSkfss(MLEobj)
where 2: MARSSharveyobsFI(MLEobj)
where 3: MARSSFisherI(MLEobj, method = method)
where 4: MARSShessian(MLEobj, method = hessian.fun)
where 5: MARSSparamCIs(kem)
where 6: CSEGriskfigure(d, datalogged = TRUE)

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (MLEobj) 
{
    condition.limit = 1e+10
    condition.limit.Ft = 1e+05
    MODELobj = MLEobj$marss
    debugkf = MLEobj$control$trace
    n = dim(MODELobj$data)[1]
    TT = dim(MODELobj$data)[2]
    m = dim(MODELobj$fixed$x0)[1]
    YM = matrix(as.numeric(!is.na(MODELobj$data)), n, TT)
    y = MODELobj$data
    y[YM == 0] = 0
    if (MODELobj$tinitx == 1) {
        init.state = "x10"
    }
    else {
        init.state = "x00"
    }
    msg = NULL
    I.m = diag(1, m)
    I.n = diag(1, n)
    Vtt = Vtt1 = VtT = Vtt1T = J = array(0, dim = c(m, m, TT))
    xtt = xtt1 = xtT = matrix(0, m, TT)
    vt = matrix(0, n, TT)
    Ft = array(0, dim = c(n, n, TT))
    Kt = array(0, dim = c(m, n, TT))
    model.elem = names(MODELobj$fixed)
    time.varying = c()
    for (elem in model.elem) {
        if ((dim(MODELobj$free[[elem]])[3] != 1) | (dim(MODELobj$fixed[[elem]])[3] != 
            1)) 
            time.varying = c(time.varying, elem)
    }
    pari = parmat(MLEobj, t = 1)
    Z = pari$Z
    A = pari$A
    B = pari$B
    U = pari$U
    x0 = pari$x0
    R = tcrossprod(pari$H %*% pari$R, pari$H)
    Q = tcrossprod(pari$G %*% pari$Q, pari$G)
    V0 = tcrossprod(pari$L %*% pari$V0, pari$L)
    if (n == 1) {
        diag.R = unname(R)
    }
    else {
        diag.R = unname(R)[1 + 0:(n - 1) * (n + 1)]
    }
    OmgRVtt = I.m
    diag.OmgRVtt = rep(1, m)
    if (any(diag.R == 0)) {
        Z.R0 = Z[diag.R == 0, , drop = FALSE]
        Z.R0.n0 = Z.R0[, colSums(Z.R0) != 0, drop = FALSE]
        if (dim(Z.R0.n0)[1] == dim(Z.R0.n0)[2]) {
            Ck = try(solve(Z.R0.n0))
            if (class(Ck) == "try-error") {
                return(list(ok = FALSE, errors = "Some R diagonal elements are 0, but Z is such that model is indeterminate in this case."))
            }
            else {
                OmgRVtt = diag(ifelse(colSums(Z.R0) != 0, 0, 
                  1), m)
            }
        }
        else {
            if (dim(Z.R0.n0)[1] > dim(Z.R0.n0)[2]) {
                return(list(ok = FALSE, errors = "Some R diagonal elements are 0, and Z is such that model is over-determined."))
            }
            else {
                OmgRVtt = diag(ifelse(colSums(Z.R0) != 0, 0, 
                  1), m)
            }
        }
        diag.OmgRVtt = takediag(OmgRVtt)
    }
    if (m == 1) {
        diag.Q = unname(Q)
    }
    else {
        diag.Q = unname(Q)[1 + 0:(m - 1) * (m + 1)]
    }
    t.B = matrix(B, m, m, byrow = TRUE)
    for (t in 1:TT) {
        if (length(time.varying) != 0) {
            pari[time.varying] = parmat(MLEobj, time.varying, 
                t = t)
            Z = pari$Z
            A = pari$A
            B = pari$B
            U = pari$U
            if ("R" %in% time.varying | "H" %in% time.varying) {
                R = tcrossprod(pari$H %*% pari$R, pari$H)
                if (n == 1) {
                  diag.R = unname(R)
                }
                else {
                  diag.R = unname(R)[1 + 0:(n - 1) * (n + 1)]
                }
                OmgRVtt = I.m
                diag.OmgRVtt = rep(1, m)
                if (any(diag.R == 0)) {
                  Z.R0 = Z[diag.R == 0, , drop = FALSE]
                  Z.R0.n0 = Z.R0[, colSums(Z.R0) != 0, drop = FALSE]
                  if (dim(Z.R0.n0)[1] == dim(Z.R0.n0)[2]) {
                    Ck = try(solve(Z.R0.n0))
                    if (class(Ck) == "try-error") {
                      return(list(ok = FALSE, errors = "Some R diagonal elements are 0, but Z is such that model is indeterminate in this case."))
                    }
                    else {
                      OmgRVtt = diag(ifelse(colSums(Z.R0) != 
                        0, 0, 1), m)
                    }
                  }
                  else {
                    if (dim(Z.R0.n0)[1] > dim(Z.R0.n0)[2]) {
                      return(list(ok = FALSE, errors = "Some R diagonal elements are 0, and Z is such that model is over-determined."))
                    }
                  }
                  diag.OmgRVtt = takediag(OmgRVtt)
                }
            }
            if ("Q" %in% time.varying | "G" %in% time.varying) {
                Q = tcrossprod(pari$G %*% pari$Q, pari$G)
                if (m == 1) {
                  diag.Q = unname(Q)
                }
                else {
                  diag.Q = unname(Q)[1 + 0:(m - 1) * (m + 1)]
                }
            }
            if ("B" %in% time.varying) 
                t.B = matrix(B, m, m, byrow = TRUE)
        }
        if (any(YM[, t] == 0)) {
            Mt = I.n
            Mt[YM[, t] == 0, ] = 0
            I.2 = I.n - Mt
            Zt = Mt %*% Z
            At = Mt %*% A
            Omg1 = I.n[YM[, t] == 1, , drop = FALSE]
            t.Omg1 = I.n[, YM[, t] == 1, drop = FALSE]
            Rt = Mt %*% R %*% Mt + I.2 %*% R %*% I.2
        }
        else {
            Zt = Z
            Rt = R
            At = A
            Omg1 = I.n
            t.Omg1 = I.n
            Mt = I.n
        }
        if (m * n == 1) 
            t.Zt = Zt
        else t.Zt = matrix(Zt, m, n, byrow = TRUE)
        if (t == 1) {
            if (init.state == "x00") {
                xtt1[, 1] = B %*% x0 + U
                Vtt1[, , 1] = B %*% V0 %*% t.B + Q
            }
            if (init.state == "x10") {
                xtt1[, 1] = x0
                Vtt1[, , 1] = V0
            }
        }
        else {
            xtt1[, t] = B %*% xtt[, t - 1, drop = FALSE] + U
            Vtt1[, , t] = B %*% Vtt[, , t - 1] %*% t.B + Q
        }
        if (m != 1) 
            Vtt1[, , t] = symm(Vtt1[, , t])
        siginv1 = Zt %*% Vtt1[, , t] %*% t.Zt + Rt
        if (debugkf == -1) {
            siginv = pcholinv(siginv1)
        }
        else {
            siginv = try(pcholinv(siginv1), silent = TRUE)
            if (n == 1) 
                diag.siginv1 = unname(siginv1)
            else diag.siginv1 = unname(siginv1)[1 + 0:(n - 1) * 
                (n + 1)]
            if (class(siginv) == "try-error") {
                if (any(diag.siginv1 != 0)) {
                  Ck1 = try(kappa(siginv1[diag.siginv1 != 0, 
                    diag.siginv1 != 0, drop = FALSE]))
                  Ck1 = ifelse(class(Ck1) == "try-error", "Inf", 
                    round(Ck1))
                  msg1 = paste("Condition num. of siginv1[t=", 
                    t, "] = ", Ck1, " ", sep = "")
                }
                msg2 = ""
                if (any(diag.R != 0) & (t == 1 || "R" %in% time.varying)) {
                  Ck4 = try(kappa((diag(1, n)[diag.R != 0, ]) %*% 
                    R %*% t(diag(1, n)[diag.R != 0, ])))
                  Ck4 = ifelse(class(Ck4) == "try-error", "Inf", 
                    round(Ck4))
                  msg2 = paste("Condition num. of R = ", Ck4, 
                    " ", sep = "")
                }
                return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: chol(Z%*%Vtt1[,,", 
                  t, "]%*%t(Z)+R) error. ", msg1, " ", msg2, 
                  "\n", sep = "")))
            }
        }
        if (n != 1) 
            siginv = symm(siginv)
        Kt[, , t] = Vtt1[, , t] %*% t.Zt %*% siginv
        Kt.tmp = sub3D(Kt, t = t)
        vt[, t] = y[, t, drop = FALSE] - (Zt %*% xtt1[, t, drop = FALSE] + 
            At)
        xtt[, t] = xtt1[, t, drop = FALSE] + Kt.tmp %*% vt[, 
            t, drop = FALSE]
        Vtt[, , t] = Vtt1[, , t] - Kt.tmp %*% Zt %*% Vtt1[, , 
            t]
        if (m != 1) 
            Vtt[, , t] = symm(Vtt[, , t])
        OmgRVtt.t = OmgRVtt
        if (any(diag.OmgRVtt == 0)) 
            diag(OmgRVtt.t) = diag.OmgRVtt + t(!(Z == 0)) %*% 
                (diag.R == 0 & YM[, t] == 0)
        Vtt[, , t] = OmgRVtt.t %*% Vtt[, , t] %*% OmgRVtt.t
        R_mod = (I.n - Mt) + Mt %*% R %*% Mt
        Ft[, , t] = Zt %*% Vtt1[, , t] %*% t.Zt + R_mod
        if (n != 1) 
            Ft[, , t] = symm(Ft[, , t])
        if (debugkf > 0) {
            Ck1 = Ck2 = Ck3 = Ck4 = 1
            if (!all(diag.siginv1 == 0)) 
                Ck1 = kappa(siginv1[diag.siginv1 != 0, diag.siginv1 != 
                  0, drop = FALSE])
            if (!all(diag.Q == 0)) 
                Ck2 = kappa(Vtt1[diag.Q != 0, diag.Q != 0, t])
            if (!all(diag.R == 0) & t > 1) 
                Ck3 = kappa(Ft[diag.R != 0, diag.R != 0, t])
            if (Ck1 > condition.limit && !all(Kt[, , t] == 0)) 
                msg = rbind(msg, paste("MARSSkfss: solution is becoming unstable.  Condition num. of siginv1[t=", 
                  t, "] = ", round(Ck1), "\n", sep = ""))
            if (Ck2 > condition.limit && t > 1) 
                msg = rbind(msg, paste("MARSSkfss: solution is becoming unstable.  Condition num. of Vtt1[t=", 
                  t, "] = ", round(Ck2), "\n", sep = ""))
            if (Ck3 > condition.limit.Ft) {
                if (!all(diag.R == 0)) 
                  Ck4 = kappa(R[diag.R != 0, diag.R != 0])
                msg = rbind(msg, paste("MARSSkfss: logLik computation is becoming unstable.  Condition num. of Sigma[t=", 
                  t, "] = ", round(Ck3), " and of R = ", round(Ck4), 
                  ".\n", sep = ""))
            }
        }
        if (m == 1) 
            diag.Vtt = unname(Vtt[, , t])
        else diag.Vtt = unname(Vtt[, , t])[1 + 0:(m - 1) * (m + 
            1)]
        if (any(diag.Vtt < 0)) {
            return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: soln became unstable and negative values appeared on the diagonal of Vtt at t=", 
                t, ".\n", sep = "")))
        }
    }
    xtT[, TT] = xtt[, TT, drop = FALSE]
    VtT[, , TT] = Vtt[, , TT]
    s = seq(TT, 2)
    for (i in 1:(TT - 1)) {
        t = s[i]
        if ("B" %in% time.varying) {
            B = parmat(MLEobj, "B", t = t)$B
            if (m == 1) 
                t.B = B
            else t.B = matrix(B, m, m, byrow = TRUE)
        }
        if ("Q" %in% time.varying | "G" %in% time.varying) {
            Q = parmat(MLEobj, "Q", t = t)$Q
            G = parmat(MLEobj, "G", t = t)$G
            Q = tcrossprod(G %*% Q, G)
            if (m == 1) {
                diag.Q = unname(Q)
            }
            else {
                diag.Q = unname(Q)[1 + 0:(m - 1) * (m + 1)]
            }
        }
        if (m == 1) 
            diag.Vtt1 = unname(Vtt1[, , t])
        else diag.Vtt1 = unname(Vtt1[, , t])[1 + 0:(m - 1) * 
            (m + 1)]
        if (any(diag.Vtt1 < 0)) 
            return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: soln became unstable and negative values appeared on the diagonal of Vtt1.\n")))
        if (debugkf != -1 & any(diag.Vtt1 == 0)) {
            Q0s = all(which(diag.Vtt1 == 0) %in% which(diag.Q == 
                0))
            if (!Q0s && (init.state == "x00" || (init.state == 
                "x10" && t > 1))) {
                return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: soln became unstable when zeros appeared on the diagonal of Vtt1 at t=", 
                  t, ".\n")))
            }
        }
        if (m == 1) {
            Vinv = pcholinv(matrix(Vtt1[, , t], 1, 1))
        }
        else {
            Vinv = pcholinv(Vtt1[, , t])
            Vinv = symm(Vinv)
        }
        J[, , t - 1] = Vtt[, , t - 1] %*% t.B %*% Vinv
        xtT[, t - 1] = xtt[, t - 1, drop = FALSE] + J[, , t - 
            1] %*% (xtT[, t, drop = FALSE] - xtt1[, t, drop = FALSE])
        if (m == 1) 
            t.J = J[, , t - 1]
        else t.J = matrix(J[, , t - 1], m, m, byrow = TRUE)
        VtT[, , t - 1] = Vtt[, , t - 1] + J[, , t - 1] %*% (VtT[, 
            , t] - Vtt1[, , t]) %*% t.J
    }
    if (init.state == "x00") {
        if ("B" %in% time.varying) {
            B = parmat(MLEobj, "B", t = 1)$B
            if (m == 1) 
                t.B = B
            else t.B = matrix(B, m, m, byrow = TRUE)
        }
        if ("Q" %in% time.varying) {
            Q = parmat(MLEobj, "Q", t = 1)$Q
            if (m == 1) {
                diag.Q = unname(Q)
            }
            else {
                diag.Q = takediag(unname(Q))
            }
        }
        diag.Vtt1 = unname(Vtt1[, , 1])
        diag.Vtt1 = diag.Vtt1[1 + 0:(m - 1) * (m + 1)]
        if (debugkf != -1 & any(diag.Vtt1 == 0)) {
            Q0s = identical(which(diag.Q == 0), which(diag.Vtt1 == 
                0))
            if (!Q0s && (init.state == "x00" || (init.state == 
                "x10" && t > 1))) {
                return(list(ok = FALSE, errors = paste("Stopped in MARSSkfss: soln became unstable when zeros appeared on the diagonal of Vtt1 at t=1.\n")))
            }
        }
        if (m == 1) {
            Vinv = pcholinv(matrix(Vtt1[, , 1], 1, 1))
        }
        else {
            Vinv = pcholinv(Vtt1[, , 1])
            Vinv = symm(Vinv)
        }
        J0 = V0 %*% t.B %*% Vinv
        x0T = x0 + J0 %*% (xtT[, 1, drop = FALSE] - xtt1[, 1, 
            drop = FALSE])
        V0T = V0 + J0 %*% (VtT[, , 1] - Vtt1[, , 1]) %*% t(J0)
        V0T = symm(V0T)
    }
    if (init.state == "x10") {
        if (m == 1) 
            J0 = matrix(J[, , 1], 1, 1)
        else J0 = J[, , 1]
        x0T = xtT[, 1, drop = FALSE]
        if (m == 1) 
            V0T = matrix(VtT[, , 1], 1, 1)
        else V0T = VtT[, , 1]
    }
    if ("Z" %in% time.varying) {
        Z = parmat(MLEobj, "Z", t = TT)$Z
    }
    Zt = Z
    Zt[YM[, TT] == 0, ] = 0
    if ("B" %in% time.varying) {
        B = parmat(MLEobj, "B", t = TT)$B
    }
    KT = matrix(Kt[, , TT], m, n)
    Vtt1T[, , TT] = (I.m - KT %*% Zt) %*% B %*% Vtt[, , TT - 
        1]
    s = seq(TT, 3)
    for (i in 1:(TT - 2)) {
        t = s[i]
        if ("B" %in% time.varying) {
            B = parmat(MLEobj, "B", t = t)$B
        }
        if (m == 1) 
            t.J = J[, , t - 2]
        else t.J = matrix(J[, , t - 2], m, m, byrow = TRUE)
        Vtt1T[, , t - 1] = Vtt[, , t - 1] %*% t.J + J[, , t - 
            1] %*% (Vtt1T[, , t] - B %*% Vtt[, , t - 1]) %*% 
            t.J
    }
    if (init.state == "x00") {
        if ("B" %in% time.varying) {
            B = parmat(MLEobj, "B", t = 2)$B
        }
        Vtt1T[, , 1] = Vtt[, , 1] %*% t(J0) + J[, , 1] %*% (Vtt1T[, 
            , 2] - B %*% Vtt[, , 1]) %*% t(J0)
    }
    if (init.state == "x10") 
        Vtt1T[, , 1] = NA
    rtn.list = list(xtT = xtT, VtT = VtT, Vtt1T = Vtt1T, x0T = x0T, 
        V0T = V0T, Vtt = Vtt, Vtt1 = Vtt1, J = J, J0 = J0, Kt = Kt, 
        xtt1 = xtt1, xtt = xtt, Innov = vt, Sigma = Ft)
    loglike = -sum(YM)/2 * log(2 * base::pi)
    for (t in 1:TT) {
        if (n == 1) 
            diag.Ft = Ft[, , t]
        else diag.Ft = unname(Ft[, , t])[1 + 0:(n - 1) * (n + 
            1)]
        if (any(diag.Ft == 0)) {
            if (t > 1 || (t == 1 & init.state == "x00")) {
                return(c(rtn.list, list(ok = FALSE, logLik = NaN, 
                  errors = paste("One of the diagonal elements of Sigma[,,", 
                    t, "]=0. That should never happen when t>1 or t=1 and tinitx=0.  \n Are both Q[i,i] and R[i,i] being set to 0?\n", 
                    sep = ""))))
            }
            else {
                OmgF1 = makediag(1, n)[diag.Ft != 0, , drop = FALSE]
                loglike = loglike + sum(diag.Ft == 0 & YM[, 1] != 
                  0)/2 * log(2 * base::pi)
                if (dim(OmgF1)[1] == 0) {
                  detFt = 1
                }
                else {
                  if (length(OmgF1 %*% Ft[, , t] %*% t(OmgF1)) == 
                    1) 
                    detFt = OmgF1 %*% Ft[, , t] %*% t(OmgF1)
                  else detFt = det(OmgF1 %*% Ft[, , t] %*% t(OmgF1))
                }
                if (n == 1) {
                  Ftinv = pcholinv(matrix(Ft[, , t], 1, 1))
                }
                else {
                  Ftinv = pcholinv(Ft[, , t])
                  Ftinv = symm(Ftinv)
                }
            }
        }
        else {
            if (n == 1) {
                detFt = Ft[, , t]
                Ftinv = 1/Ft[, , t]
            }
            else {
                detFt = det(Ft[, , t])
                Ftinv = chol2inv(chol(Ft[, , t]))
                Ftinv = symm(Ftinv)
            }
        }
        if (detFt < 0 || !is.finite(log(detFt))) 
            return(c(rtn.list, list(ok = FALSE, logLik = NaN, 
                Sigma = Ft, errors = paste("Stopped in MARSSkfss: log(det(Ft[,,", 
                  t, "]))=NA.\n", sep = ""))))
        loglike = loglike - (1/2) %*% matrix(vt[, t], 1, n) %*% 
            Ftinv %*% vt[, t, drop = FALSE] - (1/2) * log(detFt)
        loglike = as.vector(loglike)
    }
    if (!is.finite(loglike)) 
        return(c(rtn.list, list(ok = FALSE, errors = paste("Stopped in MARSSkfss: loglike computed to NA.\n"))))
    return(c(rtn.list, list(logLik = loglike, ok = TRUE, errors = msg)))
}
<bytecode: 0xc99e60>
<environment: namespace:MARSS>
 --- function search by body ---
Function MARSSkfss in namespace MARSS has this body.
 ----------- END OF FAILURE REPORT -------------- 
Error in if (class(siginv) == "try-error") { : 
  the condition has length > 1
Calls: CSEGriskfigure ... MARSShessian -> MARSSFisherI -> MARSSharveyobsFI -> MARSSkfss
Execution halted