Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

math

r

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?

like image 577
riverotter Avatar asked Jan 25 '23 10:01

riverotter


2 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.

like image 143
Dmitry Bychenko Avatar answered Feb 01 '23 10:02

Dmitry Bychenko


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
like image 38
akaDrHouse Avatar answered Feb 01 '23 11:02

akaDrHouse