Skip to content

Commit

Permalink
add inverse hyperbolic sin transform (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearsonca authored Nov 3, 2023
1 parent e0aa51b commit b885cf1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export(abs_area)
export(alpha)
export(area_pal)
export(as.trans)
export(asinh_trans)
export(asn_trans)
export(atanh_trans)
export(boxcox_trans)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
`breaks_timespan()` adds functionality for finding pleasant breakpoints across
the various bases in time units, while `timespan_trans()` wraps it all
together and provides an alternative to `hms_trans()` (#212)
* Add an inverse (area) hyperbolic sine transformation `asinh_trans()`, which
provides a logarithm-like transformation of a space, but which accommodates
negative values (#297)

# scales 1.2.1

Expand Down
15 changes: 14 additions & 1 deletion R/trans-numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ asn_trans <- function() {
#' @examples
#' plot(atanh_trans(), xlim = c(-1, 1))
atanh_trans <- function() {
trans_new("atanh", "atanh", "tanh")
trans_new("atanh", "atanh", "tanh", domain = c(-1, 1))
}

#' Inverse Hyperbolic Sine transformation
#'
#' @export
#' @examples
#' plot(asinh_trans(), xlim = c(-1e2, 1e2))
asinh_trans <- function() {
trans_new(
"asinh",
transform = asinh,
inverse = sinh
)
}

#' Box-Cox & modulus transformations
Expand Down
14 changes: 14 additions & 0 deletions man/asinh_trans.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-trans-numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,8 @@ test_that("Yeo-Johnson transform works", {
expect_equal(yj_trans(lambdas[2])$transform(x[[2]]), expected_data[[2]])
expect_equal(yj_trans(lambdas[3])$transform(x[[3]]), expected_data[[3]])
})

test_that("probability transforms have domain (0,1)", {
expect_equal(logit_trans()$domain, c(0, 1))
expect_equal(probit_trans()$domain, c(0, 1))
})

0 comments on commit b885cf1

Please sign in to comment.