\Header{makepredictcall}{Utility Function for Safe Prediction}
\methalias{makepredictcall.default}{makepredictcall}
\alias{SafePrediction}{makepredictcall}
\keyword{models}{makepredictcall}
\begin{Description}\relax
A utility to help \code{\Link{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{\Link{model.frame}}, \code{\Link{poly}}, \code{\Link{scale}},
\code{\Link{bs}}, \code{\Link{ns}}, \code{\Link{cars}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## using poly: this did not work in R < 1.5.0
data(women)
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}

