Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inverse a log2 transformation

I have data in this form:

        ds           y
1   2015-12-31 51737806366
2   2016-01-01   451800500
3   2016-01-04    48503189
4   2016-01-06      221000
5   2016-01-07   542483038
6   2016-01-08   628189789
7   2016-01-09   556762005
8   2016-01-10   195672447
9   2016-01-11   279202668
10  2016-01-12   540234196
11  2016-01-13  3403591404
12  2016-01-14   610409176

the values on the 'y' column represent income, money units. I made an exploratory plot of this data in its original form and found the plot not too useful, the visual of the data was not appropriate, so in order to improve my visualizations I applied a log2() transformation to the 'y' column... it worked fine:

        ds        y
1   2015-12-31 35.59050
2   2016-01-01 28.75111
3   2016-01-04 25.53158
4   2016-01-06 17.75369
5   2016-01-07 29.01500
6   2016-01-08 29.22663
7   2016-01-09 29.05249
8   2016-01-10 27.54387
9   2016-01-11 28.05674
10  2016-01-12 29.00901
11  2016-01-13 31.66441 

The problem now is that in order to complete my analysis I need to get the 'y' values back to their original form. Is there anyway or implicit R function to reverse the log2() transformation I applied so I can get the original numbers back?

like image 214
Miguel 2488 Avatar asked Jun 10 '18 20:06

Miguel 2488


People also ask

How do I get rid of log2?

To rid an equation of logarithms, raise both sides to the same exponent as the base of the logarithms.

What is the opposite of log transformation?

Exponential transformation (inverse of log transformation)

How do you reverse a log transform in R?

An inverse log transformation in the R programming language can be exp(x) and expm1(x) functions. exp( ) function simply computes the exponential function, whereas the expm1( ) function computes exp(x) – 1 accurately also for |x| << 1.


1 Answers

It's simple.

First, call log2:

data$y = log2(data$y)

After that, if you want to have the original y back just do:

data$y = 2^data$y

The logarithm is the inverse function to exponentiation.

The general rule is:

   logb(x) = y as by = x   

For instance:

   log2(4) = 2 as 22 = 4
   log2(8) = 3 as 23 = 8 
like image 97
Thiago Procaci Avatar answered Sep 21 '22 12:09

Thiago Procaci