Skip to main content

Principal Components Regression: What Does the Yield Curve Say About Next Year’s Economy?

Principal components regression (PCR) in R, by hand and with pls::pcr(), on eight US interest rates that correlate above .94 and the growth of the US economy a year later (FRED, 1976-2019): why least squares fails with collinear predictors, level, slope and curvature, scores and loadings, choosing the number of components by cross-validation in blocks, back to coefficients, the trap of the component with the largest variance, ridge for comparison, Newey-West errors and APA reporting.

The question: eight predictors that say the same thing

The United States borrows money for three months, for a year, for five, for ten. Each of these loans has its own interest rate, and together they form the yield curve. People who watch the economy look at its shape. When the long rates are much higher than the short ones, the economy usually grows. When the short rates climb above the long ones, the curve is inverted, and a recession often follows (Estrella & Hardouvelis, 1991).

So: can the eight interest rates of today predict how much the economy will grow in the next year?

A regression with eight predictors is easy to run and hopeless to read. The eight rates rise and fall together; two neighbors correlate above .99. Least squares cannot tell them apart, and its coefficients explode.

Principal components regression (PCR) goes around the problem in two steps. First it replaces the eight rates by a few new variables that summarize them and do not correlate with each other. Then it uses these in an ordinary regression. This example is a kind one, because the new variables have a meaning that anybody can see. It also shows the weak point of the method, in its purest form.

Code
library(ggplot2)
library(pls)        # pcr(): principal components regression, with cross-validation
library(sandwich)   # NeweyWest(): standard errors for overlapping time series
library(lmtest)     # coeftest(), coefci()
library(glmnet)     # ridge regression, for comparison

# number formats for the text
f1   <- function(x) formatC(x, format = "f", digits = 1, big.mark = ",")
f2   <- function(x) formatC(x, format = "f", digits = 2, big.mark = ",")
f3   <- function(x) formatC(x, format = "f", digits = 3, big.mark = ",")
# no leading zero
nz <- function(x, d = 2) sub("^(-?)0", "\\1", formatC(x, format = "f", digits = d))
pval <- function(p) if (p < .001) "< .001" else paste("=", nz(p, 3))
pct  <- function(x, d = 1) paste0(formatC(100 * x, format = "f", digits = d), "%")

1. The data

FRED, the database of the Federal Reserve Bank of St. Louis, gives every series as a CSV file, free and with no login. We take the monthly interest rates for eight maturities, average them over each quarter, and the real gross domestic product (GDP) of the quarter (Board of Governors of the Federal Reserve System, n.d.; U.S. Bureau of Economic Analysis, n.d.).

Code
fred <- function(id) {
  d <- read.csv(paste0("https://fred.stlouisfed.org/graph/fredgraph.csv?id=", id), na.strings = ".")
  names(d) <- c("date", "value")
  quarter <- paste0(substr(d$date, 1, 4), "Q", (as.integer(substr(d$date, 6, 7)) + 2) %/% 3)
  tapply(d$value, quarter, mean) # the mean of the months of the quarter
}
maturities <- c(`3 months` = "TB3MS", `6 months` = "TB6MS", `1 year` = "GS1", `2 years` = "GS2",
                `3 years` = "GS3", `5 years` = "GS5", `7 years` = "GS7", `10 years` = "GS10")
rates <- lapply(maturities, fred)
gdp   <- fred("GDPC1")

quarters <- names(rates[["2 years"]]) # the shortest series: it starts in 1976
quarters <- quarters[quarters >= "1976Q3" & quarters <= "2018Q4"]
X <- sapply(rates, function(r) r[quarters])                            # 8 columns: percent per year
at <- match(quarters, names(gdp))
y <- as.numeric(100 * (gdp[at + 4] / gdp[at] - 1)) # growth in the NEXT four quarters, in %
n  <- nrow(X)
c(quarters = n, rates = ncol(X))
quarters    rates 
     170        8 
Code
summary(y)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 -3.979   1.798   2.882   2.781   4.111   8.578 

A row is a quarter. The predictors are the rates of that quarter; the outcome is the growth of real GDP over the following four quarters, so it is a forecast. The sample ends with the rates of 2018Q4, whose outcome is the growth until the end of 2019: the pandemic of 2020 was not in any yield curve. There are 170 quarters. Mean growth was 2.8% a year, with a standard deviation of 2.0.


