poly.transform(polymat, coefs, intercept=T)
poly
.
In particular, this must have a
"coefs"
attribute.
intercept
is
TRUE
), and then the coefficients in the order implied
by
polymat
.
TRUE
, then the
coefs
argument is assumed to include
the intercept term also.
intercept=F
, an intercept term is returned by
poly.transform()
.
This function only works when
poly
is given a single vector with which
to form a polynomial.
The reason to use
poly
is that the regression can become ill-conditioned
(hence inaccurate) when the straightforward approach is used.
price <- freeny.x[,"price index"] price.poly <- poly(price, 3) price.reg <- lm(freeny.y ~ price.poly) coef(price.reg) # coefficients for orthogonal form # coefficients for simple form poly.transform(price.poly, coef(price.reg)) # logically the same thing, though computationally inferior coef(lm(freeny.y ~ price + price^2 + price^3))