From 077a76e250371c7a910cf395bfb9f48805c01ead Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:10:58 +0200 Subject: [PATCH 01/14] Update `DESCRIPTION` to use latest 'easystats' dependencies (#766) Co-authored-by: IndrajeetPatil <11330453+IndrajeetPatil@users.noreply.github.com> --- DESCRIPTION | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 842122309..f5cf4d81e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -73,9 +73,9 @@ BugReports: https://github.com/easystats/performance/issues Depends: R (>= 3.6) Imports: - bayestestR (>= 0.13.2), - insight (>= 0.20.2), - datawizard (>= 0.10.0), + bayestestR (>= 0.14.0), + insight (>= 0.20.3), + datawizard (>= 0.12.2), stats, utils Suggests: From 0a047a7febccec49bd984862ba5436e721221aaf Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 09:48:46 +0200 Subject: [PATCH 02/14] docs --- R/r2_nakagawa.R | 3 ++- man/icc.Rd | 3 ++- man/r2_nakagawa.Rd | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/R/r2_nakagawa.R b/R/r2_nakagawa.R index 1246a444a..aeb4df1c1 100644 --- a/R/r2_nakagawa.R +++ b/R/r2_nakagawa.R @@ -30,7 +30,7 @@ #' - Bernoulli (logistic) regression #' - Binomial regression (with other than binary outcomes) #' - Poisson and Quasi-Poisson regression -#' - Negative binomial regression (including nbinom1 and nbinom2 families) +#' - Negative binomial regression (including nbinom1, nbinom2 and nbinom12 families) #' - Gaussian regression (linear models) #' - Gamma regression #' - Tweedie regression @@ -44,6 +44,7 @@ #' - Compound Poisson regression #' - Generalized Poisson regression #' - Log-normal regression +#' - Skew-normal regression #' #' Extracting variance components for models with zero-inflation part is not #' straightforward, because it is not definitely clear how the distribution-specific diff --git a/man/icc.Rd b/man/icc.Rd index 071e1b617..8b38ece25 100644 --- a/man/icc.Rd +++ b/man/icc.Rd @@ -212,7 +212,7 @@ should be accurate and reliable for following mixed models or model families: \item Bernoulli (logistic) regression \item Binomial regression (with other than binary outcomes) \item Poisson and Quasi-Poisson regression -\item Negative binomial regression (including nbinom1 and nbinom2 families) +\item Negative binomial regression (including nbinom1, nbinom2 and nbinom12 families) \item Gaussian regression (linear models) \item Gamma regression \item Tweedie regression @@ -227,6 +227,7 @@ Following model families are not yet validated, but should work: \item Compound Poisson regression \item Generalized Poisson regression \item Log-normal regression +\item Skew-normal regression } Extracting variance components for models with zero-inflation part is not diff --git a/man/r2_nakagawa.Rd b/man/r2_nakagawa.Rd index 169af5709..75f2de3d0 100644 --- a/man/r2_nakagawa.Rd +++ b/man/r2_nakagawa.Rd @@ -111,7 +111,7 @@ should be accurate and reliable for following mixed models or model families: \item Bernoulli (logistic) regression \item Binomial regression (with other than binary outcomes) \item Poisson and Quasi-Poisson regression -\item Negative binomial regression (including nbinom1 and nbinom2 families) +\item Negative binomial regression (including nbinom1, nbinom2 and nbinom12 families) \item Gaussian regression (linear models) \item Gamma regression \item Tweedie regression @@ -126,6 +126,7 @@ Following model families are not yet validated, but should work: \item Compound Poisson regression \item Generalized Poisson regression \item Log-normal regression +\item Skew-normal regression } Extracting variance components for models with zero-inflation part is not From f1d79148a6a6178afbac8e5fa3e4e77ee0bf7905 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 30 Sep 2024 13:23:57 +0200 Subject: [PATCH 03/14] Fix failing glmmTMB tests (#769) --- DESCRIPTION | 5 +++-- NEWS.md | 4 ++++ R/check_model_diagnostics.R | 2 +- tests/testthat/test-check_collinearity.R | 2 -- tests/testthat/test-check_convergence.R | 1 - tests/testthat/test-check_model.R | 1 - tests/testthat/test-check_normality.R | 1 - tests/testthat/test-check_overdispersion.R | 4 ---- tests/testthat/test-check_predictions.R | 1 - tests/testthat/test-check_singularity.R | 2 +- tests/testthat/test-check_zeroinflation.R | 4 ---- tests/testthat/test-r2.R | 19 ++++++++++--------- 12 files changed, 19 insertions(+), 27 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f5cf4d81e..5d629a4b9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.12.3.3 +Version: 0.12.3.4 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -103,7 +103,7 @@ Suggests: ftExtra, gamm4, ggdag, - glmmTMB, + glmmTMB (>= 1.1.10), graphics, Hmisc, httr2, @@ -160,3 +160,4 @@ Config/Needs/website: r-lib/pkgdown, easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true +Remotes: easystats/insight, easystats/bayestestR, easystats/see, easystats/parameters diff --git a/NEWS.md b/NEWS.md index 81a8c5ad2..4f0984b48 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,10 @@ * Minor revisions to the printed output of `check_dag()`. +## Bug fixes + +* Fixed failing tests that broke due to changes in latest *glmmTMB* update. + # performance 0.12.3 ## New functions diff --git a/R/check_model_diagnostics.R b/R/check_model_diagnostics.R index 431a2bc0f..8897c685e 100644 --- a/R/check_model_diagnostics.R +++ b/R/check_model_diagnostics.R @@ -460,7 +460,7 @@ if (!is.na(match(faminfo$family, c("binomial", "poisson", "truncated_poisson")))) { return(1) } - betad <- model$fit$par["betad"] + betad <- model$fit$par["betadisp"] switch(faminfo$family, gaussian = exp(0.5 * betad), Gamma = exp(-0.5 * betad), diff --git a/tests/testthat/test-check_collinearity.R b/tests/testthat/test-check_collinearity.R index ba456ae6f..d62aec75d 100644 --- a/tests/testthat/test-check_collinearity.R +++ b/tests/testthat/test-check_collinearity.R @@ -24,7 +24,6 @@ test_that("check_collinearity, correct order in print", { test_that("check_collinearity", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not(getRversion() >= "4.0.0") @@ -51,7 +50,6 @@ test_that("check_collinearity", { test_that("check_collinearity", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not(getRversion() >= "4.0.0") diff --git a/tests/testthat/test-check_convergence.R b/tests/testthat/test-check_convergence.R index 0bfadc8a6..8897b785d 100644 --- a/tests/testthat/test-check_convergence.R +++ b/tests/testthat/test-check_convergence.R @@ -29,7 +29,6 @@ test_that("check_convergence", { test_that("check_convergence, glmmTMB", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") data(iris) model <- suppressWarnings(glmmTMB::glmmTMB( diff --git a/tests/testthat/test-check_model.R b/tests/testthat/test-check_model.R index 097f089a5..2b1141d26 100644 --- a/tests/testthat/test-check_model.R +++ b/tests/testthat/test-check_model.R @@ -52,7 +52,6 @@ test_that("`check_model()` works for quantreg", { }) test_that("`check_model()` warnings for tweedie", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not_installed("lme4") data(sleepstudy, package = "lme4") diff --git a/tests/testthat/test-check_normality.R b/tests/testthat/test-check_normality.R index 44b461aea..f166c6f03 100644 --- a/tests/testthat/test-check_normality.R +++ b/tests/testthat/test-check_normality.R @@ -35,7 +35,6 @@ test_that("check_normality | afex", { }) test_that("check_normality | glmmTMB", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not(getRversion() >= "4.0.0") diff --git a/tests/testthat/test-check_overdispersion.R b/tests/testthat/test-check_overdispersion.R index 06cc95dd0..2930322bb 100644 --- a/tests/testthat/test-check_overdispersion.R +++ b/tests/testthat/test-check_overdispersion.R @@ -1,5 +1,4 @@ test_that("check_overdispersion, glmmTMB-poisson", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not(getRversion() >= "4.0.0") data(Salamanders, package = "glmmTMB") @@ -50,7 +49,6 @@ test_that("check_overdispersion, glmmTMB-poisson", { test_that("check_overdispersion, glmmTMB-poisson mixed", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not(getRversion() >= "4.0.0") data(Salamanders, package = "glmmTMB") @@ -78,7 +76,6 @@ test_that("check_overdispersion, glmmTMB-poisson mixed", { test_that("check_overdispersion, zero-inflated and negbin", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not_installed("DHARMa") skip_if_not(getRversion() >= "4.0.0") @@ -183,7 +180,6 @@ test_that("check_overdispersion, MASS::negbin", { test_that("check_overdispersion, genpois", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not_installed("DHARMa") skip_if_not(getRversion() >= "4.0.0") diff --git a/tests/testthat/test-check_predictions.R b/tests/testthat/test-check_predictions.R index 04bc1d2cd..142a8b429 100644 --- a/tests/testthat/test-check_predictions.R +++ b/tests/testthat/test-check_predictions.R @@ -35,7 +35,6 @@ test_that("check_predictions", { test_that("check_predictions, glmmTMB", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") data(mtcars) model <- glmmTMB::glmmTMB(vs ~ disp, data = mtcars, family = binomial()) diff --git a/tests/testthat/test-check_singularity.R b/tests/testthat/test-check_singularity.R index dc0d56964..8a07b85e0 100644 --- a/tests/testthat/test-check_singularity.R +++ b/tests/testthat/test-check_singularity.R @@ -29,7 +29,7 @@ test_that("check_singularity", { newparam = list( beta = 0, theta = rep(0, 21), - betad = 0 + betadisp = 0 ) )[[1]] expect_warning(expect_warning({ diff --git a/tests/testthat/test-check_zeroinflation.R b/tests/testthat/test-check_zeroinflation.R index a7ff7cbbd..38a5c7726 100644 --- a/tests/testthat/test-check_zeroinflation.R +++ b/tests/testthat/test-check_zeroinflation.R @@ -1,5 +1,4 @@ test_that("check_zeroinflation", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") set.seed(123) data(Salamanders, package = "glmmTMB") @@ -22,7 +21,6 @@ test_that("check_zeroinflation", { test_that("check_zeroinflation, glmmTMB with and without zero-inflation component", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not_installed("DHARMa") set.seed(123) @@ -109,7 +107,6 @@ test_that("check_zeroinflation, glmer.nb", { test_that("check_zeroinflation, glmmTMB nbinom", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not_installed("DHARMa") skip_on_cran() @@ -166,7 +163,6 @@ test_that("check_zeroinflation, MASS::negbin", { test_that("check_zeroinflation, genpois", { - skip_if(getRversion() > "4.3.3") skip_if_not_installed("glmmTMB") skip_if_not_installed("DHARMa") skip_if_not(getRversion() >= "4.0.0") diff --git a/tests/testthat/test-r2.R b/tests/testthat/test-r2.R index f521b3aab..d7ade6b29 100644 --- a/tests/testthat/test-r2.R +++ b/tests/testthat/test-r2.R @@ -46,8 +46,7 @@ skip_if_not_installed("withr") withr::with_environment( new.env(), test_that("r2 glmmTMB, no ranef", { - skip_if(getRversion() > "4.3.3") - skip_if_not_installed("glmmTMB") + skip_if_not_installed("glmmTMB", minimum_version = "1.1.10") data(Owls, package = "glmmTMB") # linear --------------------------------------------------------------- m <- glmmTMB::glmmTMB(NegPerChick ~ BroodSize + ArrivalTime, data = Owls) @@ -89,14 +88,16 @@ withr::with_environment( data = bioChemists ) out <- r2(m) - expect_equal(out[[1]], 0.1797549, tolerance = 1e-3, ignore_attr = TRUE) + expect_equal(out[[1]], 0.14943, tolerance = 1e-3, ignore_attr = TRUE) + ## FIXME: since glmmTMB 1.1.10(?) Pearson residuals differ and results + ## are no longer identical, see https://github.com/glmmTMB/glmmTMB/issues/1101 # validate against pscl::zeroinfl - m2 <- pscl::zeroinfl( - art ~ fem + mar + kid5 + ment | kid5 + phd, - data = bioChemists - ) - out2 <- r2(m2) - expect_equal(out[[1]], out2[[1]], tolerance = 1e-3, ignore_attr = TRUE) + # m2 <- pscl::zeroinfl( + # art ~ fem + mar + kid5 + ment | kid5 + phd, + # data = bioChemists + # ) + # out2 <- r2(m2) + # expect_equal(out[[1]], out2[[1]], tolerance = 1e-3, ignore_attr = TRUE) # Gamma -------------------------------------------------------------- clotting <<- data.frame( u = c(5, 10, 15, 20, 30, 40, 60, 80, 100), From e24bdd83b3e69f41c80b2596dcb69fbd39f2fd7f Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 30 Sep 2024 14:05:23 +0200 Subject: [PATCH 04/14] desc --- DESCRIPTION | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5d629a4b9..0e042c1db 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,9 +48,9 @@ Authors@R: role = "rev"), person(given = "gjo11", role = "rev"), - person("Etienne", - "Bacher", , - "etienne.bacher@protonmail.com", + person(given = "Etienne", + family = "Bacher", , + email = "etienne.bacher@protonmail.com", role = "ctb", comment = c(ORCID = "0000-0002-9271-5075")), person(given = "Joseph", @@ -160,4 +160,3 @@ Config/Needs/website: r-lib/pkgdown, easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true -Remotes: easystats/insight, easystats/bayestestR, easystats/see, easystats/parameters From 868144c09801877c52f58236fd09437b791d55a5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 1 Oct 2024 06:57:28 +0200 Subject: [PATCH 05/14] Update `DESCRIPTION` to use latest 'easystats' dependencies (#770) Co-authored-by: IndrajeetPatil <11330453+IndrajeetPatil@users.noreply.github.com> --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0e042c1db..a6e2a3069 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -74,8 +74,8 @@ Depends: R (>= 3.6) Imports: bayestestR (>= 0.14.0), - insight (>= 0.20.3), - datawizard (>= 0.12.2), + insight (>= 0.20.4), + datawizard (>= 0.12.3), stats, utils Suggests: From 22971d617995a2f39831224e89529595e87acc0c Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 1 Oct 2024 22:06:52 +0200 Subject: [PATCH 06/14] new arg --- R/performance_aicc.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/performance_aicc.R b/R/performance_aicc.R index 3c433161f..52cf3679c 100644 --- a/R/performance_aicc.R +++ b/R/performance_aicc.R @@ -265,7 +265,7 @@ performance_aicc.rma <- function(x, ...) { .adjust_ic_jacobian <- function(model, ic) { response_transform <- insight::find_transformation(model) if (!is.null(ic) && !is.null(response_transform) && !identical(response_transform, "identity")) { - adjustment <- .safe(.ll_analytic_adjustment(model, insight::get_weights(model, na_rm = TRUE))) + adjustment <- .safe(.ll_analytic_adjustment(model, insight::get_weights(model, remove_na = TRUE))) if (!is.null(adjustment)) { ic <- ic - 2 * adjustment } From 35cd5d5006c23e98a578b501bcf5f9eabc7cbe8e Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 1 Oct 2024 22:46:40 +0200 Subject: [PATCH 07/14] lintr --- R/check_dag.R | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/R/check_dag.R b/R/check_dag.R index 7a64ae4d0..272cc5814 100644 --- a/R/check_dag.R +++ b/R/check_dag.R @@ -285,15 +285,13 @@ check_dag <- function(..., adjustment_set <- unlist(dagitty::adjustmentSets(dag, effect = x), use.names = FALSE) adjustment_nodes <- unlist(dagitty::adjustedNodes(dag), use.names = FALSE) minimal_adjustments <- as.list(dagitty::adjustmentSets(dag, effect = x)) - collider <- adjustment_nodes[vapply(adjustment_nodes, ggdag::is_collider, logical(1), .dag = dag, downstream = FALSE)] - if (!length(collider)) { + collider <- adjustment_nodes[vapply(adjustment_nodes, ggdag::is_collider, logical(1), .dag = dag, downstream = FALSE)] # nolint + if (length(collider)) { + # if we *have* colliders, remove them from minimal adjustments + minimal_adjustments <- lapply(minimal_adjustments, setdiff, y = collider) + } else { # if we don't have colliders, set to NULL collider <- NULL - } else { - # if we *have* colliders, remove them from minimal adjustments - minimal_adjustments <- lapply(minimal_adjustments, function(ma) { - setdiff(ma, collider) - }) } list( # no adjustment needed when @@ -303,7 +301,7 @@ check_dag <- function(..., # incorrect adjustment when # - required is NULL and current adjustment not NULL # - OR we have a collider in current adjustments - incorrectly_adjusted = (is.null(adjustment_set) && !is.null(adjustment_nodes)) || (!is.null(collider) && collider %in% adjustment_nodes), + incorrectly_adjusted = (is.null(adjustment_set) && !is.null(adjustment_nodes)) || (!is.null(collider) && collider %in% adjustment_nodes), # nolint current_adjustments = adjustment_nodes, minimal_adjustments = minimal_adjustments, collider = collider From 8d5742ed418f579e50370f7e35dcf70997a7dbb6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 2 Oct 2024 01:05:41 +0200 Subject: [PATCH 08/14] remove twitter handle --- DESCRIPTION | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a6e2a3069..9c2f7f969 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,22 +7,22 @@ Authors@R: family = "Lüdecke", role = c("aut", "cre"), email = "d.luedecke@uke.de", - comment = c(ORCID = "0000-0002-8895-3206", Twitter = "@strengejacke")), + comment = c(ORCID = "0000-0002-8895-3206")), person(given = "Dominique", family = "Makowski", role = c("aut", "ctb"), email = "dom.makowski@gmail.com", - comment = c(ORCID = "0000-0001-5375-9967", Twitter = "@Dom_Makowski")), + comment = c(ORCID = "0000-0001-5375-9967")), person(given = "Mattan S.", family = "Ben-Shachar", role = c("aut", "ctb"), email = "matanshm@post.bgu.ac.il", - comment = c(ORCID = "0000-0002-4287-4801", Twitter = "@mattansb")), + comment = c(ORCID = "0000-0002-4287-4801")), person(given = "Indrajeet", family = "Patil", role = c("aut", "ctb"), email = "patilindrajeet.science@gmail.com", - comment = c(ORCID = "0000-0003-1995-6531", Twitter = "@patilindrajeets")), + comment = c(ORCID = "0000-0003-1995-6531")), person(given = "Philip", family = "Waggoner", role = c("aut", "ctb"), @@ -32,12 +32,12 @@ Authors@R: family = "Wiernik", role = c("aut", "ctb"), email = "brenton@wiernik.org", - comment = c(ORCID = "0000-0001-9560-6336", Twitter = "@bmwiernik")), + comment = c(ORCID = "0000-0001-9560-6336")), person(given = "Rémi", family = "Thériault", role = c("aut", "ctb"), email = "remi.theriault@mail.mcgill.ca", - comment = c(ORCID = "0000-0003-4315-6788", Twitter = "@rempsyc")), + comment = c(ORCID = "0000-0003-4315-6788")), person(given = "Vincent", family = "Arel-Bundock", email = "vincent.arel-bundock@umontreal.ca", From c5a22290808f2200569e980592dc05d84cf4b9f9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 2 Oct 2024 01:07:52 +0200 Subject: [PATCH 09/14] Update test based on glmmTMB fix (#771) --- DESCRIPTION | 3 +- R/check_dag.R | 68 +++++++++++++++++-- R/check_heterogeneity_bias.R | 2 +- man/check_dag.Rd | 33 +++++++-- man/check_heterogeneity_bias.Rd | 2 - .../testthat/test-check_heterogeneity_bias.R | 2 +- tests/testthat/test-icc.R | 2 +- tests/testthat/test-r2.R | 17 +++-- 8 files changed, 106 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a6e2a3069..8680fd5b9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -142,7 +142,7 @@ Suggests: rstanarm, rstantools, sandwich, - see (>= 0.8.2), + see (>= 0.9.0), survey, survival, testthat (>= 3.2.1), @@ -160,3 +160,4 @@ Config/Needs/website: r-lib/pkgdown, easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true +Remotes: glmmTMB/glmmTMB/glmmTMB#1102 diff --git a/R/check_dag.R b/R/check_dag.R index 272cc5814..c8b53533f 100644 --- a/R/check_dag.R +++ b/R/check_dag.R @@ -37,9 +37,17 @@ #' @param latent A character vector with names of latent variables in the model. #' @param effect Character string, indicating which effect to check. Can be #' `"all"` (default), `"total"`, or `"direct"`. -#' @param coords A list with two elements, `x` and `y`, which both are named -#' vectors of numerics. The names correspond to the variable names in the DAG, -#' and the values for `x` and `y` indicate the x/y coordinates in the plot. +#' @param coords Coordinates of the variables when plotting the DAG. The +#' coordinates can be provided in three different ways: +#' +#' - a list with two elements, `x` and `y`, which both are named vectors of +#' numerics. The names correspond to the variable names in the DAG, and the +#' values for `x` and `y` indicate the x/y coordinates in the plot. +#' - a list with elements that correspond to the variables in the DAG. Each +#' element is a numeric vector of length two with x- and y-coordinate. +#' - a data frame with three columns: `x`, `y` and `name` (which contains the +#' variable names). +#' #' See 'Examples'. #' @param x An object of class `check_dag`, as returned by `check_dag()`. #' @@ -111,7 +119,7 @@ #' Interpreting Confounder and Modifier Coefficients. American Journal of #' Epidemiology, 177(4), 292–298. \doi{10.1093/aje/kws412} #' -#' @examplesIf require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE) && packageVersion("see") > "0.8.5" +#' @examplesIf require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE) #' # no adjustment needed #' check_dag( #' y ~ x + b, @@ -171,6 +179,22 @@ #' ) #' plot(dag) #' +#' # alternative way of providing the coordinates +#' dag <- check_dag( +#' score ~ exp + b + c, +#' exp ~ b, +#' outcome = "score", +#' exposure = "exp", +#' coords = list( +#' # x/y coordinates for each node +#' score = c(5, 3), +#' exp = c(4, 3), +#' b = c(3, 2), +#' c = c(3, 4) +#' ) +#' ) +#' plot(dag) +#' #' # Objects returned by `check_dag()` can be used with "ggdag" or "dagitty" #' ggdag::ggdag_status(dag) #' @@ -248,6 +272,9 @@ check_dag <- function(..., adjusted <- all.vars(adjusted) } + # process coords-argument + coords <- .process_coords(coords) + # convert to dag dag_args <- c(formulas, list( exposure = exposure, @@ -338,6 +365,39 @@ check_dag <- function(..., } +.process_coords <- function(coords) { + # check if the coords are not provided as list with x/y elements, but instead + # as list x/y coordinates for each element. This means, "coords" is provided as + # + # coords <- list( + # score = c(5, 3), + # exp = c(4, 3), + # b = c(3, 2), + # c = c(3, 4) + # ) + # + # but we want + # + # coords = list( + # x = c(score = 5, exp = 4, b = 3, c = 3), + # y = c(score = 3, exp = 3, b = 2, c = 4) + # ) + # + # we have to check that it's not a data frame and that it is a list - + # values like `ggdag::time_ordered_coords()` returns a function, not a list + if (!is.null(coords) && !is.data.frame(coords) && is.list(coords) && (length(coords) != 2 || !identical(names(coords), c("x", "y")))) { # nolint + # transform list into data frame, split x and y coordinates into columns + coords <- datawizard::rownames_as_column( + stats::setNames(as.data.frame(do.call(rbind, coords)), c("x", "y")), + "name" + ) + # reorder + coords <- coords[c("x", "y", "name")] + } + coords +} + + # methods -------------------------------------------------------------------- #' @rdname check_dag diff --git a/R/check_heterogeneity_bias.R b/R/check_heterogeneity_bias.R index 3c9b502ce..755f47dfa 100644 --- a/R/check_heterogeneity_bias.R +++ b/R/check_heterogeneity_bias.R @@ -39,7 +39,7 @@ #' Modeling of Time-Series Cross-Sectional and Panel Data. Political Science #' Research and Methods, 3(1), 133–153. #' -#' @examplesIf insight::check_if_installed("datawizard", minimum_version = "0.12.0", quietly = TRUE) +#' @examples #' data(iris) #' iris$ID <- sample(1:4, nrow(iris), replace = TRUE) # fake-ID #' check_heterogeneity_bias(iris, select = c("Sepal.Length", "Petal.Length"), by = "ID") diff --git a/man/check_dag.Rd b/man/check_dag.Rd index fa7e92207..e366ff07a 100644 --- a/man/check_dag.Rd +++ b/man/check_dag.Rd @@ -42,9 +42,18 @@ are adjusted for in the model, e.g. \code{adjusted = c("x1", "x2")} or \item{effect}{Character string, indicating which effect to check. Can be \code{"all"} (default), \code{"total"}, or \code{"direct"}.} -\item{coords}{A list with two elements, \code{x} and \code{y}, which both are named -vectors of numerics. The names correspond to the variable names in the DAG, -and the values for \code{x} and \code{y} indicate the x/y coordinates in the plot. +\item{coords}{Coordinates of the variables when plotting the DAG. The +coordinates can be provided in three different ways: +\itemize{ +\item a list with two elements, \code{x} and \code{y}, which both are named vectors of +numerics. The names correspond to the variable names in the DAG, and the +values for \code{x} and \code{y} indicate the x/y coordinates in the plot. +\item a list with elements that correspond to the variables in the DAG. Each +element is a numeric vector of length two with x- and y-coordinate. +\item a data frame with three columns: \code{x}, \code{y} and \code{name} (which contains the +variable names). +} + See 'Examples'.} \item{x}{An object of class \code{check_dag}, as returned by \code{check_dag()}.} @@ -137,7 +146,7 @@ adjustments or over-adjustment. } \examples{ -\dontshow{if (require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE) && packageVersion("see") > "0.8.5") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # no adjustment needed check_dag( y ~ x + b, @@ -197,6 +206,22 @@ dag <- check_dag( ) plot(dag) +# alternative way of providing the coordinates +dag <- check_dag( + score ~ exp + b + c, + exp ~ b, + outcome = "score", + exposure = "exp", + coords = list( + # x/y coordinates for each node + score = c(5, 3), + exp = c(4, 3), + b = c(3, 2), + c = c(3, 4) + ) +) +plot(dag) + # Objects returned by `check_dag()` can be used with "ggdag" or "dagitty" ggdag::ggdag_status(dag) diff --git a/man/check_heterogeneity_bias.Rd b/man/check_heterogeneity_bias.Rd index 228d26510..40b2b66ca 100644 --- a/man/check_heterogeneity_bias.Rd +++ b/man/check_heterogeneity_bias.Rd @@ -50,11 +50,9 @@ cause a heterogeneity bias, i.e. if variables have a within- and/or between-effect (\emph{Bell and Jones, 2015}). } \examples{ -\dontshow{if (insight::check_if_installed("datawizard", minimum_version = "0.12.0", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(iris) iris$ID <- sample(1:4, nrow(iris), replace = TRUE) # fake-ID check_heterogeneity_bias(iris, select = c("Sepal.Length", "Petal.Length"), by = "ID") -\dontshow{\}) # examplesIf} } \references{ \itemize{ diff --git a/tests/testthat/test-check_heterogeneity_bias.R b/tests/testthat/test-check_heterogeneity_bias.R index e01ecf3ff..9701a7c03 100644 --- a/tests/testthat/test-check_heterogeneity_bias.R +++ b/tests/testthat/test-check_heterogeneity_bias.R @@ -1,5 +1,5 @@ test_that("check_heterogeneity_bias", { - skip_if_not_installed("datawizard", minimum_version = "0.12.0") + skip_if_not_installed("datawizard") data(iris) set.seed(123) iris$ID <- sample.int(4, nrow(iris), replace = TRUE) # fake-ID diff --git a/tests/testthat/test-icc.R b/tests/testthat/test-icc.R index 82da6a3eb..73f8b6e3f 100644 --- a/tests/testthat/test-icc.R +++ b/tests/testthat/test-icc.R @@ -121,7 +121,7 @@ test_that("icc", { test_that("icc, glmmTMB 1.1.9+", { - skip_if_not_installed("glmmTMB", minimum_version = "1.1.9") + skip_if_not_installed("glmmTMB") set.seed(101) dd <- data.frame( z = rnorm(1000), diff --git a/tests/testthat/test-r2.R b/tests/testthat/test-r2.R index d7ade6b29..6b4ac0b05 100644 --- a/tests/testthat/test-r2.R +++ b/tests/testthat/test-r2.R @@ -79,6 +79,7 @@ withr::with_environment( out2 <- r2(m2) expect_equal(out[[1]], out2[[1]], tolerance = 1e-3, ignore_attr = TRUE) # zero-inflated -------------------------------------------------------------- + skip_if_not(packageVersion("glmmTMB") > "1.1.10") skip_if_not_installed("pscl") data(bioChemists, package = "pscl") m <- glmmTMB::glmmTMB( @@ -88,16 +89,14 @@ withr::with_environment( data = bioChemists ) out <- r2(m) - expect_equal(out[[1]], 0.14943, tolerance = 1e-3, ignore_attr = TRUE) - ## FIXME: since glmmTMB 1.1.10(?) Pearson residuals differ and results - ## are no longer identical, see https://github.com/glmmTMB/glmmTMB/issues/1101 + expect_equal(out[[1]], 0.1797549, tolerance = 1e-3, ignore_attr = TRUE) # validate against pscl::zeroinfl - # m2 <- pscl::zeroinfl( - # art ~ fem + mar + kid5 + ment | kid5 + phd, - # data = bioChemists - # ) - # out2 <- r2(m2) - # expect_equal(out[[1]], out2[[1]], tolerance = 1e-3, ignore_attr = TRUE) + m2 <- pscl::zeroinfl( + art ~ fem + mar + kid5 + ment | kid5 + phd, + data = bioChemists + ) + out2 <- r2(m2) + expect_equal(out[[1]], out2[[1]], tolerance = 1e-3, ignore_attr = TRUE) # Gamma -------------------------------------------------------------- clotting <<- data.frame( u = c(5, 10, 15, 20, 30, 40, 60, 80, 100), From 6b1020eb802072348253dcbcab38c27a9c2ea495 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 18 Oct 2024 20:39:52 +0200 Subject: [PATCH 10/14] Prepare CRAN submission (#772) --- DESCRIPTION | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 883790eab..826abc7b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.12.3.4 +Version: 0.12.4 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -73,9 +73,9 @@ BugReports: https://github.com/easystats/performance/issues Depends: R (>= 3.6) Imports: - bayestestR (>= 0.14.0), - insight (>= 0.20.4), - datawizard (>= 0.12.3), + bayestestR (>= 0.15.0), + insight (>= 0.20.5), + datawizard (>= 0.13.0), stats, utils Suggests: @@ -160,4 +160,3 @@ Config/Needs/website: r-lib/pkgdown, easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true -Remotes: glmmTMB/glmmTMB/glmmTMB#1102 From 8b52f6cabf7ed3c855bc27fc77f09d984a4c79a7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 21 Oct 2024 10:24:28 +0200 Subject: [PATCH 11/14] update test, due to changes in DHARMa::createData() --- tests/testthat/test-check_residuals.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-check_residuals.R b/tests/testthat/test-check_residuals.R index 9be029c0c..dbaebe447 100644 --- a/tests/testthat/test-check_residuals.R +++ b/tests/testthat/test-check_residuals.R @@ -19,13 +19,13 @@ test_that("check_residuals and simulate_residuals", { # check raw residuals expect_equal( head(residuals(res)), - c(0.55349, 0.44012, 0.39826, 0.9825, 0.90753, 0.05809), + c(0.01815, 0.7062, 0.56076, 0.19282, 0.31423, 0.10115), tolerance = 1e-4, ignore_attr = TRUE ) expect_equal( head(residuals(res, quantile_function = stats::qnorm)), - c(0.13448, -0.15068, -0.25785, 2.10826, 1.3257, -1.57097), + c(-2.09365, 0.54232, 0.1529, -0.86756, -0.4839, -1.27504), tolerance = 1e-4, ignore_attr = TRUE ) @@ -57,10 +57,10 @@ test_that("check_residuals and simulate_residuals", { # check_residuals out <- check_residuals(res) - expect_equal(out, 0.01884602, ignore_attr = TRUE, tolerance = 1e-4) + expect_equal(out, 0.02574286, ignore_attr = TRUE, tolerance = 1e-4) expect_identical( capture.output(print(out)), - "Warning: Non-uniformity of simulated residuals detected (p = 0.019)." + "Warning: Non-uniformity of simulated residuals detected (p = 0.026)." ) expect_error(simulate_residuals(m, iterations = 1), "`iterations` must be") From 90d000834997fa1a593afc8db5d0628c23c2b113 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Oct 2024 10:41:12 +0200 Subject: [PATCH 12/14] docs --- R/performance_aicc.R | 10 ++++++++++ man/performance-package.Rd | 12 ++++++------ man/performance_aicc.Rd | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/R/performance_aicc.R b/R/performance_aicc.R index 52cf3679c..bc1f3e0ab 100644 --- a/R/performance_aicc.R +++ b/R/performance_aicc.R @@ -28,6 +28,9 @@ #' scale. To get back to the original scale, the likelihood of the model is #' multiplied by the Jacobian/derivative of the transformation. #' +#' In case it is not possible to return the corrected AIC value, a waring +#' is given that the corrected log-likelihood value could not be computed. +#' #' @references #' - Akaike, H. (1973) Information theory as an extension of the maximum #' likelihood principle. In: Second International Symposium on Information @@ -52,6 +55,13 @@ #' # performance_aic() correctly detects transformed response and #' # returns corrected AIC #' performance_aic(model) +#' +#' \dontrun{ +#' # there are a few exceptions where the corrected log-likelihood values +#' # cannot be returned. The following exampe gives a warning. +#' model <- lm(1 / mpg ~ factor(cyl), mtcars) +#' performance_aic(model) +#' } #' @export performance_aicc <- function(x, ...) { UseMethod("performance_aicc") diff --git a/man/performance-package.Rd b/man/performance-package.Rd index f7a05c369..4644e6443 100644 --- a/man/performance-package.Rd +++ b/man/performance-package.Rd @@ -34,16 +34,16 @@ Useful links: } \author{ -\strong{Maintainer}: Daniel Lüdecke \email{d.luedecke@uke.de} (\href{https://orcid.org/0000-0002-8895-3206}{ORCID}) (@strengejacke) +\strong{Maintainer}: Daniel Lüdecke \email{d.luedecke@uke.de} (\href{https://orcid.org/0000-0002-8895-3206}{ORCID}) Authors: \itemize{ - \item Dominique Makowski \email{dom.makowski@gmail.com} (\href{https://orcid.org/0000-0001-5375-9967}{ORCID}) (@Dom_Makowski) [contributor] - \item Mattan S. Ben-Shachar \email{matanshm@post.bgu.ac.il} (\href{https://orcid.org/0000-0002-4287-4801}{ORCID}) (@mattansb) [contributor] - \item Indrajeet Patil \email{patilindrajeet.science@gmail.com} (\href{https://orcid.org/0000-0003-1995-6531}{ORCID}) (@patilindrajeets) [contributor] + \item Dominique Makowski \email{dom.makowski@gmail.com} (\href{https://orcid.org/0000-0001-5375-9967}{ORCID}) [contributor] + \item Mattan S. Ben-Shachar \email{matanshm@post.bgu.ac.il} (\href{https://orcid.org/0000-0002-4287-4801}{ORCID}) [contributor] + \item Indrajeet Patil \email{patilindrajeet.science@gmail.com} (\href{https://orcid.org/0000-0003-1995-6531}{ORCID}) [contributor] \item Philip Waggoner \email{philip.waggoner@gmail.com} (\href{https://orcid.org/0000-0002-7825-7573}{ORCID}) [contributor] - \item Brenton M. Wiernik \email{brenton@wiernik.org} (\href{https://orcid.org/0000-0001-9560-6336}{ORCID}) (@bmwiernik) [contributor] - \item Rémi Thériault \email{remi.theriault@mail.mcgill.ca} (\href{https://orcid.org/0000-0003-4315-6788}{ORCID}) (@rempsyc) [contributor] + \item Brenton M. Wiernik \email{brenton@wiernik.org} (\href{https://orcid.org/0000-0001-9560-6336}{ORCID}) [contributor] + \item Rémi Thériault \email{remi.theriault@mail.mcgill.ca} (\href{https://orcid.org/0000-0003-4315-6788}{ORCID}) [contributor] } Other contributors: diff --git a/man/performance_aicc.Rd b/man/performance_aicc.Rd index 0bf2120b7..529ee53aa 100644 --- a/man/performance_aicc.Rd +++ b/man/performance_aicc.Rd @@ -46,6 +46,9 @@ incorporates a correction for small sample sizes. unlike \code{stats::AIC()}, returns the "corrected" AIC value on the original scale. To get back to the original scale, the likelihood of the model is multiplied by the Jacobian/derivative of the transformation. + +In case it is not possible to return the corrected AIC value, a waring +is given that the corrected log-likelihood value could not be computed. } \examples{ m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars) @@ -63,6 +66,13 @@ AIC(model) # performance_aic() correctly detects transformed response and # returns corrected AIC performance_aic(model) + +\dontrun{ +# there are a few exceptions where the corrected log-likelihood values +# cannot be returned. The following exampe gives a warning. +model <- lm(1 / mpg ~ factor(cyl), mtcars) +performance_aic(model) +} } \references{ \itemize{ From c8c81200c91a7339fcc65314081895de12078a71 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Oct 2024 11:05:53 +0200 Subject: [PATCH 13/14] DRY --- DESCRIPTION | 3 +- R/performance_aicc.R | 65 +++----------------------------------------- 2 files changed, 6 insertions(+), 62 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 826abc7b3..2b7fe815a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.12.4 +Version: 0.12.4.1 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -160,3 +160,4 @@ Config/Needs/website: r-lib/pkgdown, easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true +Remotes: easystats/insight diff --git a/R/performance_aicc.R b/R/performance_aicc.R index bc1f3e0ab..eb10bc40f 100644 --- a/R/performance_aicc.R +++ b/R/performance_aicc.R @@ -266,8 +266,6 @@ performance_aicc.rma <- function(x, ...) { } - - # jacobian / derivate for log models and other transformations ---------------- @@ -275,68 +273,13 @@ performance_aicc.rma <- function(x, ...) { .adjust_ic_jacobian <- function(model, ic) { response_transform <- insight::find_transformation(model) if (!is.null(ic) && !is.null(response_transform) && !identical(response_transform, "identity")) { - adjustment <- .safe(.ll_analytic_adjustment(model, insight::get_weights(model, remove_na = TRUE))) + adjustment <- .safe(insight::get_loglikelihood_adjustment( + model, + insight::get_weights(model, remove_na = TRUE) + )) if (!is.null(adjustment)) { ic <- ic - 2 * adjustment } } ic } - - -# copied from `insight` -.ll_analytic_adjustment <- function(x, model_weights = NULL) { - tryCatch( - { - trans <- insight::find_transformation(x) - switch(trans, - identity = .weighted_sum(log(insight::get_response(x)), w = model_weights), - log = .weighted_sum(log(1 / insight::get_response(x)), w = model_weights), - log1p = .weighted_sum(log(1 / (insight::get_response(x) + 1)), w = model_weights), - log2 = .weighted_sum(log(1 / (insight::get_response(x) * log(2))), w = model_weights), - log10 = .weighted_sum(log(1 / (insight::get_response(x) * log(10))), w = model_weights), - exp = .weighted_sum(insight::get_response(x), w = model_weights), - expm1 = .weighted_sum((insight::get_response(x) - 1), w = model_weights), - sqrt = .weighted_sum(log(0.5 / sqrt(insight::get_response(x))), w = model_weights), - .ll_jacobian_adjustment(x, model_weights) - ) - }, - error = function(e) { - NULL - } - ) -} - - -# this function calculates the adjustment for the log-likelihood of a model -# with transformed response -.ll_jacobian_adjustment <- function(model, weights = NULL) { - tryCatch( - { - trans <- insight::get_transformation(model)$transformation - .weighted_sum(log( - diag(attr(with( - insight::get_data(model, verbose = FALSE), - stats::numericDeriv( - expr = quote(trans( - get(insight::find_response(model)) - )), - theta = insight::find_response(model) - ) - ), "gradient")) - ), weights) - }, - error = function(e) { - NULL - } - ) -} - - -.weighted_sum <- function(x, w = NULL, ...) { - if (is.null(w)) { - mean(x) * length(x) - } else { - stats::weighted.mean(x, w) * length(x) - } -} From 0aa349233fd2ba62399f5caf16cbe89511b999ac Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Oct 2024 12:59:00 +0200 Subject: [PATCH 14/14] Remove deprecated functions and arguments (#774) --- DESCRIPTION | 6 +++--- NAMESPACE | 2 -- NEWS.md | 10 ++++++++++ R/check_convergence.R | 5 +++-- R/check_heterogeneity_bias.R | 9 +-------- R/check_predictions.R | 20 -------------------- R/performance_aicc.R | 2 +- R/simulate_residuals.R | 7 ++++--- man/check_heterogeneity_bias.Rd | 10 +--------- man/check_predictions.Rd | 6 ------ man/performance_aicc.Rd | 2 +- tests/testthat/test-check_zeroinflation.R | 22 +++++++++++----------- 12 files changed, 35 insertions(+), 66 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2b7fe815a..abac13053 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.12.4.1 +Version: 0.12.4.2 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -95,7 +95,7 @@ Suggests: cplm, dagitty, dbscan, - DHARMa, + DHARMa (>= 0.4.7), estimatr, fixest, flextable, @@ -129,7 +129,7 @@ Suggests: nonnest2, ordinal, parallel, - parameters (>= 0.21.6), + parameters (>= 0.22.0), patchwork, pscl, psych, diff --git a/NAMESPACE b/NAMESPACE index 08f6bcc15..d35d82547 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -566,7 +566,6 @@ export(check_multimodal) export(check_normality) export(check_outliers) export(check_overdispersion) -export(check_posterior_predictions) export(check_predictions) export(check_residuals) export(check_singularity) @@ -602,7 +601,6 @@ export(performance_rmse) export(performance_roc) export(performance_rse) export(performance_score) -export(posterior_predictive_check) export(print_html) export(print_md) export(r2) diff --git a/NEWS.md b/NEWS.md index 4f0984b48..9eb5ded26 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# performance 0.12.5 + +## Breaking changes + +* Deprecated arguments and alias-function-names have been removed. + +## Changes + +* Increased accuracy for `check_convergence()` for *glmmTMB* models. + # performance 0.12.4 ## Changes diff --git a/R/check_convergence.R b/R/check_convergence.R index 6f7628a12..f60a7e298 100644 --- a/R/check_convergence.R +++ b/R/check_convergence.R @@ -98,9 +98,10 @@ check_convergence.merMod <- function(x, tolerance = 0.001, ...) { #' @export -check_convergence.glmmTMB <- function(x, ...) { +check_convergence.glmmTMB <- function(x, tolerance = 0.001, ...) { # https://github.com/glmmTMB/glmmTMB/issues/275 - isTRUE(x$sdr$pdHess) + # https://stackoverflow.com/q/79110546/2094622 + isTRUE(all.equal(x$fit$convergence, 0, tolerance = tolerance)) && isTRUE(x$sdr$pdHess) } diff --git a/R/check_heterogeneity_bias.R b/R/check_heterogeneity_bias.R index 755f47dfa..2414873cc 100644 --- a/R/check_heterogeneity_bias.R +++ b/R/check_heterogeneity_bias.R @@ -27,7 +27,6 @@ #' @param nested Logical, if `TRUE`, the data is treated as nested. If `FALSE`, #' the data is treated as cross-classified. Only applies if `by` contains more #' than one variable. -#' @param group Deprecated. Use `by` instead. #' #' @seealso #' For further details, read the vignette @@ -44,15 +43,9 @@ #' iris$ID <- sample(1:4, nrow(iris), replace = TRUE) # fake-ID #' check_heterogeneity_bias(iris, select = c("Sepal.Length", "Petal.Length"), by = "ID") #' @export -check_heterogeneity_bias <- function(x, select = NULL, by = NULL, nested = FALSE, group = NULL) { +check_heterogeneity_bias <- function(x, select = NULL, by = NULL, nested = FALSE) { insight::check_if_installed("datawizard", minimum_version = "0.12.0") - ## TODO: deprecate later - if (!is.null(group)) { - insight::format_warning("Argument `group` is deprecated and will be removed in a future release. Please use `by` instead.") # nolint - by <- group - } - if (insight::is_model(x)) { by <- insight::find_random(x, split_nested = TRUE, flatten = TRUE) if (is.null(by)) { diff --git a/R/check_predictions.R b/R/check_predictions.R index fbc3b5eaf..c903f4309 100644 --- a/R/check_predictions.R +++ b/R/check_predictions.R @@ -423,26 +423,6 @@ pp_check.glmmTMB <- #' S3method(bayesplot::pp_check, BFBayesFactor) - -# aliases -------------------------- - -#' @rdname check_predictions -#' @export -posterior_predictive_check <- function(object, ...) { - .Deprecated("check_predictions()") - check_predictions(object, ...) -} - -#' @rdname check_predictions -#' @export -check_posterior_predictions <- function(object, ...) { - .Deprecated("check_predictions()") - check_predictions(object, ...) -} - - - - # methods ----------------------- diff --git a/R/performance_aicc.R b/R/performance_aicc.R index eb10bc40f..74041ac1b 100644 --- a/R/performance_aicc.R +++ b/R/performance_aicc.R @@ -28,7 +28,7 @@ #' scale. To get back to the original scale, the likelihood of the model is #' multiplied by the Jacobian/derivative of the transformation. #' -#' In case it is not possible to return the corrected AIC value, a waring +#' In case it is not possible to return the corrected AIC value, a warning #' is given that the corrected log-likelihood value could not be computed. #' #' @references diff --git a/R/simulate_residuals.R b/R/simulate_residuals.R index 7312c196f..1f58218c0 100644 --- a/R/simulate_residuals.R +++ b/R/simulate_residuals.R @@ -65,9 +65,10 @@ #' @export simulate_residuals <- function(x, iterations = 250, ...) { insight::check_if_installed("DHARMa") - # TODO (low priority): Note that DHARMa::simulateResiduals(x, ...) does its own checks for whether - # or not the model passed to it is supported, do we want to use this or do our - # own checks so we can supply our own error message? + # TODO (low priority): Note that DHARMa::simulateResiduals(x, ...) does its + # own checks for whether or not the model passed to it is supported, do we + # want to use this or do our own checks so we can supply our own error + # message? if (iterations < 2) { insight::format_error("`iterations` must be at least 2.") } diff --git a/man/check_heterogeneity_bias.Rd b/man/check_heterogeneity_bias.Rd index 40b2b66ca..db18ae7ef 100644 --- a/man/check_heterogeneity_bias.Rd +++ b/man/check_heterogeneity_bias.Rd @@ -4,13 +4,7 @@ \alias{check_heterogeneity_bias} \title{Check model predictor for heterogeneity bias} \usage{ -check_heterogeneity_bias( - x, - select = NULL, - by = NULL, - nested = FALSE, - group = NULL -) +check_heterogeneity_bias(x, select = NULL, by = NULL, nested = FALSE) } \arguments{ \item{x}{A data frame or a mixed model object.} @@ -41,8 +35,6 @@ See also section \emph{De-meaning for cross-classified designs} and \item{nested}{Logical, if \code{TRUE}, the data is treated as nested. If \code{FALSE}, the data is treated as cross-classified. Only applies if \code{by} contains more than one variable.} - -\item{group}{Deprecated. Use \code{by} instead.} } \description{ \code{check_heterogeneity_bias()} checks if model predictors or variables may diff --git a/man/check_predictions.Rd b/man/check_predictions.Rd index 148df6994..6c13fc0d5 100644 --- a/man/check_predictions.Rd +++ b/man/check_predictions.Rd @@ -3,8 +3,6 @@ \name{check_predictions} \alias{check_predictions} \alias{check_predictions.default} -\alias{posterior_predictive_check} -\alias{check_posterior_predictions} \title{Posterior predictive checks} \usage{ check_predictions(object, ...) @@ -19,10 +17,6 @@ check_predictions(object, ...) verbose = TRUE, ... ) - -posterior_predictive_check(object, ...) - -check_posterior_predictions(object, ...) } \arguments{ \item{object}{A statistical model.} diff --git a/man/performance_aicc.Rd b/man/performance_aicc.Rd index 529ee53aa..b1d9a1255 100644 --- a/man/performance_aicc.Rd +++ b/man/performance_aicc.Rd @@ -47,7 +47,7 @@ unlike \code{stats::AIC()}, returns the "corrected" AIC value on the original scale. To get back to the original scale, the likelihood of the model is multiplied by the Jacobian/derivative of the transformation. -In case it is not possible to return the corrected AIC value, a waring +In case it is not possible to return the corrected AIC value, a warning is given that the corrected log-likelihood value could not be computed. } \examples{ diff --git a/tests/testthat/test-check_zeroinflation.R b/tests/testthat/test-check_zeroinflation.R index 38a5c7726..53f8af9f5 100644 --- a/tests/testthat/test-check_zeroinflation.R +++ b/tests/testthat/test-check_zeroinflation.R @@ -111,22 +111,22 @@ test_that("check_zeroinflation, glmmTMB nbinom", { skip_if_not_installed("DHARMa") skip_on_cran() + data(Salamanders, package = "glmmTMB") + m <- glmmTMB::glmmTMB( + count ~ spp + mined + (1 | site), + family = glmmTMB::nbinom1(), + data = Salamanders + ) set.seed(1234) - dat <- DHARMa::createData(sampleSize = 1000) - fit <- suppressWarnings(glmmTMB::glmmTMB( - observedResponse ~ Environment1 + (1 | group), - data = dat, - family = glmmTMB::nbinom1() - )) expect_equal( - check_zeroinflation(fit), + check_zeroinflation(m), structure( list( - predicted.zeros = 462, - observed.zeros = 482L, - ratio = 0.95850622406639, + predicted.zeros = 389, + observed.zeros = 387L, + ratio = 1.00635658914729, tolerance = 0.1, - p.value = 0.776 + p.value = 0.944 ), class = "check_zi" ),