2. Look at the data

Code
time  <- as.numeric(substr(quarters, 1, 4)) + (as.numeric(substr(quarters, 6, 6)) - 1) / 4
long <- data.frame(
  time = rep(time, 8),
  rate = as.vector(X),
  maturity = factor(rep(colnames(X), each = n), levels = colnames(X))
)
pa <- ggplot(long, aes(time, rate, colour = maturity)) +
  geom_line(linewidth = 0.5) +
  scale_colour_viridis_d(option = "D", end = 0.9, name = NULL) +
  labs(title = "Eight interest rates", x = NULL, y = "% per year") + theme_bw()
pb <- ggplot(data.frame(time, y), aes(time, y)) +
  geom_hline(yintercept = 0, colour = "grey60") +
  geom_line(colour = "#eb6834", linewidth = 0.7) +
  labs(
    title = "Growth of the economy in the following year",
    x = "quarter in which the rates were observed",
    y = "%"
  ) +
  theme_bw()
patchwork::wrap_plots(pa, pb, ncol = 1)

Plot: 2. Look at the data

Code
R <- cor(X)
range(R[lower.tri(R)])
[1] 0.9444643 0.9988344

The eight lines move as one. The correlations are between 0.94 and 0.999. What distinguishes the quarters, apart from the level, is how far the lines are spread.


3. Why least squares fails

Code
ols <- lm(y ~ X)
ols_table <- coef(summary(ols))[-1, ]
rownames(ols_table) <- colnames(X)
round(ols_table, 2)
         Estimate Std. Error t value Pr(>|t|)
3 months    -0.24       1.22   -0.20     0.84
6 months     0.06       2.39    0.02     0.98
1 year      -4.57       1.93   -2.37     0.02
2 years      8.23       3.55    2.32     0.02
3 years     -1.86       3.98   -0.47     0.64
5 years     -5.56       3.37   -1.65     0.10
7 years      5.39       3.28    1.64     0.10
10 years    -1.48       1.74   -0.85     0.40
Code
vif <- diag(solve(R))                      # variance inflation factors
round(vif)
3 months 6 months   1 year  2 years  3 years  5 years  7 years 10 years 
    1084     4158     3106    10243    12176     7932     6946     1791 
Code
c(R2 = summary(ols)$r.squared)
       R2 
0.2990087 

Read the column of estimates. The 2-year rate: 8.2. The 5-year rate: -5.6. So the economy should grow by 8.2 points more when the 2-year rate is one point higher and everything else stays the same. But everything else never stays the same. When the 2-year rate rises, the 1-year and the 3-year rates rise with it.

The variance inflation factor says how many times the variance of a coefficient is larger than it would be with uncorrelated predictors. A usual warning level is 10. Here it goes up to 12,176. The fit is not the problem: the predictions of least squares are still meaningful as long as the rates move together. But the coefficients are noise, and they change wildly if a few quarters are left out:

Code
half <- time < 1998
round(
  cbind(
    first_half = coef(lm(y ~ X, subset = half))[-1],
    second_half = coef(lm(y ~ X, subset = !half))[-1]
  ),
  1
)
          first_half second_half
X3 months       -1.0         6.3
X6 months        1.3       -14.3
X1 year         -6.7         9.7
X2 years        12.5        -5.3
X3 years        -3.4         8.2
X5 years        -2.9       -12.5
X7 years        -5.5        11.4
X10 years        5.5        -3.8

4. The method step by step, with formulas

Step 1: principal components

Center the columns of \(X\) (subtract the means). We look for a weighted sum of the eight rates, \(t_1 = X v_1\), with weights of length 1, that varies as much as possible. That is the first component. The second, \(t_2 = X v_2\), varies as much as possible among all the weighted sums that are uncorrelated with the first. And so on, until there are eight. The weights \(v_j\) are the loadings, the values \(t_{ij}\) the scores. They come from the eigenvectors of the covariance matrix of \(X\):

\[S = \frac{X^\top X}{n-1}, \qquad S v_j = \lambda_j v_j, \qquad \text{Var}(t_j) = \lambda_j\]

