To construct the smooth matrix ( \mathbf{W} ) for a running-line smoother with symmetric ( K )-nearest neighbors (( K = 2 )) and ( N = 10 ) data points, follow these steps:
Understanding the Smoother
-
Neighborhood Definition:
- For each data point ( x_i ), select ( K = 2 ) nearest neighbors on each side, resulting in a window size of ( 2K + 1 = 5 ) points.
- Edge Cases: At the boundaries (i.e., ( i = 1, 2, 9, 10 )), the number of neighbors is reduced to accommodate the lack of points on one side.
-
Least Squares Line Fit:
- For each neighborhood, fit a least squares line ( S(x_i) = \hat{\alpha}(x_i) + \hat{\beta}(x_i) x_i ).
- Due to the symmetry and equal spacing of ( x )-values, the slope ( \hat{\beta}(x_i) ) becomes zero, simplifying ( S(x_i) ) to the average of the neighboring ( y )-values.
-
Weight Assignment:
- The smooth matrix ( \mathbf{W} ) assigns equal weights to all points within the neighborhood and zero outside.
- The weights are determined by the window size ( m ):
- ( m = 5 ) for central points (( i = 3, 4, \ldots, 8 ))
- ( m = 4 ) for points near the edges (( i = 2, 9 ))
- ( m = 3 ) for the extreme edges (( i = 1, 10 ))
Constructing the Smooth Matrix ( \mathbf{W} )
Given ( N = 10 ) and ( K = 2 ), the smooth matrix ( \mathbf{W} ) is a ( 10 \times 10 ) matrix where each row corresponds to a data point ( x_i ) and contains the weights assigned to its neighbors. The weights are as follows:
[
\mathbf{W} =
\begin{bmatrix}
\frac{1}{3} & \frac{1}{3} & \frac{1}{3} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
\frac{1}{4} & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} & 0 & 0 & 0 & 0 & 0 & 0 \
\frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 & 0 & 0 & 0 \
0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 & 0 & 0 \
0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 & 0 \
0 & 0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 \
0 & 0 & 0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 \
0 & 0 & 0 & 0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} \
0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} \
0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{3} & \frac{1}{3} & \frac{1}{3} \
\end{bmatrix}
]
Explanation of the Matrix
- Rows 1 and 10: These correspond to the extreme edges with only 3 neighbors each. Hence, non-zero weights are ( \frac{1}{3} ).
- Rows 2 and 9: These are near the edges with 4 neighbors each, so non-zero weights are ( \frac{1}{4} ).
- Rows 3 to 8: These are central points with 5 neighbors each, assigning equal weights of ( \frac{1}{5} ).
Visual Representation
Here's a visual representation of the smooth matrix ( \mathbf{W} ):
[
\mathbf{W} =
\begin{bmatrix}
\frac{1}{3} & \frac{1}{3} & \frac{1}{3} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
\frac{1}{4} & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} & 0 & 0 & 0 & 0 & 0 & 0 \
\frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 & 0 & 0 & 0 \
0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 & 0 & 0 \
0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 & 0 \
0 & 0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 \
0 & 0 & 0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 \
0 & 0 & 0 & 0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} \
0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} \
0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{3} & \frac{1}{3} & \frac{1}{3} \
\end{bmatrix}
]
Conclusion
This matrix ( \mathbf{W} ) effectively smooths the data by averaging the ( y )-values within each neighborhood. Each row of ( \mathbf{W} ) corresponds to a data point ( x_i ) and contains equal weights for its ( K )-nearest neighbors, ensuring that edge effects are appropriately handled with reduced window sizes.
Final Smooth Matrix ( \mathbf{W} ):
[
\mathbf{W} =
\begin{bmatrix}
\frac{1}{3} & \frac{1}{3} & \frac{1}{3} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
\frac{1}{4} & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} & 0 & 0 & 0 & 0 & 0 & 0 \
\frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 & 0 & 0 & 0 \
0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 & 0 & 0 \
0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 & 0 \
0 & 0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 & 0 \
0 & 0 & 0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & 0 \
0 & 0 & 0 & 0 & 0 & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} & \frac{1}{5} \
0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} \
0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{3} & \frac{1}{3} & \frac{1}{3} \
\end{bmatrix}
]