Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test code needs glmmTMB #807

Merged
merged 8 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: insight
Title: Easy Access to Model Information for Various Model Objects
Version: 0.19.5
Version: 0.19.5.1
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -205,3 +205,4 @@ Config/Needs/website:
rstudio/bslib,
r-lib/pkgdown,
easystats/easystatstemplate
Remotes: glmmTMB/glmmTMB/glmmTMB
154 changes: 77 additions & 77 deletions R/find_algorithm.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@
#' @inheritParams find_parameters
#'
#' @return A list with elements depending on the model.
#' \cr
#'
#' For frequentist models:
#' \itemize{
#' \item `algorithm`, for instance `"OLS"` or `"ML"`
#' \item `optimizer`, name of optimizing function, only applies to
#' - `algorithm`, for instance `"OLS"` or `"ML"`
#' - `optimizer`, name of optimizing function, only applies to
#' specific models (like `gam`)
#' }
#'
#' For frequentist mixed models:
#' \itemize{
#' \item `algorithm`, for instance `"REML"` or `"ML"`
#' \item `optimizer`, name of optimizing function
#' }
#' - `algorithm`, for instance `"REML"` or `"ML"`
#' - `optimizer`, name of optimizing function
#'
#' For Bayesian models:
#' \itemize{
#' \item `algorithm`, the algorithm
#' \item `chains`, number of chains
#' \item `iterations`, number of iterations per chain
#' \item `warmup`, number of warmups per chain
#' }
#' - `algorithm`, the algorithm
#' - `chains`, number of chains
#' - `iterations`, number of iterations per chain
#' - `warmup`, number of warmups per chain
#'
#' @examples
#' if (require("lme4")) {
#' data(sleepstudy)
#' m <- lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy)
#' find_algorithm(m)
#' }
#' @examplesIf require("lme4")
#' data(sleepstudy, package = "lme4")
#' m <- lme4::lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy)
#' find_algorithm(m)
#'
#' @examplesIf require("rstanarm") && require("lme4")
#' \dontrun{
#' library(rstanarm)
#' m <- stan_lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy)
#' data(sleepstudy, package = "lme4")
#' m <- suppressWarnings(rstanarm::stan_lmer(
#' Reaction ~ Days + (1 | Subject),
#' data = sleepstudy,
#' refresh = 0
#' ))
#' find_algorithm(m)
#' }
#' @export
Expand All @@ -54,31 +54,31 @@ find_algorithm.default <- function(x, ...) {

#' @export
find_algorithm.Gam <- function(x, ...) {
list("algorithm" = "IWLS")
list(algorithm = "IWLS")
}


#' @export
find_algorithm.lmRob <- function(x, ...) {
list("algorithm" = x$robust.control$final.alg)
list(algorithm = x$robust.control$final.alg)
}


#' @export
find_algorithm.lmrob <- function(x, ...) {
list("algorithm" = x$control$method)
list(algorithm = x$control$method)
}


#' @export
find_algorithm.glmrob <- function(x, ...) {
list("algorithm" = x$method)
list(algorithm = x$method)
}


#' @export
find_algorithm.logistf <- function(x, ...) {
list("algorithm" = x$method)
list(algorithm = x$method)
}

#' @export
Expand All @@ -90,25 +90,25 @@ find_algorithm.flic <- find_algorithm.logistf

#' @export
find_algorithm.bigglm <- function(x, ...) {
list("algorithm" = "ML")
list(algorithm = "ML")
}


#' @export
find_algorithm.BBreg <- function(x, ...) {
list("algorithm" = "ML")
list(algorithm = "ML")
}


#' @export
find_algorithm.Arima <- function(x, ...) {
list("algorithm" = "ML")
list(algorithm = "ML")
}


#' @export
find_algorithm.glimML <- function(x, ...) {
list("algorithm" = "ML")
list(algorithm = "ML")
}


Expand All @@ -122,21 +122,21 @@ find_algorithm.BBmm <- function(x, ...) {

#' @export
find_algorithm.biglm <- function(x, ...) {
list("algorithm" = "OLS")
list(algorithm = "OLS")
}


#' @export
find_algorithm.gamlss <- function(x, ...) {
list("algorithm" = as.character(x$method)[1])
list(algorithm = as.character(x$method)[1])
}


#' @export
find_algorithm.gam <- function(x, ...) {
list(
"algorithm" = x$method,
"optimizer" = x$optimizer
algorithm = x$method,
optimizer = x$optimizer
)
}

Expand All @@ -146,25 +146,25 @@ find_algorithm.scam <- find_algorithm.gam

#' @export
find_algorithm.lm <- function(x, ...) {
list("algorithm" = "OLS")
list(algorithm = "OLS")
}


#' @export
find_algorithm.systemfit <- function(x, ...) {
list("algorithm" = x$method)
list(algorithm = x$method)
}


#' @export
find_algorithm.afex_aov <- function(x, ...) {
list("algorithm" = "OLS")
list(algorithm = "OLS")
}


#' @export
find_algorithm.speedlm <- function(x, ...) {
list("algorithm" = x$method)
list(algorithm = x$method)
}


Expand All @@ -174,62 +174,62 @@ find_algorithm.blavaan <- function(x, ...) {
check_if_installed("blavaan")

list(
"chains" = blavaan::blavInspect(x, "n.chains"),
"sample" = x@external$sample,
"warmup" = x@external$burnin
chains = blavaan::blavInspect(x, "n.chains"),
sample = x@external$sample,
warmup = x@external$burnin
)
}


#' @export
find_algorithm.speedglm <- function(x, ...) {
list("algorithm" = x$method)
list(algorithm = x$method)
}


#' @export
find_algorithm.rq <- function(x, ...) {
list("algorithm" = x$method)
list(algorithm = x$method)
}


#' @export
find_algorithm.bayesx <- function(x, ...) {
list(
"algorithm" = x$method,
"iterations" = x$iterations,
"warmup" = x$burnin
algorithm = x$method,
iterations = x$iterations,
warmup = x$burnin
)
}


#' @export
find_algorithm.crq <- function(x, ...) {
list("algorithm" = x$method)
list(algorithm = x$method)
}


#' @export
find_algorithm.rqss <- function(x, ...) {
list("algorithm" = x$method)
list(algorithm = x$method)
}


#' @export
find_algorithm.glm <- function(x, ...) {
list("algorithm" = "ML")
list(algorithm = "ML")
}


#' @export
find_algorithm.nestedLogit <- function(x, ...) {
list("algorithm" = "ML")
list(algorithm = "ML")
}


#' @export
find_algorithm.LORgee <- function(x, ...) {
list("algorithm" = "Fisher's scoring ML")
list(algorithm = "Fisher's scoring ML")
}


Expand All @@ -238,8 +238,8 @@ find_algorithm.merMod <- function(x, ...) {
algorithm <- ifelse(as.logical(x@devcomp$dims[["REML"]]), "REML", "ML")

list(
"algorithm" = algorithm,
"optimizer" = as.character(x@optinfo$optimizer)
algorithm = algorithm,
optimizer = as.character(x@optinfo$optimizer)
)
}

Expand All @@ -258,8 +258,8 @@ find_algorithm.mixed <- function(x, ...) {
algorithm <- ifelse(as.logical(x@devcomp$dims[["REML"]]), "REML", "ML")

list(
"algorithm" = algorithm,
"optimizer" = as.character(x@optinfo$optimizer)
algorithm = algorithm,
optimizer = as.character(x@optinfo$optimizer)
)
}

Expand All @@ -272,8 +272,8 @@ find_algorithm.lme <- function(x, ...) {
}

list(
"algorithm" = x$method,
"optimizer" = optimizer
algorithm = x$method,
optimizer = optimizer
)
}

Expand All @@ -282,8 +282,8 @@ find_algorithm.lme <- function(x, ...) {
find_algorithm.MixMod <- function(x, ...) {
list(
## FIXME
"algorithm" = "quasi-Newton",
"optimizer" = x$control$optimizer
algorithm = "quasi-Newton",
optimizer = x$control$optimizer
)
}

Expand All @@ -293,8 +293,8 @@ find_algorithm.glmmTMB <- function(x, ...) {
algorithm <- ifelse(x$modelInfo$REML, "REML", "ML")

list(
"algorithm" = algorithm,
"optimizer" = "nlminb"
algorithm = algorithm,
optimizer = "nlminb"
)
}

Expand All @@ -304,10 +304,10 @@ find_algorithm.stanreg <- function(x, ...) {
info <- x$stanfit@sim

list(
"algorithm" = x$algorithm,
"chains" = info$chains,
"iterations" = info$iter,
"warmup" = info$warmup
algorithm = x$algorithm,
chains = info$chains,
iterations = info$iter,
warmup = info$warmup
)
}

Expand All @@ -318,19 +318,19 @@ find_algorithm.stanfit <- function(x, ...) {
algorithm <- unlist(x@stan_args)

list(
"algorithm" = as.vector(algorithm["algorithm"]),
"chains" = info$chains,
"iterations" = info$iter,
"warmup" = info$warmup
algorithm = as.vector(algorithm["algorithm"]),
chains = info$chains,
iterations = info$iter,
warmup = info$warmup
)
}


#' @export
find_algorithm.bayesQR <- function(x, ...) {
list(
"algorithm" = x[[1]]$method,
"iterations" = nrow(x[[1]]$betadraw)
algorithm = x[[1]]$method,
iterations = nrow(x[[1]]$betadraw)
)
}

Expand All @@ -340,9 +340,9 @@ find_algorithm.brmsfit <- function(x, ...) {
info <- x$fit@sim

list(
"algorithm" = x$algorithm,
"chains" = info$chains,
"iterations" = info$iter,
"warmup" = info$warmup
algorithm = x$algorithm,
chains = info$chains,
iterations = info$iter,
warmup = info$warmup
)
}
Loading
Loading