smooth.spline {modreg} | R Documentation |
Fit a Smoothing Spline
Description
Fits a cubic smoothing spline to the supplied data.
Usage
smooth.spline(x, y, w = rep(1, length(x)), df = 5, spar = 0,
cv = FALSE, all.knots = FALSE, df.offset = 0, penalty = 1)
Arguments
x |
a vector giving the values of the predictor variable, or a list or a two-column matrix specifying x and y. |
y |
responses. If |
w |
optional vector of weights |
df |
the desired equivalent number of degrees of freedom (trace of the smoother matrix). |
spar |
the coefficient |
cv |
ordinary ( |
all.knots |
if |
df.offset |
allows the degrees of freedom to be increased by
|
penalty |
the coefficient of the penalty for degrees of freedom in the GCV criterion. |
Details
The x
vector should contain at least ten distinct values.
If spar
is missing or 0, the value of df
is used to
determine the degree of smoothing. If both are missing, leave-one-out
cross-validation is used to determine \lambda
.
Value
An object of class "smooth.spline"
with components
x |
the distinct |
y |
the fitted values corresponding to |
w |
the weights used at the unique values of |
yin |
the y values used at the unique |
lev |
leverages, the diagonal values of the smoother matrix. |
cv.crit |
(generalized) cross-validation score. |
pen.crit |
penalized criterion |
df |
equivalent degrees of freedom used. |
spar |
the value of |
fit |
list for use by |
call |
Author(s)
B.D. Ripley
See Also
predict.smooth.spline
Examples
data(cars)
attach(cars)
plot(speed, dist, main = "data(cars) & smoothing splines")
cars.spl <- smooth.spline(speed, dist)
(cars.spl)
all(cars.spl $ w == table(speed)) # TRUE (weights = multiplicities)
lines(cars.spl, col = "blue")
lines(smooth.spline(speed, dist, df=10), lty=2, col = "red")
legend(5,120,c(paste("default [C.V.] => df =",round(cars.spl$df,1)),
"s( * , df = 10)"), col = c("blue","red"), lty = 1:2,
bg='bisque')
detach()