1

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
M--
  • 25,431
  • 8
  • 61
  • 93
Sam
  • 97
  • 8
  • 5
    Duplicate of [predict.lm() in a loop. warning: prediction from a rank-deficient fit may be misleading](https://stackoverflow.com/questions/26558631/predict-lm-in-a-loop-warning-prediction-from-a-rank-deficient-fit-may-be-mis) – M-- Oct 23 '19 at 18:51
  • https://stackoverflow.com/questions/40774922/how-to-solve-rank-deficient-fit-may-be-misleading-error-on-my-linear-model – M-- Oct 23 '19 at 18:51
  • https://stats.stackexchange.com/questions/35071/what-is-rank-deficiency-and-how-to-deal-with-it – M-- Oct 23 '19 at 18:52
  • This is not an error though. It's a warning. Links I provided above answer your question. Here, https://www.dummies.com/programming/r/how-to-read-errors-and-warnings-in-r/ you can learn about warnings and errors and also this one https://www.dummies.com/programming/r/how-to-know-when-to-care-about-warnings-in-r/ tells when to care about warnings. – M-- Oct 23 '19 at 18:55

0 Answers0