I don't understand what's wrong with this code. I'm trying to create a vector with the test MSE values for 5 degrees of polynomial linear function when I am getting this error. It should be quite straightforward, but maybe there's something wrong with the loop itself. I don;t understand why it says it can't find the model. Any help will be appreciated
library(ISLR)
library(boot)
#> Warning: package 'boot' was built under R version 3.5.2
cv_error_5=rep(0,5)
for (i in 1:10) {linear_model=glm(mpg ~ poly(horsepower, i), data=Auto) + cv_error_5[i]=cv.glm(data=Auto, linear_model)$delta[1]}
#> Error in cv.glm(data = Auto, linear_model): object 'linear_model' not found
But it doesn't make sense to "add" these two operations using +, which is causing the error. You can reproduce this if you run the following specific case in a clean R session:
Thanks! When I saw the code in the paper that I was reading it had the + between the two functions, which is the code showing up in the console when being run. When doing it from the script without the +, works beautifully. Thanks again