Code
Xc      <- scale(X, scale = FALSE)                 # centered, not divided by the SD
eig     <- eigen(cov(X))
V       <- eig$vectors
# +1 or -1 for each component
turn <- sign(c(V[1, 1], V[8, 2] - V[1, 2], V[1, 3] + V[8, 3], rep(1, 5)))
V       <- V %*% diag(turn)
dimnames(V) <- list(colnames(X), paste0("PC", 1:8))
Tscores <- Xc %*% V
share   <- eig$values / sum(eig$values)
round(100 * share, 3)
[1] 98.551  1.344  0.081  0.018  0.003  0.002  0.001  0.001
Code
max(abs(abs(prcomp(X)$x) - abs(Tscores)))          # the same as prcomp()
[1] 1.131742e-12

The sign of a component is arbitrary (if \(v\) is a solution, so is \(-v\)), and we turned the first three so that they are easy to read. All the rates are in the same unit, percent per year, so we did not standardize them. With predictors in different units one must (scale. = TRUE), or the component follows the variable with the largest numbers.

Code
years <- c(0.25, 0.5, 1, 2, 3, 5, 7, 10)
load_long <- data.frame(
  years = rep(years, 3),
  loading = as.vector(V[, 1:3]),
  component = factor(
    rep(c("PC1: level", "PC2: slope", "PC3: curvature"), each = 8),
    levels = c("PC1: level", "PC2: slope", "PC3: curvature")
  )
)
ggplot(load_long, aes(years, loading, colour = component)) +
  geom_hline(yintercept = 0, colour = "grey60") +
  geom_line(linewidth = 1) + geom_point(size = 2.2) +
  scale_colour_manual(values = c("#2a78d6", "#eb6834", "#1baf7a"), name = NULL) +
  labs(title = "The weights of the first three components", x = "maturity (years)", y = "loading") +
  theme_bw() + theme(legend.position = "bottom")

Loadings – Step 1: principal components

The eight rates have turned into three ideas, known to every bond trader since Litterman and Scheinkman (1991):

  • PC1, the level (98.6% of the variance): nearly equal weights. High when all rates are high.
  • PC2, the slope (1.3%): negative weights for the short, positive for the long rates. High when the curve is steep, negative when it is inverted.
  • PC3, the curvature (0.08%): positive at both ends, negative in the middle.

The remaining five together have 0.02% of the variance.

Step 2: regress the outcome on the scores

Take the first \(a\) components and run an ordinary regression:

\[y = \gamma_0 + \gamma_1 t_1 + \dots + \gamma_a t_a + e\]

The scores are uncorrelated, so the coefficient of a component does not change when others are added or removed. There is no collinearity left.

Step 3: translate back to the original predictors

The scores are weighted sums of the rates, so the regression on the scores is a regression on the rates, with coefficients

\[\hat\beta_{PCR} = V_a \hat\gamma = \sum_{j=1}^{a} \hat\gamma_j v_j\]

With all eight components this is exactly the least-squares solution. With fewer, the directions in which the predictors hardly vary are left out, and those were the directions that made the coefficients explode: the variance of \(\hat\gamma_j\) is \(\sigma^2 / \big((n-1)\lambda_j\big)\), huge when \(\lambda_j\) is tiny.

Step 4: choose the number of components

PCR has one setting, \(a\). It is chosen by cross-validation: which number of components predicts quarters that were not used in the fit best?


5. Fitting the model

How many components? Cross-validation in blocks

Neighboring quarters are nearly copies of each other, so leaving out single quarters at random would be no test at all. We cut the years into ten blocks, leave out one, and also the four quarters on each side of it, whose outcomes overlap with the block:

