Skip to content
Related Articles

Related Articles

Improve Article

How to find inverse log transformation in R ?

  • Last Updated : 21 Apr, 2021

A logarithm of a given number n is the exponent to which another number which is been fixed, the base b, must be raised, to produce that number n. In layman terms the logarithm counts the number of occurrences of the same factor in repeated multiplication.  A logarithmic function is represented as:

f(x) = log b (x)

When the base b of the logarithm equals 10, we generally don’t mention it, i.e. f(x) = log (x). The inverse of a log or exponential function is given by :

In general case,  

y = log b (x)  ⇐⇒  b y = x



For natural log: 

y = ln (x)    ⇐⇒   e y = x

let us look at some examples for better understanding:

Example 1: if y = ln (544) = 6.298949

                       antilog ( y ) = e y = 544

Example 2: if y = log (544) = 2.735598

                       antilog ( y ) = 10 y = 544

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. Here x must be a numeric or complex vector and base must be positive.



Method 1: Using exp()

Syntax:

 exp ( x )

Where, x is a numeric value.

Example:

R




exp (100) 
exp (9867528) 
exp (0)
exp (1.7865)

Output:

[1] 2.688117e+43      # exp (100)

[1] Inf               # exp (9867528)

[1] 1                 # exp (0)

[1] 5.968526          # exp (1.7865)

For bigger numbers, it generally returns “Inf” which means infinity.



Method 2: Using expm1()

Syntax:

 expm1 ( x ) = exp (x) – 1

Where, x is a numeric value.

Example:

R




expm1 (100)
expm1 (9867528)
expm1 (0)
expm1 (1.7865)

Output:

[1] 2.688117e+43      # expm1 (100)

[1] Inf               # expm1 (9867528)

[1] 0                 # expm1 (0)

[1] 4.968526          # expm1 (1.7865)

For large numeric values exp( ) and expm1( ) functions return the same values.

Example :

R




# calculate logarithmic of a number
y = log(544, base = exp(1))
print(y)
  
# calculate its inverse log
# using exp( ) function. 
antilog_y1 = exp (y)
print(antilog_y1)
  
# calculate its inverse log
# using expm1( ) function. 
antilog_y2 = expm1 (y)
print(antilog_y2)

Output:

[1] 6.298949               # print(y)

[1] 544                    # print(antilog_y1)

[1] 543                    # print(antilog_y2)




My Personal Notes arrow_drop_up
Recommended Articles
Page :