\HeaderA{makepredictcall}{Utility Function for Safe Prediction}{makepredictcall}
\methaliasA{makepredictcall.default}{makepredictcall}{makepredictcall.default}
\aliasA{SafePrediction}{makepredictcall}{SafePrediction}
\keyword{models}{makepredictcall}
\begin{Description}\relax
A utility to help \code{\LinkA{model.frame.default}{model.frame.default}} create the right
matrices when predicting from models with terms like \code{poly} or
\code{ns}.
\end{Description}
\begin{Usage}
\begin{verbatim}
makepredictcall(var, call)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{var}] A variable.
\item[\code{call}] The term in the formula, as a call.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This is a generic function with methods for \code{poly}, \code{bs} and
\code{ns}: the default method handles \code{scale}.  If
\code{model.frame.default} encounters such a term when
creating a model frame, it modifies the \code{predvars} attribute of
the terms supplied to replace the term with one that will work for
predicting new data.  For example \code{makepredictcall.ns} adds
arguments for the knots and intercept.

To make use of this, have your model-fitting function return the
\code{terms} attribute of the model frame, or copy the \code{predvars}
attribute of the \code{terms} attribute of the model frame to your
\code{terms} object.

To extend this, make sure the term creates variables with a class,
and write a suitable method for that class.
\end{Details}
\begin{Value}
A replacement for \code{call} for the \code{predvars} attribute of
the terms.
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{model.frame}{model.frame}}, \code{\LinkA{poly}{poly}}, \code{\LinkA{scale}{scale}};
\code{\LinkA{bs}{bs}} and \code{\LinkA{ns}{ns}} in package
\pkg{splines}, \code{\LinkA{cars}{cars}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
require(graphics)

## using poly: this did not work in R < 1.5.0
fm <- lm(weight ~ poly(height, 2), data = women)
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
ht <- seq(57, 73, len = 200)
lines(ht, predict(fm, data.frame(height=ht)))

## see also example(cars)

## see bs and ns for spline examples.
\end{ExampleCode}
\end{Examples}

