I am starting to learn time series and when detrending I always end up with the same doubt...

Generally, I use diff() for, let's say there is an upward trend like inflation... and I use log() to stabilise the variance.

My question is: given time series x, is there a rule when we shall do


Instead of


(code is in R language).

  • 4
    $\begingroup$ I'm pretty sure you'd want log first, as the diff could be negative $\endgroup$
    – MikeP
    Commented Dec 2, 2019 at 13:30
  • $\begingroup$ Note: diff is fine for getting rid of stochastic trends, but not of deterministic ones. In the latter case, it introduces a unit-root moving average component (something you do not want). $\endgroup$ Commented Dec 2, 2019 at 13:53

1 Answer 1


Lets's have at look at both options.


diff(log(x)) calculates relative changes. This also takes care of exponential trends. For example, you would use this to detrend the stock price development of Google. According to the logarithms laws: $$log(a) - log(b) = log(a/b)$$

all.equal(log(3) - log(5), log(3/5))

This means, instead of using the absolute difference for detrending you are using the relative change. As a bonus differences calculated using the natural logarithm can also be interpreted as a precentage change. For more information I recommend:

Cole, T. J., & Altman, D. G. (2017). Statistics Notes: Percentage differences, symmetry, and natural logarithms. BMJ, 358(August), j3683. https://doi.org/10.1136/bmj.j3683


On the other hand log(diff(x)) calculates the absolute differences before the logarithm is applied. If you calculate a trend using this method, the trend would be more outlier resistant (but this also applies to diff(log(x))). This is helpful if there are a small number of big jumps in the time-series. Beware this method would potentially break your analyses when the difference is 0 or negative. (in R: log(0) = -Inf or log(-1) = NaN)

In my opinion diff(log(x)) is the better default choice. While there probably is a use-case for log(diff(x)), it's quite hard to think of one.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.