Skip to Content

poly {stats}

Compute Orthogonal Polynomials
R 3.0.2


Returns or evaluates orthogonal polynomials of degree 1 to degree over the specified set of points x. These are all orthogonal to the constant polynomial of degree 0. Alternatively, evaluate raw polynomials.


poly(x, ..., degree = 1, coefs = NULL, raw = FALSE)
polym(..., degree = 1, raw = FALSE)
## S3 method for class 'poly':
predict((object, newdata, ...))


x, newdata
a numeric vector at which to evaluate the polynomial. x can also be a matrix. Missing values are not allowed in x.
the degree of the polynomial. Must be less than the number of unique points if raw = TRUE.
for prediction, coefficients from a previous fit.
if true, use raw and not orthogonal polynomials.
an object inheriting from class "poly", normally the result of a call to poly with a single vector argument.
poly, polym: further vectors.
predict.poly: arguments to be passed to or from other methods.


Although formally degree should be named (as it follows ...), 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 predict part of the code.


For poly with a single vector argument:
A matrix with rows corresponding to points in x and columns corresponding to the degree, with attributes "degree" specifying the degrees of the columns and (unless raw = TRUE) "coefs" which contains the centering and normalization constants used in constructing the orthogonal polynomials. The matrix has given class c("poly", "matrix").

Other cases of poly and polym, and predict.poly: a matrix.


Chambers, J. M. and Hastie, T. J. (1992) Statistical Models in S. Wadsworth & Brooks/Cole.

Kennedy, W. J. Jr and Gentle, J. E. (1980) Statistical Computing Marcel Dekker.


This routine is intended for statistical purposes such as contr.poly: it does not attempt to orthogonalize to machine accuracy.

See Also


cars for an example of polynomial regression.


od <- options(digits = 3) # avoid too much visual clutter
(z <- poly(1:10, 3))
predict(z, seq(2, 4, 0.5))
zapsmall(poly(seq(4, 6, 0.5), 3, coefs = attr(z, "coefs")))
zapsmall(polym(1:4, c(1, 4:6), degree = 3)) # or just poly()
zapsmall(poly(cbind(1:4, c(1, 4:6)), degree = 3))

Documentation reproduced from R 3.0.2. License: GPL-2.