Research  |   Contributions  |   Matrices  |   Methods  |   Library  |   Photos  |   Links  
Methods > Generalized differencing of time series

Generalized differencing of time series


To difference time series data prior to correlation.

Data required

Technically only a single time series of (e.g. species richness, number of geologic formations etc.) as well as the dates (in millions of years) for each value, although in reality you will wish to pick at least two time series so that they can be correlated after differencing.


Much of palaeontological data can ultimately be expressed or plotted as a time series, i.e. some measure on the y-axis and time on the x-axis. We may further be interested in knowing whether any two time series co-vary, or more specificially whether they are correlated. However, it isn't safe to just correlate time series together as there is a strong danger of false positives (type I errors). This is because time series will often show some form of overall trend (rising/falling) and and so simple correlation will suggest a positive or negative relationship between the two series. This can lead to some spurious conclusions, my favourite example of which is the trends in global tempertaure and number of pirates. Instead workers have employed some form of differencing - i.e. instead of looking at values within time bins, they use the differences between time bins. The simplest form of this is first differencing which uses simply the absolute change from bin-to-bin as a new time series and uses these for correlation instead (use the 'diff' function in R to do this). However, first differencing can go too far the other way as any signal of a real trend in the data can also be removed. A compromise between these two extremes is the generalized differencing approach of McKinney (1990). This approach explicitly incoporates both any trend in the data (using a linear model) and the differences from it. It has already found favour in the literature and is even used by John Alroy (see his ten commandments!).


1. Install and run R (it's free!).

2. Copy and paste the following line into R and hit enter (this will load the necessary function):


3. Enter your time series (here I re-use the divesity and proxy dinosaur data from Barrett et al. 2009):



4. Enter the time value (in Ma) for each bin and store it in a variable named "time" (here again, I use the time data of Barrett et al. 2009):


5. We can now run the function, storing the results in two new variable called "gd.div" and "gd.proxy":



6. These can now be correlated in the normal way, for example:


7. Compare this with the same correlation of the raw data:


References cited

Barrett, P. M., McGowan, A. J. and Page, V. 2009. Dinosaur diversity and the rock record. Proceedings of the Royal Society, London B, 276, 2667-2674.

McKinney, M. L., 1990. Classifying and analyzing evolutionary trends. In Evolutionary Trends, McNamara K. J., ed. Belhaven, London, pp. 28-58.

Last updated 7th November 2008.