我有
library(ISLR)
attach(Wage)
# Polynomial Regression and Step Functions
fit=lm(wage~poly(age,4),data=Wage)
coef(summary(fit))
fit2=lm(wage~poly(age,4,raw=T),data=Wage)
coef(summary(fit2))
plot(age, wage)
lines(20:350, predict(fit, newdata = data.frame(age=20:350)), lwd=3, col="darkred")
lines(20:350, predict(fit2, newdata = data.frame(age=20:350)), lwd=3, col="darkred")
预测线似乎是相同的,但为什么系数如此不同?你如何在raw=T
和raw=F
中理解它们.
我看到poly(...,raw=T)
产生的系数与~age+I(age^2)+I(age^3)+I(age^4)
匹配.
如果我想使用系数"手动"(不使用predict()
函数)获得预测,有什么我应该注意的吗?如何解释poly()
中正交多项式的系数.