[R] Hyperbola formula

Therneau, Terry M., Ph.D. therneau at mayo.edu
Thu Jan 19 21:21:31 CET 2017


This simple form of a hyperbola is not well known.  I find it useful for change point 
models: since the derivative is continuous it often behaves better in a maximizer.

h1 <- function(x, b, k=3)  .5 * b * (x + sqrt(x^2 + k^2))

Function h1() has asymptotes of y=0 to the left of 0 and y=x to the right of 0.  The 
parameter k controls how tightly the curve bends at zero.

A generalization is
h2 <- function (x, b, k=3) {
     z <- x - b[4]
     b[1] + b[2]*z + .5*b[3]* (z + sqrt(z^2 + k^2))
}
b[1] and b[2] are the intercept and slope of the left portion of the curve, b[4] is the 
inflection point, and b[3] is the change in slope at the inflection point.

The main downside is that k is arbitrary. I simply choose it to "look right", though it 
too could be part of an optimization.

Terry Therneau



More information about the R-help mailing list