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

If \texttt{spar} is missing or 0, the value of \texttt{df} is used to
determine the degree of smoothing. If both are missing, leave-one-out
cross-validation is used to determine \eqn{\lambda}{}.\end{Details}
\begin{Value}
An object of class \texttt{"smooth.spline"} with components
\begin{ldescription}
\item[\texttt{x}] the distinct \texttt{x} values in increasing order.
\item[\texttt{y}] the fitted values corresponding to \texttt{x}.
\item[\texttt{w}] the weights used at the unique values of \texttt{x}.
\item[\texttt{yin}] the y values used at the unique \texttt{y} values.
\item[\texttt{lev}] leverages, the diagonal values of the smoother matrix.
\item[\texttt{cv.crit}] (generalized) cross-validation score.
\item[\texttt{pen.crit}] penalized criterion
\item[\texttt{df}] equivalent degrees of freedom used.
\item[\texttt{spar}] the value of \eqn{\lambda}{} chosen.
\item[\texttt{fit}] list for use by \texttt{predict.smooth.spline}.
\item[\texttt{call}] 
\end{ldescription}
\end{Value}
\begin{Author}
B.D. Ripley\end{Author}
\begin{SeeAlso}
\texttt{\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)
all(cars.spl $ w == table(speed)) # TRUE (weights = multiplicities)

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()

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}