Code
block <- cut(seq_len(n), 10, labels = FALSE)
cv_error <- function(predict_fun) {
  pred <- numeric(n)
  for (k in 1:10) {
    test <- which(block == k)
    # the block and its neighbors
    near <- which(sapply(seq_len(n), function(i) min(abs(i - test))) <= 4)
    pred[test] <- predict_fun(setdiff(seq_len(n), near), test)
  }
  sqrt(mean((y - pred)^2))
}
pcr_predict <- function(a) function(train, test) {
  if (a == 0) return(rep(mean(y[train]), length(test)))
  m <- pcr(y ~ X, ncomp = a, data = list(y = y[train], X = X[train, ]))
  drop(predict(m, newdata = list(X = X[test, , drop = FALSE]), ncomp = a))
}
spread <- X[, "10 years"] - X[, "3 months"] # the classic single predictor
spread_predict <- function(train, test) {
  b <- coef(lm(y[train] ~ spread[train])); b[1] + b[2] * spread[test]
}
set.seed(21)
ridge_predict <- function(train, test) {
  m <- cv.glmnet(
    X[train, ],
    y[train],
    alpha = 0,
    standardize = FALSE,
    lambda = 10^seq(3, -4, length.out = 80)
  )
  drop(predict(m, X[test, , drop = FALSE], s = "lambda.min"))
}
cv <- c(
  sapply(0:8, function(a) cv_error(pcr_predict(a))),
  cv_error(spread_predict),
  cv_error(ridge_predict)
)
names(cv) <- c(paste(0:8, "components"), "spread 10 years - 3 months", "ridge")
cbind(error = round(cv, 3))
                           error
0 components               2.049
1 components               2.105
2 components               1.998
3 components               1.886
4 components               1.911
5 components               1.915
6 components               1.987
7 components               1.961
8 components               2.002
spread 10 years - 3 months 2.003
ridge                      1.938
Code
best <- which.min(cv[2:9])
Code
cv_data <- data.frame(a = 0:8, rmse = cv[1:9])
ggplot(cv_data, aes(a, rmse)) +
  geom_line(colour = "#2a78d6", linewidth = 0.9) +
  geom_point(colour = "#2a78d6", size = 2.5) +
  geom_hline(
    yintercept = cv[["spread 10 years - 3 months"]],
    linetype = "dashed",
    colour = "#eb6834"
  ) +
  scale_x_continuous(breaks = 0:8) +
  labs(
    title = "Error of the forecast in left-out blocks of years",
    subtitle = "Dashed: a regression on the difference of the 10-year and the 3-month rate",
    x = "number of components",
    y = "root mean squared error (points of growth)"
  ) +
  theme_bw()

CV chart – How many components? Cross-validation in blocks

  • No component (always predict the mean): 2.05 points. One (the level) is worse: 2.11. With 3 the error is smallest, 1.89. With all 8, which is least squares, 2.00.
  • The spread between the 10-year and the 3-month rate, the one-number version of the slope, has 2.00. Ridge regression, which shrinks all the directions instead of cutting some off, has 1.94.
  • Nothing is impressive: the best model improves on the plain mean by 8%. The economy is hard to predict.

The same with pcr()

Code
market   <- data.frame(y = y)
market$X <- X                                   # a matrix as one column of the data frame
fit <- pcr(y ~ X, ncomp = 8, data = market)
summary(fit)
Data:   X dimension: 170 8 
    Y dimension: 170 1
Fit method: svdpc
Number of components considered: 8
TRAINING: % variance explained
   1 comps  2 comps  3 comps  4 comps  5 comps  6 comps  7 comps  8 comps
X  98.5508    99.89    99.98    99.99   100.00   100.00   100.00    100.0
y   0.1692    16.63    21.97    23.89    25.58    27.74    29.83     29.9
Code
beta_pcr <- drop(coef(fit, ncomp = best))
beta_hand <- drop(V[, 1:best] %*% gamma[-1][1:best])
max(abs(beta_pcr - beta_hand))
[1] 2.520206e-14

summary() prints the cumulative share of the variance of \(X\) and of \(y\) explained by 1, 2, … components. The last line says 22.0% of the variance of growth for three components. pcr() can do the cross-validation, too (validation = "CV"), but with random segments unless you pass your own in segments.

Back to the interest rates

Code
coef_data <- data.frame(
  years = rep(years, 2),
  beta = c(coef(ols)[-1], beta_pcr),
  method = rep(c("Least squares (8 components)", paste0("PCR (", best, " components)")), each = 8)
)
ggplot(coef_data, aes(years, beta, colour = method)) +
  geom_hline(yintercept = 0, colour = "grey60") +
  geom_line(linewidth = 0.9) +
  geom_point(size = 2.2) +
  scale_colour_manual(values = c("#eb6834", "#2a78d6"), name = NULL) +
  labs(
    title = "Coefficients of the eight rates",
    x = "maturity (years)",
    y = "points of growth per point of the rate"
  ) +
  theme_bw() +
  theme(legend.position = "bottom")

