# Why does the first eigenvector in PCA resemble the derivative of an underlying trend?

I am using PCA to analyze several spatially related time series, and it appears that the first eigenvector corresponds to the derivative of the mean trend of the series (example illustrated below). I am curious as to why the first eigenvector relates to the derivative of the trend as opposed to the trend itself?

The data are arranged in a matrix where the rows are the time series for each spatial entity and the columns (and in turn dimensions in the PCA) are the years (i.e. in the example below, 10 time series each of 7 years). The data are also mean-centered prior to the PCA.

Stanimirovic et al., 2007 come to the same conclusion, but their explanation is a little beyond my grasp of linear algebra. [Update] - adding data as suggested.

[Update2] - ANSWERED. I found my code was incorrectly using the transpose of the eigenvector matrix when plotting results (excel_walkthrough)(thanks @amoeba). It looks like it's just a coincidence that the transpose-eigenvector/derivative relationship exists for this particular setup. As described mathematically and intuitively in this post, the first eigenvector does indeed relate to the underlying trend and not its derivative.

• When you say "mean-centered" do you mean that column averages are subtracted, row averages, or both? – amoeba says Reinstate Monica Nov 4 '16 at 21:45
• Please explain what you mean by the "derivative of a trend," given that an eigenvector is a number while the graphics suggest you conceive of the derivative as a function. – whuber Nov 4 '16 at 23:31
• @amoeba - the column averages are subtracted (for each year, take out the average across space) – paul j Nov 7 '16 at 16:40
• @whuber - "derivative of a trend" simply referred to the derivative/first-difference of an underlying trend. In the example above, the dashed black line in the first graph is my "underlying trend" (the mean movement). The first-difference of this line is the solid black line in the second graph, which roughly equals the first eigenvector inferred from PCA (both on a normalized scale). – paul j Nov 7 '16 at 16:40
• I am still lost: that solid black line varies between -1.4 and +1.4. In what sense does that "roughly equal" anything? – whuber Nov 7 '16 at 16:51

Let's ignore the mean-centering for a moment. One way to understand the data is to view each time series as being approximately a fixed multiple of an overall "trend," which itself is a time series $x=(x_1, x_2, \ldots, x_p)^\prime$ (with $p=7$ the number of time periods). I will refer to this below as "having a similar trend."

Writing $\phi=(\phi_1, \phi_2, \ldots, \phi_n)^\prime$ for those multiples (with $n=10$ the number of time series), the data matrix is approximately

$$X = \phi x^\prime.$$

The PCA eigenvalues (without mean centering) are the eigenvalues of

$$X^\prime X = (x\phi^\prime)(\phi x^\prime) = x(\phi^\prime \phi)x^\prime = (\phi^\prime \phi) x x^\prime,$$

because $\phi^\prime \phi$ is just a number. By definition, for any eigenvalue $\lambda$ and any corresponding eigenvector $\beta$,

$$\lambda \beta = X^\prime X \beta = (\phi^\prime \phi) x x^\prime \beta = ((\phi^\prime \phi) (x^\prime \beta)) x,\tag{1}$$

where once again the number $x^\prime\beta$ can be commuted with the vector $x$. Let $\lambda$ be the largest eigenvalue, so (unless all time series are identically zero at all times) $\lambda \gt 0$.

Since the right hand side of $(1)$ is a multiple of $x$ and the left hand side is a nonzero multiple of $\beta$, the eigenvector $\beta$ must be a multiple of $x$, too.

In other words, when a set of time series conforms to this ideal (that all are multiples of a common time series), then

1. There is a unique positive eigenvalue in the PCA.

2. There is a unique corresponding eigenspace spanned by the common time series $x$.

Colloquially, (2) says "the first eigenvector is proportional to the trend."

"Mean centering" in PCA means that the columns are centered. Since the columns correspond to the observation times of the time series, this amounts to removing the average time trend by separately setting the average of all $n$ time series to zero at each of the $p$ times. Thus, each time series $\phi_i x$ is replaced by a residual $(\phi_i - \bar\phi) x$, where $\bar\phi$ is the mean of the $\phi_i$. But this is the same situation as before, simply replacing the $\phi$ by their deviations from their mean value.

Conversely, when there is a unique very large eigenvalue in the PCA, we may retain a single principal component and closely approximate the original data matrix $X$. Thus, this analysis contains a mechanism to check its validity:

All time series have similar trends if and only if there is one principal component dominating all the others.

This conclusion applies both to PCA on the raw data and PCA on the (column) mean centered data.

Allow me to illustrate. At the end of this post is R code to generate random data according to the model used here and analyze their first PC. The values of $x$ and $\phi$ are qualitatively likely those shown in the question. The code generates two rows of graphics: a "scree plot" showing the sorted eigenvalues and a plot of the data used. Here is one set of results. The raw data appear at the upper right. The scree plot at the upper left confirms the largest eigenvalue dominates all others. Above the data I have plotted the first eigenvector (first principal component) as a thick black line and the overall trend (the means by time) as a dashed red line. They are practically coincident.

