# Calculate the smoothing / influence matrix for a 1D smoothing spline
# Inputs:
  # a previously-fitted spline (a.spline)
  # a vector of regressor coordinate values of length n (x)
# Output: the n*n influence matrix for a.pline
# Presumes:
  # a.spline has a lambda component (giving the spline penalty factor)
  # if x is not the coordinates used to fit a.spline, what are you doing?
# Source: see solutions to HW1
smoother.matrix <- function(a.spline, x) {
    n <- length(x)
    w <- matrix(0, nrow=n, ncol=n)
    for (i in 1:n) {
        y <- rep_len(0, n)  # Equivalent to rep(0, length.out=n) but faster
        y[i] <- 1
        w[,i] <- fitted(smooth.spline(x, y, lambda=a.spline$lambda))
    }
    return(w)
}
