Skip to content

Commit

Permalink
increase precision
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jul 21, 2024
1 parent a77bba7 commit 61d9637
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 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.1
Version: 0.22.1.1
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
8 changes: 5 additions & 3 deletions R/equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,13 @@ equivalence_test.ggeffects <- function(x,
# then, the range from mean value to lower/upper limit, for a normal
# distribution is approximately 3.3 SD (3 SD cover 99.7% of the probability
# mass of the normal distribution). Thus, assuming that half of the ci_range
# refers to ~ 3.3 SD, we "normalize" the value (i.e. divide by 3.29) to get
# the value for one SD, which we need to build the normal distribution.
sd = (diff_ci / 2) / 3.29
# refers to ~ 3.3 SD, we "normalize" the value (i.e. divide by 3.290525) to
# get the value for one SD, which we need to build the normal distribution.
sd = (diff_ci / 2) / 3.290525
)

# compare: ci_range and range(out)

# The SGPV refers to the proportion of the confidence interval inside the
# full ROPE - thus, we set ci = 1 here
rc <- bayestestR::rope(out, range = range_rope, ci = 1)
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-equivalence_test.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("bayestestR")

test_that("equivalence_test", {
data(mtcars)
m <- lm(mpg ~ gear + wt + cyl + hp, data = mtcars)
Expand Down Expand Up @@ -28,6 +30,23 @@ test_that("equivalence_test, unequal rope-range", {
rez$ROPE_Equivalence,
c("Rejected", "Accepted", "Undecided", "Rejected", "Accepted", "Undecided")
)

# validate thet range of CI equals approximated normal distribution
diff_ci <- abs(diff(c(rez$CI_low[3], rez$CI_high[3])))
set.seed(123)
out <- bayestestR::distribution_normal(
n = 1000,
mean = rez$CI_high[3] - (diff_ci / 2),
sd = (diff_ci / 2) / 3.290525
)
expect_equal(range(out)[1], rez$CI_low[3], tolerance = 1e-4)
expect_equal(range(out)[2], rez$CI_high[3], tolerance = 1e-4)
expect_equal(
rez$SGPV[3],
bayestestR::rope(out, range = c(-Inf, 0.5), ci = 1)$ROPE_Percentage,
tolerance = 1e-4
)

rez <- equivalence_test(m, range = c(-0.5, 0.5))
expect_identical(
rez$ROPE_Equivalence,
Expand Down

0 comments on commit 61d9637

Please sign in to comment.