\HeaderA{poly}{Compute Orthogonal Polynomials}{poly}
\aliasA{makepredictcall.poly}{poly}{makepredictcall.poly}
\aliasA{polym}{poly}{polym}
\aliasA{predict.poly}{poly}{predict.poly}
\keyword{math}{poly}
\begin{Description}\relax
Returns or evaluates orthogonal polynomials of degree 1 to
\code{degree} over the specified set of points \code{x}. These are all
orthogonal to the constant polynomial of degree 0.
\end{Description}
\begin{Usage}
\begin{verbatim}
poly(x, ..., degree = 1, coefs = NULL)
polym(..., degree = 1)

## S3 method for class 'poly':
predict(object, newdata, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, newdata}] a numeric vector at which to evaluate the
polynomial. \code{x} can also be a matrix.  Missing values are not
allowed in \code{x}.
\item[\code{degree}] the degree of the polynomial
\item[\code{coefs}] for prediction, coefficients from a previous fit.
\item[\code{object}] an object inheriting from class \code{"poly"}, normally
the result of a call to \code{poly} with a single vector argument.
\item[\code{...}] \code{poly, polym}: further vectors.\\
\code{predict.poly}: arguments to be passed to or from other methods.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Although formally \code{degree} should be named (as it follows
\code{...}), an unnamed second argument of length 1 will be
interpreted as the degree.

The orthogonal polynomial is summarized by the coefficients, which can
be used to evaluate it via the three-term recursion given in Kennedy
\& Gentle (1980, pp. 343-4), and used in the \dQuote{predict} part of
the code.
\end{Details}
\begin{Value}
For \code{poly} with a single vector argument:\\
A matrix with rows corresponding to points in \code{x} and columns
corresponding to the degree, with attributes \code{"degree"} specifying
the degrees of the columns and \code{"coefs"} which contains the
centering and normalization constants used in constructing the
orthogonal polynomials.  The matrix has given class
\code{c("poly", "matrix")}.

Other cases of \code{poly} and \code{polym}, and \code{predict.poly}:
a matrix.
\end{Value}
\begin{Note}\relax
This routine is intended for statistical purposes such as
\code{contr.poly}: it does not attempt to orthogonalize to
machine accuracy.
\end{Note}
\begin{References}\relax
Chambers, J. M. and Hastie, T. J. (1992)
\emph{Statistical Models in S}.
Wadsworth \& Brooks/Cole.

Kennedy, W. J. Jr and Gentle, J. E. (1980)
\emph{Statistical Computing} Marcel Dekker.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{contr.poly}{contr.poly}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
(z <- poly(1:10, 3))
predict(z, seq(2, 4, 0.5))
poly(seq(4, 6, 0.5), 3, coefs = attr(z, "coefs"))

polym(1:4, c(1, 4:6), degree=3) # or just poly()
poly(cbind(1:4, c(1, 4:6)), degree=3)
\end{ExampleCode}
\end{Examples}

