Trends and Smoothing

36-740, Fall 2026

27 August 2026 (Lecture 2)

\[ \newcommand{\Expect}[1]{\mathbb{E}\left[ #1 \right]} \newcommand{\Var}[1]{\mathrm{Var}\left[ #1 \right]} \newcommand{\Cov}[1]{\mathrm{Cov}\left[ #1 \right]} \newcommand{\TrueRegFunc}{\mu} \newcommand{\EstRegFunc}{\widehat{\TrueRegFunc}} \newcommand{\TrueNoise}{\epsilon} \newcommand{\EstNoise}{\widehat{\TrueNoise}} \DeclareMathOperator{\tr}{tr} \DeclareMathOperator*{\argmin}{argmin} \DeclareMathOperator{\dof}{DoF} \]

The mathematical setting

Trend = central tendency of the random process

\[ \TrueRegFunc(r,t) \equiv \Expect{X(r,t)} \]

Trend + Fluctuations

Random process = trend + fluctuations

\[\begin{eqnarray} X(r,t) & = & \TrueRegFunc(r,t) + \TrueNoise(r,t)\\ \Expect{\TrueNoise(r,t)} & = & 0 \end{eqnarray}\]

(Sometimes called “signal plus noise” representation)

\(\TrueNoise =\) another random process

Learning the Trend

Averaging independent realizations gives the trend

Assume a whole theory

Assume a whole theory

Assume something about \(\TrueRegFunc\)

Our first smoothing estimator

\[ \EstRegFunc(t_i) = \frac{1}{3}\sum_{k=-1}^{k=+1}{X(t_{i+k})} \]

\[\begin{eqnarray} \EstRegFunc(t_i) & = & \frac{1}{3}\sum_{k=-1}^{k=+1}{\TrueRegFunc(t_{i+k})} + \frac{1}{3}\sum_{k=-1}^{k=+1}{\TrueNoise(t_{i+k})}\\ & = & \TrueRegFunc(t_i) + \frac{1}{3}\sum_{k=-1}^{k=+1}{(\TrueRegFunc(t_{i+k}) - \TrueRegFunc(t_i))} + \frac{1}{3}\sum_{k=-1}^{k=+1}{\TrueNoise(t_{i+k})}\\ & = & \text{truth} + \text{bias} + \text{noise} \end{eqnarray}\]

Linear smoothers

Examples of linear smoothers

Properties of linear smoothers

Expectation of the fitted values; bias

Shrinkage

A little example

n <- 10
w <- matrix(0, nrow = 10, ncol = 10)
diag(w) <- 1/3
for (i in 2:(n - 1)) {
    w[i, i + 1] <- 1/3
    w[i, i - 1] <- 1/3
}
w[1, 1] <- 1/2
w[1, 2] <- 1/2
w[n, n - 1] <- 1/2
w[n, n] <- 1/2

A little example

##  [1]  1.00000000  0.96261129  0.85490143  0.68968376  0.48651845 -0.31012390
##  [7]  0.26920019 -0.23729622 -0.11137134  0.06254301
##  [1] 0.3162278 0.3162278 0.3162278 0.3162278 0.3162278 0.3162278 0.3162278
##  [8] 0.3162278 0.3162278 0.3162278

Eigenvectors 2–4 of the example

Variance of the fitted values

Degrees of freedom

Using linear smoothers

An example to make things concrete: GDP Per Capita

An example to make things concrete: GDP Per Capita

An example to make things concrete: GDPPC growth rate

Trend=mean?

The math for taking the trend to be the global mean

A Law of Large Numbers

Trend=short moving average?

The math for moving averages

Trend=wider moving average?

Trend=one-sided moving average?

Data = trend + fluctuation

Some residuals

Residuals from using a constant trend:

Some residuals

Residuals from using an MA(5):

Some residuals

Residuals from using an MA(16) on the past:

Some math of residuals

\[\begin{eqnarray} \mathbf{\EstNoise} & = & \mathbf{x} - \mathbf{\EstRegFunc}\\ & = & \mathbf{x} - \mathbf{w}\mathbf{x}\\ & = & (\mathbf{I} - \mathbf{w})\mathbf{x} \end{eqnarray}\]

\(\mathbf{I}-\mathbf{w}\) has same eigenvectors as \(\mathbf{w}\), but eigenvalues \(1-\lambda\)

Expected residuals

\[\begin{eqnarray} \Expect{\mathbf{\EstNoise}} & = & \Expect{(\mathbf{I}-\mathbf{w})\mathbf{X}}\\ & = & (\mathbf{I}-\mathbf{w})\mathbf{\TrueRegFunc} \end{eqnarray}\]

Biased trend estimate \(\Leftrightarrow\) biased fluctuation estimate

Variance and covariance of the residuals

\[ \Var{\mathbf{\EstNoise}} = (\mathbf{I}-\mathbf{w}) \Var{\mathbf{\epsilon}} (\mathbf{I}-\mathbf{w})^T \]

IF \(\Var{\mathbf{\epsilon}} = \sigma^2 \mathbf{I}\), THEN \(\Var{\mathbf{\EstNoise}}= \sigma^2 (\mathbf{I}-\mathbf{w})(\mathbf{I}-\mathbf{w})^T\)

NB: Correlations from off-diagonal entries in \(\mathbf{w}\), even though there are no correlations for the true fluctuations

Splines

\[ \EstRegFunc = \argmin_{m}{\frac{1}{n}\sum_{i=1}^{n}{(x_i - m(t_i))^2} + \lambda\int{(m^{\prime\prime}(t))^2 dt}} \]

How do we pick \(\lambda\)?

Leave-one-out cross-validation (LOOCV)

Leave-one-out cross-validation (LOOCV)

Don’t have to re-fit linear smoothers \(n\) times:

\[\begin{eqnarray} \EstRegFunc^{(-i)}(t_i) &= & \frac{({\mathbf{w} \mathbf{x})}_i - w_{ii} x_i}{1-w_{ii}}\\ x_i - \EstRegFunc^{(-i)}(t_i) & = & \frac{x_i - \EstRegFunc(t_i)}{1-w_{ii}}\\ LOOCV & = & \frac{1}{n}\sum_{i=1}^{n}{\left(\frac{x_i-\EstRegFunc(t_i)}{1-w_{ii}}\right)^2} \end{eqnarray}\]

This just needs one fit to the whole data, and the diagonal of \(\mathbf{w}\)

(Trick due to Grace Wahba in the 1970s, see Wahba (1990), Thm. 4.2.1)

Spline smoothing of economic growth

## Call:
## smooth.spline(x = year, y = growth)
## 
## Smoothing Parameter  spar= 0.2246046  lambda= 7.290324e-08 (12 iterations)
## Equivalent Degrees of Freedom (Df): 79.22516
## Penalized Criterion (RSS): 0.1855217
## GCV: 0.001062535

Spline smoothing of economic growth

Confession: I cheated a little by omitting 2020–2021

## Call:
## smooth.spline(x = year, y = growth)
## 
## Smoothing Parameter  spar= 1.499938  lambda= 123.1236 (24 iterations)
## Equivalent Degrees of Freedom (Df): 2.006161
## Penalized Criterion (RSS): 0.6110623
## GCV: 0.001952273

Unsurprisingly (?), this looks almost the same as the original curve, except around 2020

Summing up

Next time

Exercises, to think through / practice with, rather than hand in

  1. Extract residuals from splines (i.e., both the spline curves) and plot them. Qualitatively, how do they look compared to each other? Compared to the residuals from the moving averages?
  2. Make a mosaic of plots of the residuals from the global mean, from all the moving averages, and from the splines, against each other. Qualitatively, do they mostly line up around the diagonal, or are there visually-discernable patterns?
    • Make sure you’re plotting residuals for the same time points across different estimators; this may need some fiddly adjustment of indices
  3. (Spiders Georg) Give 1–3 reasons why it makes sense to not include 2020–2021 in cross-validation here (“adn should not have been counted”). Also give 1–3 reasons why it is important, even vital, to include those years.
  4. Refer to the slide “A Law of Large Numbers”. Suppose \(\Expect{X_t} = \mu\), \(\Var{X_t} = \sigma^2\), and \(\Cov{X_t, X_s} = \sigma^2 \beta^{|t-s|}\) for some \(\beta \in (-1, 1)\). Show that \(V_n = o(n^2)\) and find an expression for \(\lim{n \Expect{(A_n - \mu)^2}}\) in terms of \(\mu\), \(\sigma^2\) and/or \(\beta\).
    • See also the exercises at the end of lecture 1.
  5. (LLN continued) More generally, suppose that \(\Cov{X_t, X_s} = \rho(|t-s|)\), with \(\rho(0) = \sigma^2\). Show that if \(\sum_{h=-\infty}^{\infty}{\rho(h)} = \sigma^2 \tau < \infty\), then \(V_n/n \rightarrow \sigma^2 \tau\) and \(n\Expect{(A_n - \mu)^2} \rightarrow \sigma^2 \tau\). Explain why, in this situation \(n/\tau\) is called the effective sample size.

Backup: More about eigenvalues and eigenvectors of influence matrices

Linear Regression \(\Leftrightarrow\) Projection onto a linear subspace

Backup: More about eigenvalues and eigenvectors of influence matrices

Weighted averages

References

Farebrother, Richard William. 1999. Fitting Linear Relationships: A History of the Calculus of Observations 1750–1900. New York: Springer-Verlag. https://doi.org/10.1007/978-1-4612-0545-6.

Shalizi, Cosma Rohilla. 2022. “A Simple Non-Stationary Mean Ergodic Theorem, with Bonus Weak Law of Large Numbers.” arxiv:2203.09085. https://arxiv.org/abs/2203.09085.

Taylor, G. I. 1922. “Diffusion by Continuous Movements.” Proceedings of the London Mathematical Society, 2nd ser., 20:196–212. https://doi.org/10.1112/plms/s2-20.1.196.

Tsai, Yao-Hung Hubert, Shaojie Bai, Makoto Yamada, Louis-Philippe Morency, and Ruslan Salakhutdinov. 2019. “Transformer Dissection: A Unified Understanding of Transformer’s Attention via the Lens of Kernel.” In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing [Emnlp 2019], 4344–53. https://doi.org/10.18653/v1/D19-1443.

Vaswani, Ashish, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. “Attention Is All You Need.” In Advances in Neural Information Processing Systems 30 [Nips 2017], edited by I. Guyon, U. Von Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett, 5998–6008. Red Hook, New York: Curran Associates. http://arxiv.org/abs/1706.03762.

Wahba, Grace. 1990. Spline Models for Observational Data. Philadelphia: Society for Industrial; Applied Mathematics. https://doi.org/10.1137/1.9781611970128.