smooth.spline(x, y, w = <<see below>>, df = <<see below>>, spar = 0, cv = F, all.knots = F, df.offset = 0, penalty = 1)
x and y can be supplied in a variety of different forms, along the lines of the function plot; e.g., a list with components x and y, a two-column matrix, or simply a single vector, taken to be a time series if it is not complex..
A cubic B-spline is fit with care taken to insure that the algorithm runs linear in the number of data points. For small data vectors (n<50), a knot is placed at every distinct data point, and the regression is fit by penalized least squares. For larger data sets the number of knots is chosen judiciously in order to keep the computation time manageable (if all.knots=F). The penalty spar can be chosen automatically by cross-validation (if spar=0), can be supplied explicitly, or supplied implicitly via the more intuitive df number.
attach(air) plot(ozone,temperature) lines(smooth.spline(ozone,temperature)) lines(smooth.spline(ozone,temperature, df = 5), lty = 2)# smoothing spline fit and approximate 95% "confidence" intervals # need to create object x and y
fit <- smooth.spline(x, y) # smooth.spline fit res <- (fit$yin - fit$y)/(1-fit$lev) # jackknife residuals sigma <- sqrt(var(res)) # estimate sd
upper <- fit$y + 2.0*sigma*sqrt(fit$lev) # upper 95% conf. band lower <- fit$y - 2.0*sigma*sqrt(fit$lev) # lower 95% conf. band matplot(fit$x, cbind(upper, fit$y, lower), type="plp", pch=".")