
R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i686-pc-linux-gnu (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 
>  library(mcmc)
> 
>  x <- seq(0, 10, length = 10001)
> 
>  ### sub-exponentially light transformation
> 
>  b <- 0.5
>  fsub <- morph(b = b)
> 
>  y <- unlist(Map(fsub$inverse, x))
> 
>  myfsub <- function(x) ifelse(x > 1 / b, exp(b * x) - exp(1) / 3,
+      (x * b)^3 * exp(1) / 6 + x * b * exp(1) / 2)
>  y2 <- myfsub(x)
>  all.equal(y, y2, tolerance = 1e-14)
[1] TRUE
> 
>  z <- unlist(Map(fsub$transform, y))
>  all.equal(z, x, tolerance = 1e-14)
[1] TRUE
> 
>  ### exponentially light transformation
> 
>  r <- 5 
>  p <- 3
>  fp3 <- morph(r = r)
> 
>  y <- unlist(Map(fp3$inverse, x))
> 
>  myfp3 <- function(x) ifelse(x < r, x, x + (x - r)^p)
>  y2 <- myfp3(x)
>  all.equal(y, y2, tolerance = 1e-14)
[1] TRUE
> 
>  z <- unlist(Map(fp3$transform, y))
>  all.equal(z, x, tolerance = 1e-12)
[1] TRUE
> 
>  ### both together
> 
>  fboth <- morph(b = b, r = r)
> 
>  y <- unlist(Map(fboth$inverse, x))
>  y2 <- myfsub(myfp3(x))
>  all.equal(y, y2, tolerance = 1e-14)
[1] TRUE
> 
>  z <- unlist(Map(fboth$transform, y))
>  all.equal(z, x, tolerance = 1e-12)
[1] TRUE
> 
>  ### exponentially light transformation with p != 3
> 
>  r <- 5 
>  p <- 2.2
>  fpo <- morph(r = r, p = p)
> 
>  y <- unlist(Map(fpo$inverse, x))
> 
>  myfpo <- function(x) ifelse(x < r, x, x + (x - r)^p)
>  y2 <- myfpo(x)
>  all.equal(y, y2, tolerance = 1e-14)
[1] TRUE
> 
>  z <- unlist(Map(fpo$transform, y))
>  all.equal(z, x, tolerance = 1e-14)
[1] TRUE
> 
> 
> proc.time()
   user  system elapsed 
  4.024   0.036   4.038 
