# NOT RUN {
require(stats) # for smooth.spline() or loess()
x1 <- c(1:4, 7:12)
H1 <- hatMat(x1, spar = 0.5) # default : smooth.spline()
matplot(x1, H1, type = "l", main = "columns of smoother hat matrix")
## Example 'pred.sm' arguments for hatMat() :
pspl <- function(x,y,...) predict(smooth.spline(x,y, ...), x = x)$y
pksm <- function(x,y,...) ksmooth(sort(x),y, "normal", x.points=x, ...)$y
## Rather than ksmooth():
if(require("lokern"))
pksm2 <- function(x,y,...) glkerns(x,y, x.out=x, ...)$est
# }
# NOT RUN {
<!-- % pRmean <- function(x,y,...) run.mean(y, ...) -->
# }
# NOT RUN {
<!-- % pRline <- function(x,y,...) run.line(x,y, ...)$y -->
# }
# NOT RUN {
## Explaining 'trace = TRUE'
all.equal(sum(diag((hatMat(c(1:4, 7:12), df = 4)))),
hatMat(c(1:4, 7:12), df = 4, trace = TRUE), tol = 1e-12)
## ksmooth() :
Hk <- hatMat(x1, pr = pksm, bandwidth = 2)
cat(sprintf("df = %.2f\n", sum(diag(Hk))))
image(Hk)
Matrix::printSpMatrix(as(round(Hk, 2), "sparseMatrix"))
##---> see demo("hatmat-ex") for more (and larger) examples
# }
# NOT RUN {
<!-- %% should test these also for x with ties -->
# }
Run the code above in your browser using DataCamp Workspace