I would like to know how to transform negative values to
Log(), since I have heteroskedastic data. I read that it works with the formula
Log(x+1)but this doesn’t work with my database and I continue getting NaNs as result. E.g. I get this Warning message (I didn’t put my complete database because I think with one of my negative values is enough to show an example):
> log(-1.27+1)  NaN Warning message: In log(-1.27 + 1) : NaNs produced >
Thanks in advance
Here is an histogram of my data. I’m working with palaeontological time series of chemical measurements, E.g the difference between variables like Ca and Zn is too big, then I need some type of data standardization, that is why I’m testing the
This is my raw data
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 z <- z[-min(z)] z <- z[-max(z)] min(z); max(z)
and finally apply the inverse hyperbolic tangent:
t <- atanh(z) plot(density(t))
Now, your data look approximately normally distributed. This is also called Fisher transformation.