我正在使用ISLR的自动数据,而我所做的只是对mpg的简单回归。但是,当我使用poly()函数时,会得到较大的系数结果。
library(ISLR)
Auto = Auto
attach(Auto)
set.seed(1)
train = sample(392, 196)
lm.fit = lm(mpg~horsepower, data = Auto, subset = train)
lm.fit2 = lm(mpg~horsepower + I(horsepower^2), data = Auto, subset = train)
lm.fit3 = lm(mpg~poly(horsepower,2), data = Auto, subset = train)