R/checkConv.R

Defines functions print.checkConv checkConv.zeroinfl checkConv.unmarkedFit checkConv.polr checkConv.nls checkConv.multinom checkConv.lmerModLmerTest checkConv.merMod checkConv.maxlikeFit checkConv.lavaan checkConv.hurdle checkConv.glmmTMB checkConv.glm checkConv.clmm checkConv.clm checkConv.betareg checkConv.default checkConv

Documented in checkConv checkConv.betareg checkConv.clm checkConv.clmm checkConv.default checkConv.glm checkConv.glmmTMB checkConv.hurdle checkConv.lavaan checkConv.lmerModLmerTest checkConv.maxlikeFit checkConv.merMod checkConv.multinom checkConv.nls checkConv.polr checkConv.unmarkedFit checkConv.zeroinfl print.checkConv

##generic
checkConv <- function(mod, ...) {
    UseMethod("checkConv", mod)
}



##default
checkConv.default <- function(mod, ...) {
    stop("\nFunction not yet defined for this object class\n")
}



##betareg
checkConv.betareg <- function(mod, ...) {
    if(mod$optim$convergence == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- mod$optim$message
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##clm
checkConv.clm <- function(mod, ...) {
    if(mod$convergence$code == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- mod$convergence$alg.message
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##clmm
checkConv.clmm <- function(mod, ...) {
    if(mod$optRes$convergence == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- mod$optRes$message
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##glm
checkConv.glm <- function(mod, ...) {
    if(mod$converged) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- NULL ##object does not include a message from IWLS algorithm
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##glmmTMB
checkConv.glmmTMB <- function(mod, ...) {
    if(mod$fit$convergence == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- mod$fit$message ##object does not include a message from IWLS algorithm
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##hurdle
checkConv.hurdle <- function(mod, ...) {
    if(mod$converged) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- NULL ##object does not include a message from IWLS algorithm
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##lavaan
checkConv.lavaan <- function(mod, ...) {
    if(mod@Fit@converged) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- NULL ##object does not include a message from IWLS algorithm
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##maxlikefit
checkConv.maxlikeFit <- function(mod, ...) {
    if(mod$optim$convergence == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- mod$optim$message
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##merMod
checkConv.merMod <- function(mod, ...) {
    if(mod@optinfo$conv$opt == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- NULL ##object does not include a message from IWLS algorithm
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##lmerModLmerTest
checkConv.lmerModLmerTest <- function(mod, ...) {
    if(mod@optinfo$conv$opt == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- NULL ##object does not include a message from IWLS algorithm
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##multinom
checkConv.multinom <- function(mod, ...) {
    if(mod$convergence == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- NULL ##object does not include a message from IWLS algorithm
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##nls
checkConv.nls <- function(mod, ...) {
    if(mod$convInfo$isConv) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- mod$convInfo$stopMessage
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##polr
checkConv.polr <- function(mod, ...) {
    if(mod$convergence == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- NULL ##object does not include a message from IWLS algorithm
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##unmarked
checkConv.unmarkedFit <- function(mod, ...) {
    if(mod@opt$convergence == 0) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- mod@opt$message
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



##zeroinfl
checkConv.zeroinfl <- function(mod, ...) {
    if(mod$converged) {
        conv <- TRUE
    } else {conv <- FALSE}

    msg <- NULL ##object does not include a message from IWLS algorithm
    out <- list(converged = conv, message = msg)
    class(out) <- "checkConv"
    return(out)
}



print.checkConv <- function(x, ...) {
  cat("\nConverged: ", x$converged, "\n")
  if(!is.null(x$message)) {
      cat("(", x$message, ")", "\n", sep = "")
  }
}

Try the AICcmodavg package in your browser

Any scripts or data that you put into this service are public.

AICcmodavg documentation built on Nov. 17, 2023, 1:08 a.m.