# What are analysts looking for when they plot a differenced, logged time series?

So in R, for instance, this would be:

my_ts_logged_diffed = diff(log(some_ts_object))
plot(my_ts_logged_diffed)


This seems to be part of every experienced analyst/forecaster analytical workflow--in particular, a visual examination of the plotted data. What are they looking for--i.e., what useful information does this transformation help reveal?

Similarly, I have a pretty good selection of time series textbooks, tutorials, and the like; nearly all of them mention this analytical step, but none of them say why it's done (i am sure there's a good reason, and one that's apparently too obvious to even mention).

(i do indeed routinely rely on this transformation but only for the limited purpose of testing for a normal distribution (i think the test is called Shapiro-Wilk). The application of the test just involves (assuming i am applying it correctly) comparing a couple of parameters (a 'W' parameter and the p-value) against a baseline--the Test doesn't appear to require plotting the data).

Essentially they're looking for the log of the fold-change from one time point to the next because intuitively, it's easier to think about log-fold changes visually than actual fold-changes.

Log-fold changes make decreases and increases simply a difference in sign, so that a log-2-fold increase is the same distance as a log-2-fold decrease (i.e. |log 2| = |log 0.5|). In addition, many systems exhibit multiplicative effects for independent events, e.g. biological systems and economic systems, where two independent x-fold increases results in an x^2 fold increase, whereas on a log scale, this becomes an additive (and thus easier to see) 2*log(x) increase.

Also, diff(log(x)) is prettier than x[-1]/x[-length(x)].

usually, you plot such a series to check the extend to which it exhibits heteroskedasticity. Depending on the answer, you may have to model the residuals, even if you are only interested in the mean.

This is often used for a price to return transformation based on assuming continuously compounded returns. The Campbell, Lo, and MacKinlay book (Econometrics of Financial Markets, 1997) lays it out quite nicely:

Define r_t as the log of gross returns 1 + R_t:

r_t := log(1 + R_t)


which is the same as the log of the previous prices

log(P_t / P_{t-1})


which is the same as

p_t - p_{t-1}


• Your last line should have been with the log(P)'s, right? And isn't this also a simple consequence of Markov processes and the related exponential distribution? Commented Jul 29, 2010 at 13:47
• In the notation I borrowed: x_t := log(X_t) to the p_t are the logs of the P_t. Commented Jul 29, 2010 at 14:08

Most growth/decay processes will at most change the moving quantity at an exponential rate. The differences of the logs of the quantity relate to the local slope λ, so for a underlying exponential growth or decay process it would be flat in t. Any deviation from flat gives you hints if and where there are switchovers between different purly exponential pieces; also for chaotic behavior you would expect more than linear growth or decay, i.e. a "local λ" curve that is not flat for small t-ranges.

• +1 from me--domain-independent answers are particularly useful here. It seems to me that in interdisciplinary domains, the "why" is often ignored because of the (understandable) emphasis on practical application.
– doug
Commented Jul 29, 2010 at 23:32

I've found that the books I've read tend to mention the "why" behind diff and log. And it's easy to see for yourself. Try this:

data (AirPassengers)
plot (AirPassengers)


Notice the seasonal pattern, but also notice the upward trend. So try

plot (diff (AirPassengers))


See how the upward trend is gone? By looking at the change each month instead of the actual data, you're seeing the patterns more clearly. You've stabilized the time series in some sense.

But also note that the pattern gets larger towards the right side of the graph. That's because the pattern is not additive (add amount Y), but rather multiplicative (add a percentage, or multiply). Logs turn multiplication into addition, so:

plot (diff (log (AirPassengers)))


and you have a stable pattern that you can better perceive what's actually happening over time to the pattern, independently of the trend. A time series with this kind of stability is called "stationary". (Of course, "stationary" has a very technical meaning beyond looking "stable", but let's not go there for now.)

Obviously, the first step to analysis is to understand and preprocess your data and a graph of the raw data is an essential step in the process. Graphing the diff(log(foo)) is just confirming that you understand the data and the results look appropriate, and it gives you a bit more insight into the seasonal patterns of the data.

There are also tests (ADF, etc) and graphs (ACF) that would be used to confirm that differencing of a series is called for, but it can't hurt to look at things as well.

So the transformation reveals the de-trended data (if the transform is indeed called for) for you to look at, and it is the data that you will actually feed into follow-on analysis. (Though some software you use will do the diff and the log under-the-hood for you and you'll only ever see the output which is reversed back to the original data scale)

Time serie analysis is easier on stationary data. (more tools) When a time serie is non stationary, you can try to find another time series, linked to the initial one, and which is stationary. In many cases taking the difference will be enough. (Time series integrated with order 1) Sometimes you'll have to take the logarithm before (for instance for financial time series) The reason is that investment returns are in percentage!

Just don't forget before doing that, there are also some tools for non stationary data. Sometimes taking the diff or the log return may lead to spurious regressions!

Fred