# The log of a predictor and polynomial regression

I’m working with primate brain data as a predictor in regression models. In the primate brain literature it is custom to log brain data, but it is unclear to me why. It has been argued that since one gram brain tissue means different things to primates of different size, it is the relative brain volume (among species) that is interesting, hence taking the log (does that make sense?).

By taking the log you enhance the impact of differences in small values in a regression, and the opposite for larger values?

In another post it has been argued that logging a predictor can be approximated with a polynomial regression such that

$$𝛽_{0}+𝛽_{1}log(𝑃)≈𝛽_{0}+𝛽_{1}(𝑃−1)−𝛽_{1}(1/2)(𝑃−1)^2+𝛽_{1}(1/3)(𝑃−1)^3−𝛽_{1}(1/4)(𝑃−1)^4\\=𝛽^∗_0+𝛽^∗_1𝑃+𝛽^∗_2𝑃^2+𝛽^∗_3𝑃^3+𝛽^∗_4𝑃^4$$

If this is correct it means that logging a predictor correspond to a certain hypothesis about the relationship between X and Y. And that’s all it means, or am I missing something?

I have been trying to illustrate this and this is the code I came up with. However, I was expecting the regression lines to be more similar. Am I doing it right?

x <- rlnorm(100, 1)
log.x = log(x)
y <- rnorm(100, x, 5)

a = x-1
b = (1/2*(x-1))^2
c = (1/3*(x-1))^3
d = (1/4*(x-1))^4

f1 <- lm(y ~ a + b + c + d)
f2 <- lm(y ~ log.x)

a <- seq(min(a), max(a), length.out=1000)
b <- seq(min(b), max(b), length.out=1000)
c <- seq(min(c), max(c), length.out=1000)
d <- seq(min(d), max(d), length.out=1000)
t <- predict(f1, newdata = data.frame(a = a, b = b, c = c, d = d))

plot(y ~ log.x)
lines(log(a), t, col = "red")

s <- seq(min(log.x), max(log.x), length.out=1000)
t <- predict( f2, newdata = data.frame(log.x = s))
lines(s, t, col = "blue")


Much of your question is addressed extensively on this page. Basically, log transforms bring out fractional rather than arithmetic differences in original variable values, whether the variable is a predictor or and outcome.

So yes, it does make sense to take logs if it is "relative brain volume (among species) that is interesting." And it is true that "logging a predictor corresponds to a certain hypothesis about the relationship between X and Y." In particular, the hypothesis (if X is the predictor and Y is the outcome) is that equal fractional changes in X are associated with equal additive changes in Y.

I haven't checked your code in detail. Note that the original sampling of $$x$$ was from a lognormal distribution itself rather than from a normal distribution, with a meanlog value of 1 (corresponding to $$x=e$$ on a linear scale). The Taylor approximation you use for $$x$$ holds in the vicinity of $$x=1$$, which might be part of your problem.

• Ok, thanks for your answer! I would love to hear your or anyone's thoughts on why differences in brain size preferably would be thought of in terms of logarithms rather than original values. – Andreas Jul 23 at 12:01
• @Andreas I think you put it correctly in your question with respect to comparisons among species: "it is the relative brain volume (among species) that is interesting, hence taking the log." – EdM Jul 23 at 12:23

• Your f1 model estimates separate coefficients for each of a, b, c and d, so this is not a faithful demonstration of the Taylor series expansion.
• You had a small error in your implementation of the Taylor series. You shouldn't apply the polynomial term to the fraction but rather only to the $$P-1$$ term.
• The true data generating model has $$E[Y|X=x] = x$$, but you are fitting models that regress $$Y$$ against $$\log(x)$$ or an approximation thereof, so it's not reasonable to expect that the lines that you plot, which demonstrate your fitted models, will recreate the points that you plot, which illustrate the true model.
• As EdM points out, your log-normal generating distribution can have values that are quite far from $$X=1$$, where the Taylor series expansion is centered at, and so the approximation quickly deteriorates. I had to decrease the variation in the predictor in order to create a sensible approximation.
x <- rnorm(5e2, mean = -0.5, sd = 0.5) # this is log(P)
y <- rnorm(length(x), x, 0.3)

taylor.log = function(x)
{
(x - 1) -
(x - 1)^2 / 2 +
(x - 1)^3 / 3 -
(x - 1)^4 / 4
}

f1 <- lm(y ~ x)
f2 <- lm(y ~ taylor.log(exp(x)))

new_x = seq(quantile(x, p = 0.025),
quantile(x, p = 0.975),
length = 1001);

yhat1 <- predict(f1, newdata = data.frame(x = new_x))
yhat2 <- predict(f2, newdata = data.frame(x = new_x))

plot(x, y, cex = 0.5, pch = 16)
lines(new_x, yhat1, col = "red", lwd = 2)
lines(new_x, yhat2, col = "blue", lwd = 2)

• I should also add that although I think this is an interesting theoretical exercise, there's no reason that I can see for you to try to implement this Taylor series approximation as opposed to just log-transforming the predictor. In your original question, I only pointed out the Taylor series relationship to argue that your are actually dealing with nested models. – psboonstra Jul 11 at 12:35
• Yes, thanks for pointing this out. My original goal was to understand why anyone would ever want to use the logarithm of brain size in a regression instead of original values. The connection between taking the log of a predictor and the Taylor series in this context, as you pointed out, has been very informative. It is still not clear to me why you would want to use the log of brain size rather than original values in a regression, other than that it relates to a particular hypotheses about the relationship between X and Y. – Andreas Jul 23 at 12:12