Trends and Smoothing II

36-467/36-667

4 September 2018

\[ \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}} \DeclareMathOperator{\tr}{tr} \DeclareMathOperator*{\argmin}{argmin} \DeclareMathOperator{\dof}{DoF} \DeclareMathOperator{\det}{det} \newcommand{\TrueNoise}{\epsilon} \newcommand{\EstNoise}{\widehat{\TrueNoise}} \]

In our last episode…

Expectation of the fitted values

\[\begin{eqnarray} \Expect{\mathbf{\EstRegFunc}} & = & \Expect{\mathbf{w}\mathbf{X}}\\ & = & \mathbf{w}\Expect{\mathbf{X}}\\ & = & \mathbf{w} \mathbf{\mu} \end{eqnarray}\]

Unbiased estimate \(\Leftrightarrow \mathbf{w} \mathbf{\mu} = \mathbf{\mu}\)

Expanding in eigenvectors

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

w
##            [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
##  [1,] 0.5000000 0.5000000 0.0000000 0.0000000 0.0000000 0.0000000
##  [2,] 0.3333333 0.3333333 0.3333333 0.0000000 0.0000000 0.0000000
##  [3,] 0.0000000 0.3333333 0.3333333 0.3333333 0.0000000 0.0000000
##  [4,] 0.0000000 0.0000000 0.3333333 0.3333333 0.3333333 0.0000000
##  [5,] 0.0000000 0.0000000 0.0000000 0.3333333 0.3333333 0.3333333
##  [6,] 0.0000000 0.0000000 0.0000000 0.0000000 0.3333333 0.3333333
##  [7,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.3333333
##  [8,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
##  [9,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [10,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
##            [,7]      [,8]      [,9]     [,10]
##  [1,] 0.0000000 0.0000000 0.0000000 0.0000000
##  [2,] 0.0000000 0.0000000 0.0000000 0.0000000
##  [3,] 0.0000000 0.0000000 0.0000000 0.0000000
##  [4,] 0.0000000 0.0000000 0.0000000 0.0000000
##  [5,] 0.0000000 0.0000000 0.0000000 0.0000000
##  [6,] 0.3333333 0.0000000 0.0000000 0.0000000
##  [7,] 0.3333333 0.3333333 0.0000000 0.0000000
##  [8,] 0.3333333 0.3333333 0.3333333 0.0000000
##  [9,] 0.0000000 0.3333333 0.3333333 0.3333333
## [10,] 0.0000000 0.0000000 0.5000000 0.5000000

A little example

eigen(w)$values
##  [1]  1.00000000  0.96261129  0.85490143  0.68968376  0.48651845
##  [6] -0.31012390  0.26920019 -0.23729622 -0.11137134  0.06254301
eigen(w)$vectors[,1]
##  [1] 0.3162278 0.3162278 0.3162278 0.3162278 0.3162278 0.3162278 0.3162278
##  [8] 0.3162278 0.3162278 0.3162278

A little example

Variance of the fitted values

\[\begin{eqnarray} \Var{\mathbf{\EstRegFunc}} & = & \Var{\mathbf{w}\mathbf{X}}\\ & = & \mathbf{w}\Var{\mathbf{X}}\mathbf{w}^T\\ & = & \mathbf{w}\Var{\mathbf{\TrueRegFunc} + \mathbf{\TrueNoise}}\mathbf{w}^T\\ & = & \mathbf{w}\Var{\mathbf{\TrueNoise}}\mathbf{w}^T \end{eqnarray}\]

IF \(\Var{\mathbf{\TrueNoise}} = \sigma^2 \mathbf{I}\), THEN \(\Var{\mathbf{\EstRegFunc}} = \sigma^2\mathbf{w}\mathbf{w}^T\)

How much do the fitted values respond to the data?

\[\begin{eqnarray} \sum_{i=1}^{n}{\Cov{\EstRegFunc_i, X_i}} & = & \sum_{i=1}^{n}{\Cov{\sum_{j=1}^{n}{w_{ij} X_j}, X_i}}\\ & = & \sum_{i=1}^{n}{\sum_{j=1}^{n}{w_{ij} \Cov{X_i, X_j}}}\\ & = & \sum_{i=1}^{n}{\sum_{j=1}^{n}{w_{ij} \Cov{\TrueNoise_i, \TrueNoise_j}}} \end{eqnarray}\]

IF \(\Var{\mathbf{\TrueNoise}} = \sigma^2 \mathbf{I}\), THEN this \(= \sigma^2\tr{\mathbf{w}} = \sigma^2 \text{(sum of eigenvalues)}\)

\(\tr{\mathbf{w}} =\) (effective) degrees of freedom

Data = trend + fluctuation

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

Convince yourself: \(\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

Break for the in-class exercise

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 this \(= \sigma^2 (\mathbf{I}-\mathbf{w})(\mathbf{I}-\mathbf{w})^T\)

NB: Correlations from off-diagonal entries in \(\mathbf{w}\)

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}\]

Many variants

The moral

Summing up