From 43ef485e0535275689bd7d67573efd917ea91efe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 5 Oct 2025 19:49:39 +0000 Subject: [PATCH 01/12] Initial plan From cafab505a605e9f6b89395e82b7f51a1c26dbd0c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 5 Oct 2025 19:53:51 +0000 Subject: [PATCH 02/12] Add validation to ensure es_type only used with effectsize='boot' Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> --- R/estimate_contrasts.R | 6 ++++ .../test-estimate_contrasts_effectsize.R | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/R/estimate_contrasts.R b/R/estimate_contrasts.R index c777e6253..b989f89c4 100644 --- a/R/estimate_contrasts.R +++ b/R/estimate_contrasts.R @@ -317,6 +317,12 @@ estimate_contrasts.default <- function( # validate input estimate <- .validate_estimate_arg(estimate) comparison <- .check_for_inequality_comparison(comparison) + + # Validate es_type usage + call_args <- match.call() + if ("es_type" %in% names(call_args) && !is.null(effectsize) && effectsize != "boot") { + insight::format_error("`es_type` can only be used when `effectsize = \"boot\"`.") + } if (backend == "emmeans") { # Emmeans ---------------------------------------------------------------- diff --git a/tests/testthat/test-estimate_contrasts_effectsize.R b/tests/testthat/test-estimate_contrasts_effectsize.R index 52346c495..01252a37d 100644 --- a/tests/testthat/test-estimate_contrasts_effectsize.R +++ b/tests/testthat/test-estimate_contrasts_effectsize.R @@ -65,3 +65,33 @@ test_that("estimate_contrasts - random effects", { "We strongly recommend not using" ) }) + +test_that("estimate_contrasts - es_type only with effectsize='boot'", { + # Should error when es_type is used with effectsize != "boot" + expect_error( + estimate_contrasts(model, effectsize = "emmeans", es_type = "hedges.g", backend = "emmeans"), + "can only be used when" + ) + + expect_error( + estimate_contrasts(model, effectsize = "marginal", es_type = "hedges.g", backend = "emmeans"), + "can only be used when" + ) + + expect_error( + estimate_contrasts(model, effectsize = "marginal", es_type = "hedges.g", backend = "marginaleffects"), + "can only be used when" + ) + + # Should work when es_type is used with effectsize = "boot" + set.seed(100) + result <- estimate_contrasts(model, effectsize = "boot", es_type = "hedges.g", backend = "emmeans") + expect_s3_class(result, "estimate_contrasts") + + # Should work when es_type is NOT specified (using default) + result_emmeans <- estimate_contrasts(model, effectsize = "emmeans", backend = "emmeans") + expect_s3_class(result_emmeans, "estimate_contrasts") + + result_marginal <- estimate_contrasts(model, effectsize = "marginal", backend = "emmeans") + expect_s3_class(result_marginal, "estimate_contrasts") +}) From cc1e795229e9181f7b7820bd95186fba48ad7bf7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 5 Oct 2025 19:56:00 +0000 Subject: [PATCH 03/12] Improve validation to also error when es_type used with effectsize=NULL Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> --- R/estimate_contrasts.R | 8 ++++++-- tests/testthat/test-estimate_contrasts_effectsize.R | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/R/estimate_contrasts.R b/R/estimate_contrasts.R index b989f89c4..ec025778c 100644 --- a/R/estimate_contrasts.R +++ b/R/estimate_contrasts.R @@ -320,8 +320,12 @@ estimate_contrasts.default <- function( # Validate es_type usage call_args <- match.call() - if ("es_type" %in% names(call_args) && !is.null(effectsize) && effectsize != "boot") { - insight::format_error("`es_type` can only be used when `effectsize = \"boot\"`.") + if ("es_type" %in% names(call_args)) { + if (is.null(effectsize)) { + insight::format_error("`es_type` can only be used when `effectsize` is specified. Currently `effectsize = NULL`.") + } else if (effectsize != "boot") { + insight::format_error("`es_type` can only be used when `effectsize = \"boot\"`.") + } } if (backend == "emmeans") { diff --git a/tests/testthat/test-estimate_contrasts_effectsize.R b/tests/testthat/test-estimate_contrasts_effectsize.R index 01252a37d..97b2fcf07 100644 --- a/tests/testthat/test-estimate_contrasts_effectsize.R +++ b/tests/testthat/test-estimate_contrasts_effectsize.R @@ -83,6 +83,12 @@ test_that("estimate_contrasts - es_type only with effectsize='boot'", { "can only be used when" ) + # Should error when es_type is used with effectsize = NULL + expect_error( + estimate_contrasts(model, es_type = "hedges.g", backend = "emmeans"), + "can only be used when" + ) + # Should work when es_type is used with effectsize = "boot" set.seed(100) result <- estimate_contrasts(model, effectsize = "boot", es_type = "hedges.g", backend = "emmeans") From fbebfd3cac37385322acc35ee2e7ff217514e624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:28:15 -0400 Subject: [PATCH 04/12] Update R/estimate_contrasts.R [skip ci] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- R/estimate_contrasts.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/estimate_contrasts.R b/R/estimate_contrasts.R index ec025778c..11ff11e4a 100644 --- a/R/estimate_contrasts.R +++ b/R/estimate_contrasts.R @@ -317,7 +317,6 @@ estimate_contrasts.default <- function( # validate input estimate <- .validate_estimate_arg(estimate) comparison <- .check_for_inequality_comparison(comparison) - # Validate es_type usage call_args <- match.call() if ("es_type" %in% names(call_args)) { From d273af4b9b170e89906a55510fae67a1206c345f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:28:54 -0400 Subject: [PATCH 05/12] Update tests/testthat/test-estimate_contrasts_effectsize.R [skip ci] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/testthat/test-estimate_contrasts_effectsize.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-estimate_contrasts_effectsize.R b/tests/testthat/test-estimate_contrasts_effectsize.R index 97b2fcf07..a243e1502 100644 --- a/tests/testthat/test-estimate_contrasts_effectsize.R +++ b/tests/testthat/test-estimate_contrasts_effectsize.R @@ -69,7 +69,12 @@ test_that("estimate_contrasts - random effects", { test_that("estimate_contrasts - es_type only with effectsize='boot'", { # Should error when es_type is used with effectsize != "boot" expect_error( - estimate_contrasts(model, effectsize = "emmeans", es_type = "hedges.g", backend = "emmeans"), + estimate_contrasts( + model, + effectsize = "emmeans", + es_type = "hedges.g", + backend = "emmeans" + ), "can only be used when" ) From e73655e69ad936bd15c7c2a49b0b3e287315a30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:29:06 -0400 Subject: [PATCH 06/12] Update tests/testthat/test-estimate_contrasts_effectsize.R [skip ci] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/testthat/test-estimate_contrasts_effectsize.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-estimate_contrasts_effectsize.R b/tests/testthat/test-estimate_contrasts_effectsize.R index a243e1502..d93c5c215 100644 --- a/tests/testthat/test-estimate_contrasts_effectsize.R +++ b/tests/testthat/test-estimate_contrasts_effectsize.R @@ -77,7 +77,6 @@ test_that("estimate_contrasts - es_type only with effectsize='boot'", { ), "can only be used when" ) - expect_error( estimate_contrasts(model, effectsize = "marginal", es_type = "hedges.g", backend = "emmeans"), "can only be used when" From 68d30a6c0122ac3243f31d7abf7f79b888a81192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:35:39 -0400 Subject: [PATCH 07/12] air because reviewdog is being really annoying right now --- R/estimate_contrasts.R | 4 +- .../test-estimate_contrasts_effectsize.R | 82 ++++++++++++------- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/R/estimate_contrasts.R b/R/estimate_contrasts.R index 11ff11e4a..4a2fc9ddf 100644 --- a/R/estimate_contrasts.R +++ b/R/estimate_contrasts.R @@ -321,7 +321,9 @@ estimate_contrasts.default <- function( call_args <- match.call() if ("es_type" %in% names(call_args)) { if (is.null(effectsize)) { - insight::format_error("`es_type` can only be used when `effectsize` is specified. Currently `effectsize = NULL`.") + insight::format_error( + "`es_type` can only be used when `effectsize` is specified. Currently `effectsize = NULL`." + ) } else if (effectsize != "boot") { insight::format_error("`es_type` can only be used when `effectsize = \"boot\"`.") } diff --git a/tests/testthat/test-estimate_contrasts_effectsize.R b/tests/testthat/test-estimate_contrasts_effectsize.R index d93c5c215..1db8b620a 100644 --- a/tests/testthat/test-estimate_contrasts_effectsize.R +++ b/tests/testthat/test-estimate_contrasts_effectsize.R @@ -10,54 +10,64 @@ data(iris) model <- lm(Sepal.Width ~ Species, data = iris) test_that("estimate_contrasts - emmeans backend", { - expect_snapshot(estimate_contrasts(model, backend = "emmeans"), + expect_snapshot(estimate_contrasts(model, backend = "emmeans"), variant = "windows") + expect_snapshot( + estimate_contrasts(model, effectsize = "none", backend = "emmeans"), variant = "windows" ) - expect_snapshot(estimate_contrasts(model, effectsize = "none", backend = "emmeans"), + expect_snapshot( + estimate_contrasts(model, effectsize = "emmeans", backend = "emmeans"), variant = "windows" ) - expect_snapshot(estimate_contrasts(model, effectsize = "emmeans", backend = "emmeans"), + expect_snapshot( + estimate_contrasts(model, effectsize = "marginal", backend = "emmeans"), variant = "windows" ) - expect_snapshot(estimate_contrasts(model, effectsize = "marginal", backend = "emmeans"), + set.seed(100) + expect_snapshot( + estimate_contrasts(model, effectsize = "boot", backend = "emmeans"), variant = "windows" ) set.seed(100) - expect_snapshot(estimate_contrasts(model, effectsize = "boot", backend = "emmeans"), + expect_snapshot( + estimate_contrasts( + model, + effectsize = "boot", + es_type = "akp.robust.d", + backend = "emmeans" + ), variant = "windows" ) set.seed(100) - expect_snapshot(estimate_contrasts(model, - effectsize = "boot", - es_type = "akp.robust.d", - backend = "emmeans" - ), variant = "windows") - set.seed(100) - expect_snapshot(estimate_contrasts( - model, - effectsize = "boot", - es_type = "hedges.g", - backend = "emmeans" - ), variant = "windows") + expect_snapshot( + estimate_contrasts(model, effectsize = "boot", es_type = "hedges.g", backend = "emmeans"), + variant = "windows" + ) }) test_that("estimate_contrasts - marginaleffects backend", { expect_snapshot(estimate_contrasts(model, backend = "marginaleffects"), variant = "windows") - expect_snapshot(estimate_contrasts(model, effectsize = "none", backend = "marginaleffects"), + expect_snapshot( + estimate_contrasts(model, effectsize = "none", backend = "marginaleffects"), variant = "windows" ) expect_error( estimate_contrasts(model, effectsize = "emmeans", backend = "marginaleffects"), "only possible with" ) - expect_snapshot(estimate_contrasts(model, effectsize = "marginal", backend = "marginaleffects"), + expect_snapshot( + estimate_contrasts(model, effectsize = "marginal", backend = "marginaleffects"), variant = "windows" ) }) test_that("estimate_contrasts - random effects", { sleepstudy <- lme4::sleepstudy - sleepstudy$Days_factor <- cut(sleepstudy$Days, breaks = 3, labels = c("Low", "Medium", "High")) + sleepstudy$Days_factor <- cut( + sleepstudy$Days, + breaks = 3, + labels = c("Low", "Medium", "High") + ) model_random_effects <- lme4::lmer(Reaction ~ Days_factor + (1 | Subject), data = sleepstudy) expect_error( @@ -77,31 +87,47 @@ test_that("estimate_contrasts - es_type only with effectsize='boot'", { ), "can only be used when" ) + expect_error( - estimate_contrasts(model, effectsize = "marginal", es_type = "hedges.g", backend = "emmeans"), + estimate_contrasts( + model, + effectsize = "marginal", + es_type = "hedges.g", + backend = "emmeans" + ), "can only be used when" ) - + expect_error( - estimate_contrasts(model, effectsize = "marginal", es_type = "hedges.g", backend = "marginaleffects"), + estimate_contrasts( + model, + effectsize = "marginal", + es_type = "hedges.g", + backend = "marginaleffects" + ), "can only be used when" ) - + # Should error when es_type is used with effectsize = NULL expect_error( estimate_contrasts(model, es_type = "hedges.g", backend = "emmeans"), "can only be used when" ) - + # Should work when es_type is used with effectsize = "boot" set.seed(100) - result <- estimate_contrasts(model, effectsize = "boot", es_type = "hedges.g", backend = "emmeans") + result <- estimate_contrasts( + model, + effectsize = "boot", + es_type = "hedges.g", + backend = "emmeans" + ) expect_s3_class(result, "estimate_contrasts") - + # Should work when es_type is NOT specified (using default) result_emmeans <- estimate_contrasts(model, effectsize = "emmeans", backend = "emmeans") expect_s3_class(result_emmeans, "estimate_contrasts") - + result_marginal <- estimate_contrasts(model, effectsize = "marginal", backend = "emmeans") expect_s3_class(result_marginal, "estimate_contrasts") }) From 63a6934df8a327276c9deeed4abc79cf91452857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:50:42 -0400 Subject: [PATCH 08/12] spellcheck, wordlist --- R/estimate_means.R | 40 +++++++++-------- inst/WORDLIST | 99 ++++++++++++------------------------------- man/estimate_means.Rd | 2 +- 3 files changed, 50 insertions(+), 91 deletions(-) diff --git a/R/estimate_means.R b/R/estimate_means.R index 07860b417..223592d12 100644 --- a/R/estimate_means.R +++ b/R/estimate_means.R @@ -306,7 +306,7 @@ #' #' The output from `equivalence_test()` returns a column `SGPV`, the "second #' generation p-value", which is equivalent to the `p (Equivalence)` column when -#' using the `equivalence` argument. It is basically representiv the ROPE coverage +#' using the `equivalence` argument. It is basically representative of the ROPE coverage #' from the confidence interval of the estimate (i.e. the proportion of the #' confidence intervals that lies within the region of practical equivalence). #' @@ -414,16 +414,18 @@ #' estimate_means(model, by = "Sepal.Width", length = 3) #' } #' @export -estimate_means <- function(model, - by = "auto", - predict = NULL, - ci = 0.95, - estimate = NULL, - transform = NULL, - keep_iterations = FALSE, - backend = NULL, - verbose = TRUE, - ...) { +estimate_means <- function( + model, + by = "auto", + predict = NULL, + ci = 0.95, + estimate = NULL, + transform = NULL, + keep_iterations = FALSE, + backend = NULL, + verbose = TRUE, + ... +) { # Process argument --------------------------------------------------------- # -------------------------------------------------------------------------- @@ -469,12 +471,16 @@ estimate_means <- function(model, info <- attributes(estimated) # Table formatting - attr(means, "table_title") <- c(switch(estimate, - specific = "Model-based Predictions", - typical = "Estimated Marginal Means", - average = "Average Predictions", - population = "Average Counterfactual Predictions" - ), "blue") + attr(means, "table_title") <- c( + switch( + estimate, + specific = "Model-based Predictions", + typical = "Estimated Marginal Means", + average = "Average Predictions", + population = "Average Counterfactual Predictions" + ), + "blue" + ) attr(means, "table_footer") <- .table_footer( means, diff --git a/inst/WORDLIST b/inst/WORDLIST index 22430aa17..c1057ba81 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,45 +1,39 @@ -’s ANCOVAs -Arel -ATE ATEs ATT ATU +Analysing +Arel Axelsson -BH BLUPs Bundock -cdot -Chatton CJ -coefficients’ -diag -Dickerman -Dom +Chatton DS +Dickerman EFC EMM EMMs EUROFAMCARE Fitzsimons GAMM +GLM's GLMM GLMMs -GLM's GMM GMMs Greifer Heiss -Hernan Hernán ICC's ICCs IPW Intersectional Intersectionality +JOSS +LM Leckie Lenth -LM MAIHDA Mattan McCabe @@ -49,37 +43,34 @@ Merlo Mize Mmmh Modelisation -Modelling -Møller Montiel Mulinari +Møller Neyman -Olea +Nonresponse ORCID +Olea Owww -PCVs PCV +PCVs Plagborg -QoL Psychometrika +QoL RCTs README -Rohrer RStudio RTs Ratcliff -Reproducibility -Rescaling +Rohrer +SSM +SV +SVARs Setosa Shachar Spiller -SSM Subramanian -SV -SVARs Versicolor Virginica -Visualisation Visualising Wagenmakers Weisberg @@ -87,40 +78,30 @@ Wemrell Wiernik al analysing -bc behaviour -blogpost -bocode -bonferroni bootES brglm brms -caregiving +cdot ception codecov -computable +coefficients’ conditionspeed -counterfactuals confounder -confounders coxme d'être -d’être dat datagrid datawizard +diag doi dpar +d’être easystats -edu -effectsize emmeans -emtrends et exchangeability favour -fdr -fmwww foR generalizability geoms @@ -128,75 +109,47 @@ ggplot github glmmTMB glms -grano grey -hochberg -holm -hommel -http https -individuals' -interpretable +individuals’ intersectional intersectionality intra -io jmr joss labelled -lifecycle lme -lme4 loess marginaleffects -marginalizations mattansb modelisation modelled modelling -natively nd nnet ol onwards partialled -patilindrajeets -pscl pre -quartiles +pscl rOpenSci -Remotes raison -recoding -recodings -repec -reproducibility -rescaled -rescales -residualize residualized +residualizes rootSolve rstanarm -salis spinoff ssmph -strengejacke -summarised summarises -terciles -transint -tukey -ultron -uninformativeness +tinyplot unidimensional +uninformativeness unstandardizing usecases versicolor virginica visualisation visualise -visualising walkthrough -Nonresponse -tinyplot ’ +’s diff --git a/man/estimate_means.Rd b/man/estimate_means.Rd index 906f04894..8802eee86 100644 --- a/man/estimate_means.Rd +++ b/man/estimate_means.Rd @@ -351,7 +351,7 @@ p-values returned when using the \code{equivalence} argument. The output from \code{equivalence_test()} returns a column \code{SGPV}, the "second generation p-value", which is equivalent to the \code{p (Equivalence)} column when -using the \code{equivalence} argument. It is basically representiv the ROPE coverage +using the \code{equivalence} argument. It is basically representative of the ROPE coverage from the confidence interval of the estimate (i.e. the proportion of the confidence intervals that lies within the region of practical equivalence). } From f9d311be6b53e16498fade9ceb016d7877640ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Sun, 5 Oct 2025 17:08:30 -0400 Subject: [PATCH 09/12] Update R/estimate_contrasts.R Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- R/estimate_contrasts.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/estimate_contrasts.R b/R/estimate_contrasts.R index 4a2fc9ddf..6424a4f92 100644 --- a/R/estimate_contrasts.R +++ b/R/estimate_contrasts.R @@ -322,7 +322,7 @@ estimate_contrasts.default <- function( if ("es_type" %in% names(call_args)) { if (is.null(effectsize)) { insight::format_error( - "`es_type` can only be used when `effectsize` is specified. Currently `effectsize = NULL`." + "`es_type` can only be used when `effectsize = \"boot\"`." ) } else if (effectsize != "boot") { insight::format_error("`es_type` can only be used when `effectsize = \"boot\"`.") From f2ba8b3605f868d1c27e5e59e1db6198852c8928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Sun, 5 Oct 2025 17:20:19 -0400 Subject: [PATCH 10/12] air because of annoying dog --- R/estimate_contrasts.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/estimate_contrasts.R b/R/estimate_contrasts.R index 6424a4f92..4a2fc9ddf 100644 --- a/R/estimate_contrasts.R +++ b/R/estimate_contrasts.R @@ -322,7 +322,7 @@ estimate_contrasts.default <- function( if ("es_type" %in% names(call_args)) { if (is.null(effectsize)) { insight::format_error( - "`es_type` can only be used when `effectsize = \"boot\"`." + "`es_type` can only be used when `effectsize` is specified. Currently `effectsize = NULL`." ) } else if (effectsize != "boot") { insight::format_error("`es_type` can only be used when `effectsize = \"boot\"`.") From 5ff532c09569e4be953539871ac76a8deec33450 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 6 Oct 2025 08:49:36 +0200 Subject: [PATCH 11/12] refactor --- R/estimate_contrasts.R | 20 ++++++++------------ R/estimate_contrasts_effectsize.R | 8 ++++++++ man/estimate_contrasts.Rd | 6 ++++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/R/estimate_contrasts.R b/R/estimate_contrasts.R index 4a2fc9ddf..b7af196ea 100644 --- a/R/estimate_contrasts.R +++ b/R/estimate_contrasts.R @@ -71,8 +71,9 @@ #' size will be computed. #' @param es_type Specifies the type of effect-size measure to estimate when #' using `effectsize = "boot"`. One of `"unstandardized"`, `"cohens.d"`, -#' `"hedges.g"`, `"cohens.d.sigma"`, `"r"`, or `"akp.robust.d"`. See` -#' effect.type` argument of [bootES::bootES] for details. +#' `"hedges.g"`, `"cohens.d.sigma"`, `"r"`, or `"akp.robust.d"`. See `effect.type` +#' argument of [`bootES::bootES()`] for details. If not specified, defaults to +#' `"cohens.d"`. #' @param iterations The number of bootstrap resamples to perform. #' @inheritParams estimate_means #' @@ -301,7 +302,7 @@ estimate_contrasts.default <- function( keep_iterations = FALSE, effectsize = NULL, iterations = 200, - es_type = "cohens.d", + es_type = NULL, backend = NULL, verbose = TRUE, ... @@ -318,15 +319,10 @@ estimate_contrasts.default <- function( estimate <- .validate_estimate_arg(estimate) comparison <- .check_for_inequality_comparison(comparison) # Validate es_type usage - call_args <- match.call() - if ("es_type" %in% names(call_args)) { - if (is.null(effectsize)) { - insight::format_error( - "`es_type` can only be used when `effectsize` is specified. Currently `effectsize = NULL`." - ) - } else if (effectsize != "boot") { - insight::format_error("`es_type` can only be used when `effectsize = \"boot\"`.") - } + if (is.null(effectsize) && !is.null(es_type)) { + insight::format_error( + "`es_type` can only be used when `effectsize` is specified. Currently `effectsize = NULL`." + ) } if (backend == "emmeans") { diff --git a/R/estimate_contrasts_effectsize.R b/R/estimate_contrasts_effectsize.R index ce683c357..534687975 100644 --- a/R/estimate_contrasts_effectsize.R +++ b/R/estimate_contrasts_effectsize.R @@ -12,6 +12,10 @@ insight::format_error("`effectsize = \"emmeans\"` only possible with `backend = \"emmeans\"`") } + if (!is.null(bootES_type) && effectsize != "boot") { + insight::format_error("`es_type` can only be used when `effectsize = \"boot\"`.") + } + # Check if the model includes any random effects. Effect size calculations in # the current implementation are not designed for, or may not be appropriate # for, models with random effects. Random effects complicate the calculation @@ -58,6 +62,10 @@ contrasts_results <- cbind(contrasts_results, marginal_d = d_adj) }, boot = { + # set default + if (is.null(bootES_type)) { + bootES_type <- "cohens.d" + } insight::check_if_installed("bootES") dat <- insight::get_data(model) resp <- insight::find_response(model) diff --git a/man/estimate_contrasts.Rd b/man/estimate_contrasts.Rd index 7bbdfcaa7..c49262e5e 100644 --- a/man/estimate_contrasts.Rd +++ b/man/estimate_contrasts.Rd @@ -20,7 +20,7 @@ estimate_contrasts(model, ...) keep_iterations = FALSE, effectsize = NULL, iterations = 200, - es_type = "cohens.d", + es_type = NULL, backend = NULL, verbose = TRUE, ... @@ -244,7 +244,9 @@ size will be computed.} \item{es_type}{Specifies the type of effect-size measure to estimate when using \code{effectsize = "boot"}. One of \code{"unstandardized"}, \code{"cohens.d"}, -\code{"hedges.g"}, \code{"cohens.d.sigma"}, \code{"r"}, or \code{"akp.robust.d"}. See\code{ effect.type} argument of \link[bootES:bootES]{bootES::bootES} for details.} +\code{"hedges.g"}, \code{"cohens.d.sigma"}, \code{"r"}, or \code{"akp.robust.d"}. See \code{effect.type} +argument of \code{\link[bootES:bootES]{bootES::bootES()}} for details. If not specified, defaults to +\code{"cohens.d"}.} \item{backend}{Whether to use \code{"marginaleffects"} (default) or \code{"emmeans"} as a backend. Results are usually very similar. The major difference will be From db77b9ba50af8db94d569a1975a33ae1505167dc Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 6 Oct 2025 08:51:02 +0200 Subject: [PATCH 12/12] air --- R/estimate_contrasts_effectsize.R | 33 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/R/estimate_contrasts_effectsize.R b/R/estimate_contrasts_effectsize.R index 534687975..242cb9d7a 100644 --- a/R/estimate_contrasts_effectsize.R +++ b/R/estimate_contrasts_effectsize.R @@ -1,15 +1,19 @@ -.estimate_contrasts_effectsize <- function(model, - estimated, - contrasts_results, - effectsize, - bootstraps, - bootES_type, - backend) { +.estimate_contrasts_effectsize <- function( + model, + estimated, + contrasts_results, + effectsize, + bootstraps, + bootES_type, + backend +) { # Add standardized effect size insight::validate_argument(effectsize, c("none", "emmeans", "marginal", "boot")) if (effectsize == "emmeans" && backend != "emmeans") { - insight::format_error("`effectsize = \"emmeans\"` only possible with `backend = \"emmeans\"`") + insight::format_error( + "`effectsize = \"emmeans\"` only possible with `backend = \"emmeans\"`" + ) } if (!is.null(bootES_type) && effectsize != "boot") { @@ -40,7 +44,8 @@ )) } - switch(effectsize, + switch( + effectsize, emmeans = { eff <- emmeans::eff_size( estimated, @@ -58,7 +63,9 @@ # d_adj <- contrasts$t * contrasts$SE / sigma(model) * sqrt(1 - R2) # New: d_adj <- difference * (1- R2)/ sigma R2 <- summary(model)$r.squared - d_adj <- contrasts_results$Difference * (1 - R2) / insight::get_sigma(model, verbose = FALSE) + d_adj <- contrasts_results$Difference * + (1 - R2) / + insight::get_sigma(model, verbose = FALSE) contrasts_results <- cbind(contrasts_results, marginal_d = d_adj) }, boot = { @@ -92,7 +99,11 @@ eff <- do.call(rbind, es.lists) eff <- eff[1:3] - names(eff) <- c(bootES_type, paste0(bootES_type, "_CI_low"), paste0(bootES_type, "_CI_high")) + names(eff) <- c( + bootES_type, + paste0(bootES_type, "_CI_low"), + paste0(bootES_type, "_CI_high") + ) contrasts_results <- cbind(contrasts_results, eff) }