\HeaderA{smooth.construct.cr.smooth.spec}{Penalized Cubic regression splines in GAMs}{smooth.construct.cr.smooth.spec}
\aliasA{cubic.regression.spline}{smooth.construct.cr.smooth.spec}{cubic.regression.spline}
\aliasA{cyclic.cubic.spline}{smooth.construct.cr.smooth.spec}{cyclic.cubic.spline}
\aliasA{smooth.construct.cc.smooth.spec}{smooth.construct.cr.smooth.spec}{smooth.construct.cc.smooth.spec}
\aliasA{smooth.construct.cs.smooth.spec}{smooth.construct.cr.smooth.spec}{smooth.construct.cs.smooth.spec}
\keyword{models}{smooth.construct.cr.smooth.spec}
\keyword{regression}{smooth.construct.cr.smooth.spec}
\begin{Description}\relax
\code{\LinkA{gam}{gam}} can use univariate penalized cubic regression spline smooths, specified via terms like
\code{s(x,bs="cr")}. \code{s(x,bs="cs")} specifies a penalized cubic regression spline in which a small ridge 
penalty has been added to the cubic spline penalty, in order to allow the term to be shrunk  to zero if the 
smoothing parameter is high enough (as the smoothing parameter goes to infinity a normal cubic spline tends to a 
straight line.) \code{s(x,bs="cc")} specifies a cyclic penalized cubic regression spline smooth.

`Cardinal' spline bases are used: Wood (2006) sections 4.1.2 and 4.1.3 gives full details. These bases have 
very low setup costs. For a given basis dimension, \code{k}, they typically perform a little less well 
then thin plate regression splines, but a little better than p-splines. See \code{\LinkA{te}{te}} to use these bases in tensor product smooths of several variables.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'cr.smooth.spec':
smooth.construct(object, data, knots)
## S3 method for class 'cs.smooth.spec':
smooth.construct(object, data, knots)
## S3 method for class 'cc.smooth.spec':
smooth.construct(object, data, knots)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{object}] a smooth specification object, usually generated by a term \code{s(...,bs="cr",...)},
\code{s(...,bs="cs",...)} or \code{s(...,bs="cc",...)}
\item[\code{data}] a list containing just the data (including any \code{by} variable) required by this term, 
with names corresponding to \code{object\$term} (and \code{object\$by}). The \code{by} variable 
is the last element.
\item[\code{knots}] a list containing any knots supplied for basis setup --- in same order and with same names as \code{data}. 
Can be \code{NULL}
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The constructor is not normally called directly, but is rather used internally by \code{\LinkA{gam}{gam}}. 
To use for basis setup it is recommended to use \code{\LinkA{smooth.construct2}{smooth.construct2}}.  

If they are not supplied then the knots  of the spline are placed evenly
throughout the covariate values to which the term refers:  For
example, if fitting 101 data with an 11 knot spline of \code{x} then
there would be a knot at every 10th (ordered)  \code{x} value. The
parameterization used represents the spline in terms of its
values at the knots. The values at neighbouring knots
are connected by sections of  cubic polynomial constrained to be 
continuous up to and including second derivative at the knots. The resulting curve
is a natural cubic  spline through the values at the knots (given two extra conditions specifying 
that the second derivative of the curve should be zero at the two end 
knots).

Note that the cyclic smoother will wrap at the smallest and largest covariate values, unless knots are supplied, and 
is not subject to the condition that second derivatives go to zero at the first and last knots.
\end{Details}
\begin{Value}
An object of class \code{"cr.smooth"} \code{"cs.smooth"} or \code{"cyclic.smooth"}.
In addition to the usual elements of a smooth class documented under \code{\LinkA{smooth.construct}{smooth.construct}}, 
this object will contain:
\begin{ldescription}
\item[\code{xp}] giving the knot locations used to generate the basis.
\item[\code{BD}] class \code{"cyclic.smooth"} objects include matrix \code{BD} which transforms function values 
at the knots to second derivatives at the knots.
\end{ldescription}

normal-bracket51bracket-normal
\end{Value}
\begin{Author}\relax
Simon N. Wood \email{simon.wood@r-project.org}
\end{Author}
\begin{References}\relax
Wood S.N. (2006) Generalized Additive Models: An Introduction with R. Chapman
and Hall/CRC Press.
\end{References}
\begin{Examples}
\begin{ExampleCode}
## cyclic spline example...
  set.seed(6)
  x <- sort(runif(200)*10)
  z <- runif(200)
  f <- sin(x*2*pi/10)+.5
  y <- rpois(exp(f),exp(f)) 

## finished simulating data, now fit model...
  b <- gam(y ~ s(x,bs="cc",k=12) + s(z),family=poisson,
                      knots=list(x=seq(0,10,length=12)))
## plot results...
  par(mfrow=c(2,2))
  plot(x,y);plot(b,select=1,shade=TRUE);lines(x,f-mean(f),col=2)
  plot(b,select=2,shade=TRUE);plot(fitted(b),residuals(b))
  

\end{ExampleCode}
\end{Examples}

