How do I approach finding the inverse of this function? I'm reading a paper by Steve Horvath (2013) for the epigenetic clock he developed. He used an age calibration function before carrying out an elastic net regression analysis. The function F for transforming age is as follows (adult age = 20):

F(age)=log(age+1)-log(adult.age+1) if age<= adult.age

F(age)=(age-adult.age)/(adult.age+1) if age> adult.age

Using R, I have written the function as follows:
ageC <- function(age) {
  if (age <= 20) {
    ageC = log(age+1)-log(21)}
  if (age > 20) {
    ageC = (age-20)/(21)
  }
  return(ageC)
}

My question is how do I find the inverse of the function F? The model predicts DNA methylation age (DNAmAge) using the following:

DNAmAge = inverse.F(b0 + b1CpG1 + . . . + b353CpG353)

What is the "inverse.F" portion?

In order to find a quick solution about the inverse of the function $f$ just define an interpolation functions $g$ such that $g(f(x))=x$.
Here is a quick example doing that in R:
ageC <- function(age) {
  if (age <= 20) {
    ageC = log(age+1)-log(21)}
  if (age > 20) {
    ageC = (age-20)/(21)
  }
  return(ageC)
}

mydf = data.frame(
  ages = seq(0,100, by=0.05)
)

mydf$agesC = sapply(mydf$ages, ageC)

inv_ages = approxfun(x=mydf$agesC, y=mydf$ages) # the function g

# Quick check it works
q_age = 42.1
all.equal(q_age, inv_ages(ageC(q_age))) # Yep, TRUE

