\Header{bs}{Generate a Basis for Polynomial Splines}
\begin{Usage}
\begin{verbatim}
bs(x, df, knots, degree=3, intercept=FALSE, Boundary.knots)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{x}] the predictor variable.
\item[\texttt{df}] degrees of freedom; one can specify \texttt{df} rather than
\texttt{knots}; \texttt{bs()} then chooses \texttt{df-degree-1} knots at
suitable quantiles of \texttt{x}.
\item[\texttt{knots}] the \emph{internal} breakpoints that define the
spline.  The default is \texttt{NULL}, which results in a basis for
ordinary polynomial regression. Typical values are the mean or
median for one knot, quantiles for more knots. See also
\texttt{Boundary.knots}.
\item[\texttt{degree}] degree of the piecewise polynomial---default is 3 for
cubic splines.
\item[\texttt{intercept}] if \texttt{TRUE}, an intercept is included in the
basis; default is \texttt{FALSE}.
\item[\texttt{Boundary.knots}] boundary points at which to anchor the B-spline
basis (default the range of the data). If both \texttt{knots} and
\texttt{Boundary.knots} are supplied, the basis parameters do not
depend on \texttt{x}. Data can extend beyond \texttt{Boundary.knots}
\end{ldescription}
\end{Arguments}
\begin{Value}
a matrix of dimension \texttt{length(x) * df}, where either \texttt{df}
was supplied or if \texttt{knots} were supplied,
\texttt{df = length(knots) + 3 + intercept}.  Attributes are returned
that  correspond to the arguments to \texttt{bs}, and explicitly give
the \texttt{knots}, \texttt{Boundary.knots} etc for use by
\texttt{predict.bs()}.

\texttt{bs()} is based on the function \texttt{spline.des()} written by
Douglas Bates. It generates a basis matrix for representing the family
of piecewise polynomials with the specified interior knots and degree,
evaluated at the values of \texttt{x}. A primary use is in modeling
formulas to directly specify a piecewise polynomial term in a model. 

Beware of making predictions with new \texttt{x} values when \texttt{df}
is used as an argument. Either use \texttt{safe.predict.gam()}, or else
specify \texttt{knots} and \texttt{Boundary.knots}.\end{Value}
\begin{SeeAlso}
\texttt{ns}, \texttt{poly}, \texttt{lo}, \texttt{s}, \texttt{smooth.spline},
\texttt{predict.bs}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
lm(y ~ bs(age, 4) + bs(income, 4)) # an additive model 
fit <- lm(y ~ bs(age, knots=c(20,30), B=c(0,100)))
predict(fit, new.age) #safe predictions because explicit knot sequence was supplied.
\end{ExampleCode}
\end{Examples}