Coefficients chart – Back to the interest rates

The coefficients of PCR are small and follow a smooth pattern; those of least squares jump up and down. Both predict. Only one can be read: what matters is the shape of the curve, the long end against the short end and the middle.


6. What do the numbers mean?

The slope component is nearly the classic spread: their correlation is

Code
cor(Tscores[, "PC2"], spread)
[1] 0.9464751
Code
sd_slope <- sd(Tscores[, "PC2"])
c(sd_of_slope_score = sd_slope, effect_of_one_sd = unname(gamma["slope"]) * sd_slope)
sd_of_slope_score  effect_of_one_sd 
        1.1672042         0.8126678 

A quarter whose slope score is one standard deviation above average was followed by growth that was 0.81 points higher, 95% CI [0.49, 1.14].

Code
ggplot(
  data.frame(
    slope = Tscores[, "PC2"],
    y,
    decade = factor(paste0(10 * (as.numeric(substr(quarters, 1, 4)) %/% 10), "s"))
  ),
  aes(slope, y)
) +
  geom_vline(xintercept = 0, colour = "grey70") +
  geom_point(aes(colour = decade), size = 1.8, alpha = 0.8) +
  geom_smooth(method = "lm", formula = y ~ x, se = FALSE, colour = "grey20", linewidth = 0.8) +
  scale_colour_viridis_d(option = "C", end = 0.9, name = NULL) +
  labs(
    title = "The slope of the yield curve and growth in the following year",
    x = "score of PC2 (left: flat or inverted curve; right: steep)",
    y = "growth (%)"
  ) +
  theme_bw() +
  theme(legend.position = "bottom")

Scores chart – 6. What do the numbers mean?

Is the relation stable?

Code
periods <- list(`1976-2018` = rep(TRUE, n), `1976-1984` = time < 1985, `1985-2018` = time >= 1985)
stable <- t(sapply(periods, function(p) {
  m <- lm(y[p] ~ Tscores[p, 1:3])
  c(quarters = sum(p), slope = coef(m)[[3]], R2 = summary(m)$r.squared)
}))
round(stable, 2)
          quarters slope   R2
1976-2018      170  0.70 0.22
1976-1984       34  1.40 0.66
1985-2018      136  0.42 0.11

It is not. The slope mattered much more until 1984 than after. A model that was chosen on the whole period knows how the story ended. A real forecaster did not.


7. Things to keep in mind

  • Choose the components by how they predict, not by their variance. Cross-validate, look at the correlation of every component with the outcome, and do not trust the rule of 80% or 95% of the variance.
  • Nor choose them one by one by their p values. With many components, picking the significant ones is stepwise regression with all its problems. Taking the first \(a\) in their order is a safer restriction.
  • Standardize unless all the predictors are in the same unit and their differences in variance mean something.
  • The components belong to the sample. In cross-validation they must be computed from the training rows only, as pcr() does, and for new data the old means and loadings are used.
  • PCR does not select predictors. Every component contains all of them. To leave some out, use the lasso.
  • Ridge regression is the smooth version of the same idea: it shrinks a direction more the smaller its variance (see regularized regression). PCR keeps it or drops it.
  • Partial least squares chooses its components by looking at the outcome, which repairs the weak point shown here.
  • Factor analysis is not PCR. A component is a weighted sum of the observed variables. A factor is a hidden cause of them, with its own model of measurement error.
  • Overlapping outcomes make a short sample look long. The 170 quarters here are about 42 independent years, with 14 quarters of falling GDP ahead, in a handful of recessions.

8. Reporting the results in APA style

A report (APA 7th edition) needs the predictors and their scaling, how the number of components was chosen, the share of variance of each component, what the components mean, and the regression on them. The numbers come from the R objects:

Code
apa_table <- data.frame(
  Component = c("Intercept", "PC1: level", "PC2: slope", "PC3: curvature"),
  var  = c("—", pct(share[1:3], 2)),
  r    = c("—", nz(r_components[1:3])),
  b    = f3(gamma), SE = f3(hac[, 2]),
  CI   = paste0("[", f2(ci[, 1]), ", ", f2(ci[, 2]), "]"),
  p    = sapply(hac[, 4], function(p) sub("^= ", "", pval(p))))

