Skip to content

Commit

Permalink
prepare CRAN release (#995)
Browse files Browse the repository at this point in the history
* prepare CRAN release

* cran comments

* remove remotes

* fix

* comment code

* comments
  • Loading branch information
strengejacke authored Jul 21, 2024
1 parent ea690d9 commit a77bba7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 26 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.22.0
Date: 2024-06-19 20:40:00 UTC
SHA: 3861512ee3c11ecca44c2edd412c2a5cb65e1f59
Version: 0.22.1
Date: 2024-07-21 11:02:42 UTC
SHA: 109a438b12d4893ae5b2b86aa058923798a6045a
3 changes: 1 addition & 2 deletions 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.7
Version: 0.22.1
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -218,4 +218,3 @@ Config/testthat/edition: 3
Config/testthat/parallel: true
Config/Needs/website: easystats/easystatstemplate
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/bayestestR
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# parameters 0.22.1

## Breaking changes

* Revised calculation of the second generation p-value (SGPV) in `equivalence_test()`,
which should now be more accurate related to the proportion of the interval
that falls inside the ROPE. Formerly, the confidence interval was simply treated
as uniformly distributed when calculating the SGPV, now the interval is assumed
to be normally distributed.

## New supported models

* Support for `svy2lme` models from package *svylme*.
Expand Down
48 changes: 31 additions & 17 deletions R/equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ bayestestR::equivalence_test
#' Second generation p-values (SGPV) were proposed as a statistic that
#' represents _the proportion of data-supported hypotheses that are also null
#' hypotheses_ _(Blume et al. 2018, Lakens and Delacre 2020)_. It represents the
#' proportion of the confidence interval range that is inside the ROPE.
#' proportion of the confidence interval range (assuming a normally distributed,
#' equal-tailed interval) that is inside the ROPE.
#'
#' ## ROPE range
#' Some attention is required for finding suitable values for the ROPE limits
Expand Down Expand Up @@ -592,10 +593,9 @@ equivalence_test.ggeffects <- function(x,
data.frame(
CI_low = final_ci[1],
CI_high = final_ci[2],
SGPV = .sgpv(range_rope, final_ci),
SGPV = .rope_coverage(range_rope, final_ci),
ROPE_low = range_rope[1],
ROPE_high = range_rope[2],
# ROPE_Percentage = .rope_coverage(range_rope, final_ci),
ROPE_Equivalence = decision,
stringsAsFactors = FALSE
)
Expand All @@ -606,48 +606,62 @@ equivalence_test.ggeffects <- function(x,

# helper ---------------------


.sgpv <- function(rope, ci) {
diff_rope <- abs(diff(rope))
# this function simply takes the length of the range and calculates the proportion
# of that range that is inside the rope. However, this assumed a "flat", i.e.
# uniformly distributed interval, which is not accurate for standard confidence
# intervals. thus, we no longer use this function, but switch to ".rope_coverage()".
.sgpv <- function(range_rope, ci) {
diff_rope <- abs(diff(range_rope))
diff_ci <- abs(diff(ci))

# inside?
if (min(ci) >= min(rope) && max(ci) <= max(rope)) {
if (min(ci) >= min(range_rope) && max(ci) <= max(range_rope)) {
coverage <- 1

# outside?
} else if (max(ci) < min(rope) || min(ci) > max(rope)) {
} else if (max(ci) < min(range_rope) || min(ci) > max(range_rope)) {
coverage <- 0

# CI covers completely rope?
} else if (max(ci) > max(rope) && min(ci) < min(rope)) {
} else if (max(ci) > max(range_rope) && min(ci) < min(range_rope)) {
coverage <- diff_rope / diff_ci

# CI inside rope and outside max rope?
} else if (min(ci) >= min(rope) && max(ci) > max(rope)) {
diff_in_rope <- max(rope) - min(ci)
} else if (min(ci) >= min(range_rope) && max(ci) > max(range_rope)) {
diff_in_rope <- max(range_rope) - min(ci)
coverage <- diff_in_rope / diff_ci

# CI inside rope and outside min rope?
} else if (max(ci) <= max(rope) && min(ci) < min(rope)) {
diff_in_rope <- max(ci) - min(rope)
} else if (max(ci) <= max(range_rope) && min(ci) < min(range_rope)) {
diff_in_rope <- max(ci) - min(range_rope)
coverage <- diff_in_rope / diff_ci
}

coverage
}


## FIXME make sure this works for different CI levels
.rope_coverage <- function(rope, ci_range, ci) {
# this function simulates a normal distribution, which approximately has the
# same range / limits as the confidence interval, thus indeed representing a
# normally distributed confidence interval. We then calculate the probability
# mass of this interval that is inside the ROPE.
.rope_coverage <- function(range_rope, ci_range) {
diff_ci <- abs(diff(ci_range))
out <- bayestestR::distribution_normal(
n = 1000,
mean = ci_range[2] - (diff_ci / 2),
sd = diff_ci / 3.28
# we divide the complete range by 2, the one-directional range for the SD
# 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
)

rc <- bayestestR::rope(out, range = rope, ci = ci)
# 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)
rc$ROPE_Percentage
}

Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This release addresses issues with duplicated ORCID in the DESCRIPTION file.
Maintainance release. Furthermore, this release also fixes an issue with the _datawizard_ dependency on Mac OS X with R (old-release).
3 changes: 2 additions & 1 deletion man/equivalence_test.lm.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/equivalence_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
Parameter | 90% CI | SGPV | Equivalence | p
------------------------------------------------------------
(Intercept) | [26.52, 46.86] | < .001 | Rejected | > .999
gear | [-1.34, 2.07] | 0.354 | Undecided | 0.578
gear | [-1.34, 2.07] | 0.648 | Undecided | 0.578
wt | [-4.47, -1.57] | < .001 | Rejected | 0.996
cyl | [-1.94, 0.32] | 0.407 | Undecided | 0.644
cyl | [-1.94, 0.32] | 0.270 | Undecided | 0.644
hp | [-0.05, 0.01] | > .999 | Accepted | < .001

0 comments on commit a77bba7

Please sign in to comment.