Skip to content

Commit

Permalink
format_bf() should also add stars for lower BFs
Browse files Browse the repository at this point in the history
Fixes #954
  • Loading branch information
strengejacke committed Nov 6, 2024
1 parent eda1a6d commit 70d038c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 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: insight
Title: Easy Access to Model Information for Various Model Objects
Version: 0.99.0.10
Version: 0.99.0.11
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
* `format_value()` gains a `decimal_point` argument, to change the decimal point
in output conversion.

* `format_bf()` with `stars = TRUE` used the `°` symbol for inferiority
(evidence *against* the comparison).

## Bug fix

* `clean_parameters()` now uses the correct labels for the random effects
Expand Down
10 changes: 9 additions & 1 deletion R/format_bf.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#' @return A formatted string.
#'
#' @examples
#' format_bf(bfs <- c(0.000045, 0.033, NA, 1557, 3.54))
#' bfs <- c(0.000045, 0.033, NA, 1557, 3.54)
#' format_bf(bfs)
#' format_bf(bfs, exact = TRUE, name = NULL)
#' format_bf(bfs, stars = TRUE)
#' format_bf(bfs, protect_ratio = TRUE)
Expand Down Expand Up @@ -82,6 +83,13 @@ format_bf <- function(bf,
)
)

## Add stars
bf_text <- ifelse(bf_orig < (1 / 30), paste0(bf_text, "\u00B0\u00B0\u00B0"),
ifelse(bf_orig < 0.1, paste0(bf_text, "\u00B0\u00B0"), # nolint
ifelse(bf_orig < (1 / 3), paste0(bf_text, "\u00B0"), bf_text) # nolint
)
)

out <- .add_prefix_and_remove_stars(p_text = bf_text, stars, stars_only, name)
if (is.na(na_reference)) out[bad_bf] <- ""
out
Expand Down
3 changes: 2 additions & 1 deletion R/format_p.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ format_p <- function(p,
}

if (stars_only) {
p_text <- gsub("[^\\*]", "", p_text)
p_text <- gsub("[^(\\*|°)]", "", p_text)
} else if (!stars) {
p_text <- gsub("*", "", p_text, fixed = TRUE)
p_text <- gsub("\u00B0", "", p_text, fixed = TRUE)
}

# replace missing with related string
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-format.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ test_that("format_ci, character", {
test_that("format others", {
expect_type(insight::format_pd(0.02), "character")
expect_identical(nchar(format_bf(4)), 9L)
expect_identical(
format_bf(c(0.000045, 0.033, NA, 1557, 3.54)),
c("BF < 0.001", "BF = 0.033", "", "BF > 1000", "BF = 3.54")
)
expect_identical(
format_bf(c(0.000045, 0.033, NA, 1557, 3.54), name = NULL),
c("< 0.001", "0.033", "", "> 1000", "3.54")
)
expect_identical(
format_bf(c(0.000045, 0.033, NA, 1557, 3.54), stars = TRUE),
c("BF < 0.001°°°", "BF = 0.233°", "", "BF > 1000***", "BF = 3.54*")
)
expect_identical(
format_bf(c(0.000045, 0.033, NA, 1557, 3.54), stars = TRUE, stars_only = TRUE),
c("°°°", "°", "", "***", "*")
)
expect_identical(
format_bf(c(0.000045, 0.033, NA, 1557, 3.54), protect_ratio = TRUE),
c("BF < 1/1000", "BF = 1/30.30", "", "BF > 1000", "BF = 3.54")
)
expect_identical(
format_bf(c(0.000045, 0.033, NA, 1557, 3.54), protect_ratio = TRUE, exact = TRUE),
c("BF = 1/2.22e+04", "BF = 1/30.30", "", "BF = 1.56e+03", "BF = 3.54")
)
expect_type(format_rope(0.02), "character")
})

Expand Down

0 comments on commit 70d038c

Please sign in to comment.