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.
1 2 3 4 5
a numeric vector at which to evaluate the
the degree of the polynomial. Must be less than the
number of unique points when
for prediction, coefficients from a previous fit.
if true, use raw and not orthogonal polynomials.
logical indicating if a simple matrix (with no further
an object inheriting from class
degree should be named (as it follows
...), an unnamed second argument of length 1 will be
interpreted as the degree, such that
poly(x, 3) can be used in
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
... is just a convenience wrapper for
coef is ignored. Conversely, if
called with a single argument in
... it is a wrapper for
coefs=NULL as per default):
A matrix with rows corresponding to points in
x and columns
corresponding to the degree, with attributes
the degrees of the columns and (unless
raw = TRUE)
"coefs" which contains the centering and normalization
constants used in constructing the orthogonal polynomials and
predict.poly(): a matrix.
This routine is intended for statistical purposes such as
contr.poly: it does not attempt to orthogonalize to
R Core Team. Keith Jewell (Campden BRI Group, UK) contributed improvements for correct prediction on subsets.
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.
cars for an example of polynomial regression.
1 2 3 4 5 6 7 8 9 10
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"))) zm <- zapsmall(polym ( 1:4, c(1, 4:6), degree = 3)) # or just poly(): (z1 <- zapsmall(poly(cbind(1:4, c(1, 4:6)), degree = 3))) ## they are the same : stopifnot(all.equal(zm, z1, tol = 1e-15)) options(od)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.