\Header{smooth.spline}{Fit a Smoothing Spline}
\alias{predict.smooth.spline.fit}{smooth.spline}
\alias{print.smooth.spline}{smooth.spline}
\keyword{smooth}{smooth.spline}
\begin{Description}\relax
Fits a cubic smoothing spline to the supplied data.\end{Description}
\begin{Usage}
\begin{verbatim}
smooth.spline(x, y, w = rep(1, length(x)), df = 5, spar = 0,
              cv = FALSE, all.knots = FALSE, df.offset = 0, penalty = 1)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a vector giving the values of the predictor variable, or  a
list or a two-column matrix specifying x and y. 
\item[\code{y}] responses. If \code{y} is missing, the responses are assumed
to be specified by \code{x}.
\item[\code{w}] optional vector of weights
\item[\code{df}] the desired equivalent number of degrees of freedom (trace of
the smoother matrix).
\item[\code{spar}] the coefficient \eqn{\lambda}{} of the integral of the squared
second derivative in the fit (penalized log likelihood) criterion.
\item[\code{cv}] ordinary (\code{TRUE}) or `generalized' (\code{FALSE})
cross-validation.
\item[\code{all.knots}] if \code{TRUE}, all points in \code{x} are uses as
knots. If \code{FALSE}, a suitably fine grid of knots is used.
\item[\code{df.offset}] allows the degrees of freedom to be increased by
\code{df.offset} in the GCV criterion.
\item[\code{penalty}] the coefficient of the penalty for degrees of freedom
in the GCV criterion.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The \code{x} vector should contain at least ten distinct values.

If \code{spar} is missing or 0, the value of \code{df} is used to
determine the degree of smoothing. If both are missing, leave-one-out
cross-validation is used to determine \eqn{\lambda}{}.

The `generalized' cross-validation method will work correctly when
there are duplicated points in \code{x}.  However, it is ambiguous what
leave-one-out cross-validation means with duplicated points, and the
internal code uses an approximation that involves leaving out groups
of duplicated points.  \code{cv=TRUE} is best avoided in that case.\end{Details}
\begin{Value}
An object of class \code{"smooth.spline"} with components
\begin{ldescription}
\item[\code{x}] the distinct \code{x} values in increasing order.
\item[\code{y}] the fitted values corresponding to \code{x}.
\item[\code{w}] the weights used at the unique values of \code{x}.
\item[\code{yin}] the y values used at the unique \code{y} values.
\item[\code{lev}] leverages, the diagonal values of the smoother matrix.
\item[\code{cv.crit}] (generalized) cross-validation score.
\item[\code{pen.crit}] penalized criterion
\item[\code{df}] equivalent degrees of freedom used.
\item[\code{spar}] the value of \eqn{\lambda}{} chosen.
\item[\code{fit}] list for use by \code{predict.smooth.spline}.
\item[\code{call}] the matched call.
\end{ldescription}
\end{Value}
\begin{Author}\relax
B.D. Ripley\end{Author}
\begin{SeeAlso}\relax
\code{\Link{predict.smooth.spline}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(cars)
attach(cars)
plot(speed, dist, main = "data(cars)  &  smoothing splines")
cars.spl <- smooth.spline(speed, dist)
(cars.spl)
## This example has duplicate points, so avoid cv=TRUE

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()
\end{ExampleCode}
\end{Examples}

