mlr_mod<-lm(y ~ x+x^2)
summary(mlr_mod)
##
## Call:
## lm(formula = y ~ x + x^2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.108 -1.393 0.748 1.490 3.776
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.8270 0.2431 -7.514 2.72e-11 ***
## x 1.4349 0.2569 5.585 2.09e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.406 on 98 degrees of freedom
## Multiple R-squared: 0.2415, Adjusted R-squared: 0.2337
## F-statistic: 31.2 on 1 and 98 DF, p-value: 2.09e-07
plot(x,y)

library(boot)
xy<-data.frame(x, y)
cv.error<-rep(0, 4)
for(i in 1:4){
glm.fit<-glm(y~poly(x, i))
cv.error[i]<-cv.glm(xy, glm.fit)$delta[1]
}
cv.error
## [1] 6.178719 0.982515 1.004089 1.025716
cvDF<-data.frame(degree=1:4, cv.error)