Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse inverse hyperbolic sine transformation in R?

Tags:

r

statistics

Transformation using inverse hyperbolic sine transformation could be done in R using this simple function:

ihs <- function(x) {
    y <- log(x + sqrt(x ^ 2 + 1))
    return(y)
}

However, I could not find the way to reverse this transformation. So my question is: How to reverse inverse hyperbolic sine transformation in R?

like image 411
Jot eN Avatar asked Nov 09 '15 15:11

Jot eN


2 Answers

The inverse of inverse hyperbolic sine is hyperbolic sine so you can use:

sinh(x)

And if you want to inverse the function on your own that should help you:

hs <- function(x) {
    y <- 0.5*exp(-x)*(exp(2*x)-1)
    return(y)
}

enter image description here

like image 188
Maju116 Avatar answered Nov 12 '22 10:11

Maju116


@Maju116 has given the right answer, but he has not shown his work. :-)

Here is how to derive the inverse of the inverse hyperbolic sine function together with a full R solution to generate the function and plots.

y = \log(x + \sqrt{x^2 + 1})   
\exp(y) - x = \sqrt{x^2 + 1}  
Squaring both sides   
\exp(2y) + x^2 - 2\exp(y)x = x^2 + 1  
\exp(2y) - 1 = 2\exp(y)x  
(1/2)*(\exp(2y) - 1)/exp(y) = x

Plot of the functions: enter image description here

library(ggplot2)

# inverse hyperbolic since function
ihs <- function(x) {
  y <- log(x + sqrt(x^2 + 1))
  return(y)
}

# hyperbolic sine function
hs = function(x) {
  0.5*exp(-x)*(exp(2*x) - 1)
}

# data
dfX = data_frame(x = seq(-2, 2, 0.01), 
                 ihs = ihs(x), 
                 hs1 = sinh(x), 
                 hs2 = hs(x))

# plot
ggplot(data = dfX, aes(x = x)) +
  stat_function(aes(color = "Inverse Hyperbolic Sine"), fun = ihs, ) +
  stat_function(aes(color = "Hyperbolic Sine (Manual)"), fun = hs) +
  stat_function(aes(color = "Hyperbolic Sine (Base)"), fun = sinh) +
  theme_bw() + 
  scale_colour_manual("Function", values = c("red", "darkblue", "darkgreen"))][1]][1]
like image 30
tchakravarty Avatar answered Nov 12 '22 08:11

tchakravarty