## define age
age <- 1:9
## simple case - transform age to log(age)
(fun <- quote(log(age)))
(transformed.age <- eval(fun))
(inverting.function <- ifun(fun)$fn)
(inverted.transformed.age <- inverting.function(transformed.age))
## is inverted transformed age identical to age?
all.equal(age, inverted.transformed.age)
## more complex case - transform age to log age since conception
fun <- quote(log(age + 0.75))
(transformed.age <- eval(fun))
(inverting.function <- ifun(fun)$fn)
(inverted.transformed.age <- inverting.function(transformed.age))
## identical to original?
all.equal(age, inverted.transformed.age)
## ludicrously complex case involving exp, log10, ^, pi and trigonometry
(fun <- quote((exp(sin(pi * log10(age + 0.75)/2) - 1)^4)))
(transformed.age <- eval(fun))
(inverting.function <- ifun(fun)$fn)
(inverted.transformed.age <- inverting.function(transformed.age))
## identical to original?
all.equal(age, inverted.transformed.age)
## example of plot.sitar back-transforming transformed x and y in sitar models
m1 <- sitar(x=age, y=height, id=id, data=heights, df=6)
m2 <- update(m1, y=height^2)
m3 <- update(m1, x=log(age+0.75))
## default plot settings back-transform x and y to original scales
plot(m1, 'd')
lines(m2, 'd', col=2)
lines(m3, 'd', col=3)
Run the code above in your browser using DataLab