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:
a 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 for the polynomial 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. The coefs attribute 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 of the individual variables.

The coefs attribute contains the normalization constants used in constructing the orthogonal polynomials. See poly.raw for information on how these can be used to construct additional evaluations of the same polynomial basis.

We now describe the meaning of coefs. The jth column of the output represents a polynomial P(j). Define P(-1) = 0, and P(0) = 1. Then P(j+1) = (x - alpha[j+1]) * P(j) - norm2[j+2]/norm2[j+1] * P(j-1). Finally, the columns (polynomials) are scaled by their norms.


SEE ALSO:
poly.raw , bs , ns , formula , polyroot .

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)