0

And also, why you would need to difference twice to remove quadratic trends [in a sequence of numbers].

(I was asked to add this as a question and answer, to give the answer more exposure from Why does differencing once remove not only linear but also nonlinear trends?)

MrDrFenner
  • 231
  • 1
  • 8

1 Answers1

0

The principle is based on the Method of Differences.

If you'll forgive some Python:

>>> import numpy as np
x>>> xs = np.arange(5)
>>> xs
array([0, 1, 2, 3, 4])
>>> ys_constant = 0.0 * xs + 1
>>> ys_constant
array([1., 1., 1., 1., 1.])
>>> np.diff(ys_constant)
array([0., 0., 0., 0.])
>>> ys_linear = 2.0 * xs + 1
>>> ys_linear
array([1., 3., 5., 7., 9.])
>>> np.diff(ys_linear)
array([2., 2., 2., 2.])
>>> ys_quad = xs**2 + 2.0*xs + 1
>>> ys_quad
array([ 1.,  4.,  9., 16., 25.])
>>> np.diff(ys_quad)
array([3., 5., 7., 9.])
# need the second difference to get constant behavior
>>> np.diff(np.diff(ys_quad))
array([2., 2., 2.])
>>> np.diff(ys_quad, n=2)
array([2., 2., 2.])

Now, that shows that the method works. But how/why? Consider the differences as simple approximations to a derivative $\frac{f(x)-f(x+\Delta)}{\Delta}$ where the $\Delta$ values is fixed at $1$ (so it disappears from the denominator and is use a "fixed increment" to the next input in the sequence, for example $x=2 \rightarrow x=3$).

Then, repeated differencing is like taking higher order derivatives. The first order derivative of a line (aka the slope of a line) is always constant. So, we only need a first order difference to remove a linear trend. The second order derivative of a quadratic likewise gets us to a constant (in $y=ax^2 + bx + c$ we throw away the $b,c$ and are left with $a$).

MrDrFenner
  • 231
  • 1
  • 8