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

Bug in equivalente_test when using big numbers for lower bounds #992

Merged
merged 9 commits into from
Jul 20, 2024
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: parameters
Title: Processing of Model Parameters
Version: 0.22.0.4
Version: 0.22.0.5
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -204,6 +204,7 @@ Suggests:
tinytable (>= 0.1.0),
TMB,
truncreg,
vdiffr,
VGAM,
withr,
WRS2
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

## Bug fixes

* Fixed issue with `equivalence_test()` when ROPE range was not symmetrically
centered around zero (e.g., `range = c(-99, 0.1)`).

* `model_parameters()` for `anova()` from mixed models now also includes the
denominator degrees of freedom in the output (`df_error`).

Expand Down
53 changes: 24 additions & 29 deletions R/equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@
#' - "classic" - The TOST rule (Lakens 2017)
#'
#' This rule follows the "TOST rule", i.e. a two one-sided test procedure
#' (_Lakens 2017_). Following this rule, practical equivalence of an effect
#' (i.e. H0) is *rejected*, when the coefficient is statistically significant
#' *and* the narrow confidence intervals (i.e. `1-2*alpha`) *include* or
#' *exceed* the ROPE boundaries. Practical equivalence is assumed
#' (i.e. H0 "accepted") when the narrow confidence intervals are completely
#' inside the ROPE, no matter if the effect is statistically significant
#' or not. Else, the decision whether to accept or reject practical
#' equivalence is undecided.
#' (_Lakens 2017_). Following this rule...
#' - practical equivalence is assumed (i.e. H0 *"accepted"*) when the narrow
#' confidence intervals are completely inside the ROPE, no matter if the
#' effect is statistically significant or not;
#' - practical equivalence (i.e. H0) is *rejected*, when the coefficient is
#' statistically significant, both when the narrow confidence intervals
#' (i.e. `1-2*alpha`) include or exclude the the ROPE boundaries, but the
#' narrow confidence intervals are *not fully covered* by the ROPE;
#' - else the decision whether to accept or reject practical equivalence is
#' undecided (i.e. when effects are *not* statistically significant *and*
#' the narrow confidence intervals overlaps the ROPE).
#'
#' - "cet" - Conditional Equivalence Testing (Campbell/Gustafson 2018)
#'
Expand Down Expand Up @@ -538,7 +541,7 @@


#' @keywords internal
.equivalence_test_numeric <- function(ci_wide, ci_narrow, range_rope, rule, ci = 0.95, verbose) {

Check warning on line 544 in R/equivalence_test.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/equivalence_test.R,line=544,col=88,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
final_ci <- NULL

# ==== HDI+ROPE decision rule, by Kruschke ====
Expand All @@ -559,20 +562,14 @@

if (rule == "classic") {
final_ci <- ci_narrow
# significant result?
if (min(ci_narrow) > 0 || max(ci_narrow) < 0) {
# check if CI are entirely inside ROPE. If CI crosses ROPE, reject H0, else accept
if (min(abs(ci_narrow)) < max(abs(range_rope)) && max(abs(ci_narrow)) < max(abs(range_rope))) {
decision <- "Accepted"
} else {
decision <- "Rejected"
}
# non-significant results
} else if (min(abs(ci_narrow)) < max(abs(range_rope)) && max(abs(ci_narrow)) < max(abs(range_rope))) {
# check if CI are entirely inside ROPE. If CI crosses ROPE, reject H0, else accept
if (all(ci_narrow < max(range_rope)) && all(ci_narrow > min(range_rope))) {
# narrow CI is fully inside ROPE - always accept
decision <- "Accepted"
} else {
} else if (min(ci_narrow) < 0 && max(ci_narrow) > 0) {
# non-significant results - undecided
decision <- "Undecided"
} else {
decision <- "Rejected"
}
}

Expand All @@ -585,7 +582,7 @@
if (min(ci_wide) > 0 || max(ci_wide) < 0) {
decision <- "Rejected"
# non-significant results, all narrow CI inside ROPE
} else if (min(abs(ci_narrow)) < max(abs(range_rope)) && max(abs(ci_narrow)) < max(abs(range_rope))) {
} else if (all(ci_narrow < max(range_rope)) && all(ci_narrow > min(range_rope))) {
decision <- "Accepted"
} else {
decision <- "Undecided"
Expand Down Expand Up @@ -741,14 +738,12 @@
orig_x <- x

rule <- attributes(x)$rule
if (!is.null(rule)) {
if (rule == "cet") {
insight::print_color("# Conditional Equivalence Testing\n\n", "blue")
} else if (rule == "classic") {
insight::print_color("# TOST-test for Practical Equivalence\n\n", "blue")
} else {
insight::print_color("# Test for Practical Equivalence\n\n", "blue")
}
if (is.null(rule)) {
insight::print_color("# Test for Practical Equivalence\n\n", "blue")
} else if (rule == "cet") {
insight::print_color("# Conditional Equivalence Testing\n\n", "blue")
} else if (rule == "classic") {
insight::print_color("# TOST-test for Practical Equivalence\n\n", "blue")
} else {
insight::print_color("# Test for Practical Equivalence\n\n", "blue")
}
Expand Down
21 changes: 13 additions & 8 deletions man/equivalence_test.lm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions tests/testthat/_snaps/equivalence_test/equivalence-test-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions tests/testthat/_snaps/equivalence_test/equivalence-test-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading