I'm trying to fit and plot a cubic spline to the Auto data set with mpg
as the response and horsepower as the predictor in R.
However, I'm getting an error that I can't quite make sense of. The error is below the code.
attach(Auto)
View(Auto)
str(Auto)
mpg_lims = range(mpg)
mpg.grid <- seq(mpg_lims[1],mpg_lims[2])
fit <- lm(mpg~bs(horsepower,knots = c(25,50,75)))
summary(fit)
plot(horsepower, mpg, col='grey', xlab = "Horsepower", ylab = "MPG", main = "MPG Vs. Horsepower")
points(mpg.grid,predict(fit,newdata = list(mpg = mpg.grid)), col='green',lwd=2,type = "l")
abline(v = c(25,50,75), lty=2, col='green')
**Warning message:** In predict.lm(fit, newdata = list(mpg = mpg.grid)) : prediction from a rank-deficient fit may be misleading