Is there a way to back-transform log(x+1)?

Viewed 532

Is there a way to back-transform the mean of a vector of log(x+1) values in R? I tried to use the expm1() function from the base package, but the number is definitely not correct.

df <- c(11, 24, 21, 63, 44, 95, 12, 43, 0, 5, 26, 22, 25, 48, 86, 2)

mean(df)

This gives us 32.9375

Now, if we do ...

df.log1p <- log1p(df)
mean(df.log1p)

This gives us 3.0382116

Now, can I back-transform that single mean value to get the non-log1p mean value of 32.9375? I used expm1(3.0382116) to try that but I got 19.86789.

Is this possible at all?

3 Answers

No, it's not possible. Unfortunately, mean(log1p(x)) == mean(log(1 + x)) is one way operation. Imagine

 A <- c(1 / exp(1) - 1, exp(1) - 1)
 B <- c(0, 0)

As you can see

 mean(A) = 0.5430806
 mean(B) = 0 

But

 mean(log1p(A)) = 0
 mean(log1p(B)) = 0

so having mean(log1p(...)) you can't get mean(...). For a given mean(log1p()) there are infinitely many different corresponding means whenever the collection has more than one item.

This is more a math question. The exponentiated value of mean(log(x)) is not equal to the mean of (x).

mydf <- c(5,10)
mean(mydf)
[1] 7.5
log(mydf)
[1] 1.609438 2.302585
mean(log(mydf))
[1] 1.956012
exp(mean(log(mydf)))
[1] 7.071068

@DmitryBychenko's answer clearly explains why this is not possible if you only have the mean. However, you can get an approximate answer if you have the mean and the variance by using a form of the delta method (this uses a second-order Taylor series approximation) which says that in general (approximately) mean(F(x)) ~ F(mean(x)) + F''(mean(x))*var(x)/2. For this particular problem,

F(x) = exp(x)-1
F''(x) = exp(x)

This is elementary calculus, but you can use D(D(expression(exp(x)-1),"x"),"x") to double-check if you want. Now:

## mean and variance on the transformed scale
m <- mean(log(1+df))
v <- var(log(1+df))
## delta-method
expm1(m) + exp(m)*v/2
## [1] 35.68235

This is different from mean(df) = 32.9375, but it's much closer than the naive approach of just back-transforming the mean (expm1(m)=19.86789).


From Hilborn and Mangel The Ecological Detective (Princeton University Press), via Google books:

derivation of Jensen's inequality approx

Related