The centered data appear at the lower right. You now the "trend" in the data is a trend in variability rather than level. Although the scree plot is far from nice--the largest eigenvalue no longer predominates--nevertheless the first eigenvector does a good job of tracing out this trend.

#
# Specify a model.
#
x <- c(5, 11, 15, 25, 20, 35, 28)
phi <- exp(seq(log(1/10)/5, log(10)/5, length.out=10))
sigma <- 0.25 # SD of errors
#
# Generate data.
#
set.seed(17)
D <- phi %o% x * exp(rnorm(length(x)*length(phi), sd=0.25))
#
# Prepare to plot results.
#
par(mfrow=c(2,2))
sub <- "Raw data"
l2 <- function(y) sqrt(sum(y*y))
times <- 1:length(x)
col <- hsv(1:nrow(X)/nrow(X), 0.5, 0.7, 0.5)
#
# Plot results for data and centered data.
#
k <- 1 # Use this PC
for (X in list(D, sweep(D, 2, colMeans(D)))) {
#
# Perform the SVD.
#
S <- svd(X)
X.bar <- colMeans(X)
u <- S$v[, k] / l2(S$v[, k]) * l2(X) / sqrt(nrow(X))
u <- u * sign(max(X)) * sign(max(u))
#
# Check the scree plot to verify the largest eigenvalue is much larger
# than all others.
#
plot(S$d, pch=21, cex=1.25, bg="Tan2", main="Eigenvalues", sub=sub) # # Show the data series and overplot the first PC. # plot(range(times)+c(-1,1), range(X), type="n", main="Data Series", xlab="Time", ylab="Value", sub=sub) invisible(sapply(1:nrow(X), function(i) lines(times, X[i,], col=col[i]))) lines(times, u, lwd=2) # # If applicable, plot the mean series. # if (zapsmall(l2(X.bar)) > 1e-6*l2(X)) lines(times, X.bar, lwd=2, col="#a03020", lty=3) # # Prepare for the next step. # sub <- "Centered data" }  • This makes perfect sense as to why "the first eigenvector is proportional to the tend", and is what I was expecting prior to the results of the analysis. However, what Stanimivroc and I are seeing is that the first eigenvector is proportional to the DERIVATIVE (or first-difference) of the trend ... and not the tend itself. – paul j Nov 7 '16 at 18:26 • Yes--and what do you suppose you are looking at after you perform the mean centering? – whuber Nov 7 '16 at 18:31 • Just the underlying data centered around 0 ... here is a 2-Dimensional example. In my case, it's 7-Dimensions (axes) instead of two. The shape/trend of the data doesn't change through mean-centering ... it just gets centered to help ensure the PCA yields meaningful results. – paul j Nov 7 '16 at 20:01 • @paulj Thanks for posting the data. I cannot reproduce your figure. When I do the mean centering and then PCA (SVD), I get PC1 of constant sign (and roughly monotonically increasing, similar to your "trend" and to whuber's$x\$), as I expected. – amoeba says Reinstate Monica Nov 8 '16 at 8:59
• @amoeba - thank you ... you are correct. I found my code was incorrectly using the transpose of the eigenvector matrix when plotting results (excel_walkthrough). It looks like it's just a coincidence that the transpose/first-derivative relationship exists. Thank you again. – paul j Nov 8 '16 at 18:06

Derivative of the data (~ first difference) removes the pointwise dependencies in the data which are due to nonstationarity (cf. ARIMA). What you then recover is approximately the stable stationary signal, which I guess the SVD is recovering.

• I don't see how this answers the question about the resemblance of PC1 and derivative of the mean. – amoeba says Reinstate Monica Nov 6 '16 at 19:26
• Thank you both for your replies. I also agree with @amoeba ... I understand that the derivative (or first-difference as you said) helps make the data stationary, but why would this first-difference essentially equate to the first principal component in this set-up? – paul j Nov 7 '16 at 16:30
• I also don't have such a strong intuition about why this might be. Maybe worth running some simulations to see if this is the case empirically, but I'm not sure if its analytically transparent. – LE Rogerson Nov 7 '16 at 16:39
• Thanks @LERogerson ... yeah, I've run a few simulations, and the outcome seems to hold. The Stanimirovic paper I posted above has the same findings and offers a complex linear algebra explanation, but it's just a little beyond my grasp/not very intuitive. – paul j Nov 7 '16 at 17:12
• @paulj To be honest, I don't quite understand the example given in your post. If I look at your Figure 1 and imagine what happens after mean centering, the black dashed line should be at constant zero and most time series should be either entirely above or entirely below zero. This suggests to me that the PC1 should be of constant sign, but your PC1 shown on Figure 2 changes sign several times. This is strange. Do you maybe want to add your data to your question? – amoeba says Reinstate Monica Nov 7 '16 at 21:04