poly
Compute Orthogonal Polynomials

Description

Returns a matrix of orthonormal polynomials, which represents a basis or multiply for polynomial regression. predict.poly is used to structure new polynomials with new data.

Usage

poly(x, ..., degree = 1, coefs = NULL, raw = FALSE)
polym(..., degree = 1, raw = FALSE) 
predict.poly(object, newdata, ...) 

Arguments

x numeric vector or matrix. Missing values are not allowed.
degree the degree of the polynomial. The default degree is 1. It must be less than number of unique points when raw is TRUE or coefs is NULL.
coefs coefficients used for prediction.
raw logical flag, if true, use raw and not orthogonal polynomials.
object polynomials, usually the returned value of function poly.
newdata numeric vector or matrix. New data to structure polynomials.
... additional vectors or matrices may be given. In function polym, ... must supply one or more vectors with the same length.

Details

If x is a matrix, it will be bind with additional matrices in ... and converted to be a data frame, then its class attribute will be stripped.
If the length of ... is 1 and the length of the first argument in it is 1, it is taken to be the degree of the polynomial. Otherwise this method is returned by calling polym.
If newdata is NULL, return the input object; if attribute "coef" of object is NULL, new polynomial will also not include attribute "coef".
Value
a matrix with class attributes "poly" and "matrix", and with the following attributes:
"colnames": the column names, its value is a vector 1L:degree.
"degree": the degrees of the columns.
"coefs": the centering and normalization constants used in constructing the orthogonal polynomials, this attribute is not provided when raw is TRUE.
Function polym is used to deal with more vector or matrix for Polynomial Regression.
References
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.
See Also
polym, formula, polyroot.
Examples
poly.old <- poly(1:10, 5)
polym(1:5, runif(5), degree = 3)
poly.new <- predict.poly(poly.old, 1:5)
Package stats version 4.0.0-28
Package Index