Transform Coefficients from Orthogonal Polynomial Form
Returns the vector of coefficients for the polynomial in simple form when given the coefficients for the orthogonal form.
poly.transform(polymat, coefs, intercept = TRUE)
an object that is the output of the poly function. In particular, this must have a "coefs" attribute.
a vector of coefficients for the polynomial in orthogonal form.
The order of these must be the coefficient for the intercept
(if intercept is TRUE), and then the coefficients in
the order implied by polymat.
a logical flag. If TRUE (the default), then the coefs
argument is assumed to include the intercept term.
This function works only when poly is given a single
vector with which to form a polynomial.
Use poly because the regression can become
ill-conditioned (hence inaccurate) when the straightforward approach is used.
returns a vector of coefficients for the polynomial in simple form.
That is, the first element is the constant term,
the second element is the coefficient for x,
the third element is the coefficient for x squared, and so on.
Notice that even if intercept is FALSE,
an intercept term is returned by poly.transform().
d <- data.frame(y=1:16, x=log(1:16))
cPoly <- coef(lm(y~poly(x,3), data=d)) # Orthogonal polynomial
coef(lm(y~x+I(x^2)+I(x^3), data=d)) # Naive monomials
poly.transform(poly(d$x,3), cPoly) # Orthogonal -> Naive