Generate a Basis for Polynomial Regression

DESCRIPTION:

Returns a matrix of orthonormal polynomials, which represents a basis for polynomial regression.

USAGE:

poly(x, ...) 

REQUIRED ARGUMENTS:

x
numeric vector or matrix.

OPTIONAL ARGUMENTS:

...
additional vectors or matrices may be given. If the final argument is a single number, it is taken to be the degree of the polynomial. The default degree is 1.

VALUE:

a matrix of orthonormal polynomials; the constant column is excluded. The matrix has an attribute degree that is a vector giving the degree of each column. When called with a single vector argument, there is an additional attribute coefs, which is a list with component names alpha and norm2.

DETAILS:

The orthogonality of the polynomial is with respect to the data. For several arguments (vector, matrix, or both), each of the column vectors is used to generate orthogonal polynomials of the required degree. The columns will be a subset of the tensor product of the orthogonal polynomials of given degree of each for the individual variables.

The actual construction of the orthogonal basis is performed by the poly.raw function. You can supply a coefs argument to the poly function that is used by poly.raw to determine the normalization constants used in constructing the orthogonal polynomials. The coefs argument is used by poly.raw in the following manner:

Let the jth column of the output represent a polynomial P(j), and define P(-1)=0 and P(0)=1. Then the orthogonal basis for the polynomials can be generated using the formula



P(j+1) = (x - alpha[j+1]) * P(j) - norm2[j+2]/norm2[j+1] * P(j-1).



The actual basis for the polynomials returned by poly.raw is the P(j) columns above scaled by their norms. See the poly.raw help file for information on how these can be used to construct additional evaluations of the same polynomial basis.

The poly.transform function is used to transform coefficients for an orthogonal polynomial into coeffiecients for a standard polynomial representation. For example, the coefficient estimates from a statistical model can be supplied, along with the orthogonal polynomial, to the poly.transform function to obtain the coefficient estimates for a standard polynomial representation. See the help file for poly.transform for more information on the use of this function.

SEE ALSO:

, , , , , .

EXAMPLES:

poly(freeny.y, 3) 
poly(freeny.y, freeny.x) 
poly(freeny.y, freeny.x, 2) 
glm(Kyphosis ~ poly(Age, 3) + Start, family=binomial, data=kyphosis) 
lm(NOx ~ poly(C, E, 4), data=ethanol)