cubicspline Error in xy.coords(x, y) : 'x' and 'y' lengths differ

Hi: I have some problems with editing the plot of the splines model. I write the code.
Thanks in advance for your help
Jesús

modspline <- lm(horsepower~ bs(mpg,knots=c(10,20,30),degree=3),data=Auto)
summary(modspline
library(splines)
spline_fit <- lm(Auto$horsepower ~ bs(Auto$mpg,knots=c(10,20,30
)))

rango <- range(Auto$mpg)
npuntos <- seq(from = rango[1], to = rango[2], by = 0.5)
npuntos <- data.frame(mpg=npuntos)
npredic <- predict(spline_fit,newdata = npuntos, se.fit = TRUE, level = 0.95)
head(npredic)

intconf <- data.frame(
inferior = npredic$fit - 1.96npredic$se.fit,
superior = npredic$fit + 1.96
npredic$se.fit)

plot(x = Auto$mpg, y =Auto$horsepower, pch = 20, col = "red")
title("Spline cúbica, nodos: 10, 20, 30")
lines(x = npuntos$mpg, npredic$fit, col = "green", lwd = 2)
lines(x = npuntos$mpg, intconf$inferior, col = "blue",
lwd = 2, lty = 2)
lines(x = npuntos$mpg,intconf$superior, col = "blue",
lwd = 2, lty = 2)

Error in xy.coords(x, y) : 'x' and 'y' lengths differ
(the length or mpg and horsepower are equal)

If you provide a reprex. See the FAQ, an answer is more likely since no search will need be made for bs() and Auto.

I have solved my mistake
Thanks

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.