Method (data analysis):

We predicted the growth of US real GDP over the following four quarters from the interest rates of eight maturities (3 months to 10 years; quarterly means, 1976Q3–2018Q4, N = 170). Because the rates were highly correlated (r = .94 to .999; largest variance inflation factor = 12,176), we used principal components regression on the centered, unstandardized rates. The number of components was chosen by cross-validation with ten blocks of consecutive quarters, leaving out four quarters on each side of the block. Standard errors are Newey–West with six lags, because the outcomes of neighboring quarters overlap. Analyses were conducted in R (Version 4.6.2; R Core Team, 2026) with the package pls (Mevik & Wehrens, 2007).

Results:

The first three components explained 99.98% of the variance of the rates and corresponded to the level, the slope and the curvature of the yield curve (Table 1). Cross-validation favored 3 components (RMSE = 1.89 percentage points, against 2.05 for the mean and 2.00 for least squares with all the rates). The level was not related to growth, b = 0.008, p = .747. Growth was higher after a steep curve, b = 0.70, 95% CI [0.42, 0.97], p < .001, and lower after a curve that was high at both ends, b = -1.61, 95% CI [-2.57, -0.66], p = .001; R² = .22. The coefficient of the slope was 1.40 until 1984 and 0.42 afterwards.

Table 1

Principal Components Regression of GDP Growth on the Yield Curve

Component Variance of the rates r with growth b SE 95% CI p
Intercept — — 2.781 0.244 [2.30, 3.26] < .001
PC1: level 98.55% .04 0.008 0.026 [-0.04, 0.06] .747
PC2: slope 1.34% .41 0.696 0.140 [0.42, 0.97] < .001
PC3: curvature 0.08% -.23 -1.615 0.484 [-2.57, -0.66] .001

Note. N = 170 quarters. b: percentage points of growth per unit of the component score. Newey–West standard errors (6 lags).

Points to remember:

  • Say whether the predictors were standardized.
  • Report the variance share and the relation to the outcome of each component.
  • Name the components only after showing their loadings.
  • Validate with a scheme that fits the data: blocks for time series, groups for clustered data.

9. Summary

When Many, highly correlated predictors, and the aim is prediction or a few interpretable summaries
Step 1 Principal components of \(X\): uncorrelated weighted sums, ordered by variance
Step 2 Regress \(y\) on the first \(a\) scores
Back \(\hat\beta = V_a \hat\gamma\): coefficients for the original predictors
How (R) pls::pcr(y ~ X, ncomp = , scale = , validation = "CV"), or prcomp() and lm()
Choose \(a\) Cross-validation, with the components computed inside
Weak point The components ignore \(y\); small-variance components can matter most
Relatives Ridge (shrinks instead of cutting), partial least squares (looks at \(y\))
Related pages Regularized regression, stepwise regression, generalized least squares

References

Board of Governors of the Federal Reserve System (US). (n.d.). Market yield on U.S. Treasury securities at constant maturity [Data set]. FRED, Federal Reserve Bank of St. Louis. https://fred.stlouisfed.org/series/GS10

Estrella, A., & Hardouvelis, G. A. (1991). The term structure as a predictor of real economic activity. The Journal of Finance, 46(2), 555–576. https://doi.org/10.1111/j.1540-6261.1991.tb02674.x

Jolliffe, I. T. (1982). A note on the use of principal components in regression. Journal of the Royal Statistical Society: Series C, 31(3), 300–303. https://doi.org/10.2307/2348005

Litterman, R. B., & Scheinkman, J. (1991). Common factors affecting bond returns. The Journal of Fixed Income, 1(1), 54–61. https://doi.org/10.3905/jfi.1991.692347

Mevik, B.-H., & Wehrens, R. (2007). The pls package: Principal component and partial least squares regression in R. Journal of Statistical Software, 18(2), 1–23. https://doi.org/10.18637/jss.v018.i02

U.S. Bureau of Economic Analysis. (n.d.). Real gross domestic product [GDPC1] [Data set]. FRED, Federal Reserve Bank of St. Louis. https://fred.stlouisfed.org/series/GDPC1