Dealing zeros in log transformation

log

#1

How can we deal with the 0s in data while transforming them to log scale. Also We don’t want to discard the 0s.


#2

Hello Santosh,

You can add 1 to the variable you want to log transform.

So the transformation will be log(1+x)


#4

Hi Jagdish,

Thanks for a quick response.

There is a problem with such an approach to my data. I am dealing with some biological data where 0 means it is not present there, and if we add 1 to these the meaning of data changes. One more problem is there are certain values of -1 present in our data, which became 0 after adding 1. So, can you please suggest me how to deal with these kind of situations.

Thanks,
Santosh


#5

Regarding the “0” you can encode it with some value which is outside the range of your variable (9999) since this represents missing data or try imputation. (median/mean).

To counter (-1) or the negative values I would find the min, and then try to convert to log.

log(1+abs(min(x)) + x)

This should take care of the negatives.


#6

Thank You Jagdish,

I will try that