Skip to main content
2 of 2
Edited the text.
Thomas Bilach
  • 6.5k
  • 2
  • 13
  • 33

Log-transforming a value less than 1 results in a negative number. Here is a quick demonstration in R:

# Generating a sequence of values between 0 and 1 (inclusive), incrementing by 0.1

x <- seq(0, 1, by = 0.1)
x
[1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

# Taking the log() of each value in this sequence

round(log(x), 2)
[1]  -Inf -2.30 -1.61 -1.20 -0.92 -0.69 -0.51 -0.36 -0.22 -0.11  0.00

It is entirely possible for the sign of a Pearson's correlation to flip as a consequence of logging observations between 0 and 1. In such contexts, it's possible for $\rho(X,Y)$ to flip sign if we $\log X$ or $\log Y$, or both. See below for a quick-and-dirty simulation. In each iteration, I assessed the correlation between 10 pairs of values. The correlation was preserved in 7 out of the 10 trials. Note, upon each draw of 10 observations, a subset fall between 0 and 1, which reverse in sign after the log transformation; this has the potential to influence the relationship between variables.

set.seed(13)

sims <- 10
levels <- vector(mode = "numeric", length = 10)  # storage for the numeric values in levels
logged <- vector(mode = "numeric", length = 10)  # storage for the "logged" numeric values

for (i in 1:sims) {
  x <- exp(rnorm(10)); y <- exp(rnorm(10))       # drawing 'positive' random deviates             

  levels[i] <- cor(x, y)                         # correlation in levels
  logged[i] <- cor(log(x), log(y))               # correlation of the logged values
}

flipped <- (levels > 0 & logged < 0) | (levels < 0 & logged > 0)
preserved <- !flipped

# Were the correlations between pairs preserved?

cbind(levels, logged, flipped, preserved)

           levels      logged flipped preserved
 [1,]  0.10728307 -0.01369591       1         0
 [2,]  0.93652958  0.62956976       0         1
 [3,]  0.01300703  0.07601658       0         1
 [4,] -0.06794333  0.37656387       1         0
 [5,]  0.17978986  0.27654877       0         1
 [6,]  0.19476326  0.54571601       0         1
 [7,] -0.09462134 -0.04706490       0         1
 [8,] -0.25225396 -0.40215868       0         1
 [9,] -0.20694668 -0.05695933       0         1
[10,] -0.04839709  0.08447948       1         0

Another example is when a transformation dampens an outlier that was exerting major leverage. Review the top answer here for a very simple and clear demonstration of this. If you're working with per capita rates (e.g., limited number of incidents per unit population) or proportions, then a log transformation can influence or even reverse the sign of a coefficient.

Thomas Bilach
  • 6.5k
  • 2
  • 13
  • 33