diff --git a/R/trans-numeric.R b/R/trans-numeric.R index cddeef2a..301e15b0 100644 --- a/R/trans-numeric.R +++ b/R/trans-numeric.R @@ -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 ) } diff --git a/tests/testthat/test-trans-numeric.R b/tests/testthat/test-trans-numeric.R index 749b8743..a7f5cbf8 100644 --- a/tests/testthat/test-trans-numeric.R +++ b/tests/testthat/test-trans-numeric.R @@ -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))