poly
Compute Orthogonal Polynomials

Description

Returns a matrix of orthonormal polynomials. The matrix represents a basis or a 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) 
## S3 method for class 'poly':
predict(object, newdata, ...) 

Arguments

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

Details

If x is a matrix, it binds with additional matrices in ... and is converted to a data frame, and then its class attribute is stripped.
If the length of ... is 1, and if the length of the first argument in ... is 1, then it is taken to be the degree of the polynomial. Otherwise, this method is returned by calling polym.
If newdata is NULL, poly returns the input object. If the attribute "coef" of object is NULL, a new polynomial does not include the attribute "coef".
Value
returns a matrix with the class attributes "poly" and "matrix", and with the following attributes:
"colnames" The column names. Its value is the 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.
The function polym is used to deal with more vectors or matrices for Polynomial Regression.
References
Chambers, J. M. and Hastie, T .J. (Eds.) 1992. Statistical Models in S. Pacific Grove, CA.: Wadsworth & Brooks/Cole.
Kennedy, W. J. Jr and Gentle, J. E. 1980. Statistical Computing. Marcel Dekker, Ed.
See Also
polym, formula, polyroot, predict.
Examples
poly.old <- poly(1:10, 5)
polym(1:5, runif(5), degree = 3)
poly.new <- predict(poly.old, 1:5)  ## call method predict.poly
Package stats version 6.1.4-13
Package Index