Skip to main content
1 of 2
stochazesthai
  • 5.2k
  • 2
  • 22
  • 29

Since logarithm is only defined for positive numbers, you can't take the logarithm of negative values. However, if you are aiming at obtaining a better distribution for your data, you can apply the following transformation.

Suppose you have skewed negative data:

x <- rlnorm(n = 1e2, meanlog = 0, sdlog = 1)
x <- x - 5
plot(density(x))

then you can apply a first transformation to make your data lie in $[-1,1]$:

z <- (x - min(x)) / (max(x) - min(x)) * 2 - 1
min(z); max(z)

and finally apply the inverse hyperbolic tangent:

t <- atanh(z)
plot(density(t))

Now, your data look approximately normally distributed.

stochazesthai
  • 5.2k
  • 2
  • 22
  • 29