Skip to content

Commit

Permalink
derivatives for asinh_trans
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Nov 3, 2023
1 parent d343060 commit 5826400
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/trans-numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ asinh_trans <- function() {
trans_new(
"asinh",
transform = asinh,
inverse = sinh
inverse = sinh,
d_transform = function(x) 1 / sqrt(x^2 + 1),
d_inverse = cosh
)
}

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-trans-numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ test_that("atanh_trans derivatives work", {
expect_equal(trans$d_inverse(x), 1 / trans$d_transform(trans$inverse(x)))
})

test_that("asinh_trans derivatives work", {
trans <- asinh_trans()
expect_equal(trans$d_transform(c(-1, 0, 1)), c(sqrt(2) / 2, 1, sqrt(2) / 2))
expect_equal(trans$d_inverse(c(-log(2), 0, log(2))), c(1.25, 1, 1.25))
x <- seq(-0.9, 0.9, length.out = 10)
expect_equal(trans$d_transform(x), 1 / trans$d_inverse(trans$transform(x)))
expect_equal(trans$d_inverse(x), 1 / trans$d_transform(trans$inverse(x)))
})

test_that("boxcox_trans derivatives work", {
trans <- boxcox_trans(p = 0, offset = 1)
expect_equal(trans$d_transform(c(0, 1, 2)), c(1, 1/2, 1/3))
Expand Down

0 comments on commit 5826400

Please sign in to comment.