I've done simple polynomial regression. By some reason, this is the plot I'm getting:
This is my code:
mod = lm(D$Life.expectancy ~ poly(D$Adult.Mortality, 2))
summary(mod)
x4 = seq(min(D$Adult.Mortality), max(D$Adult.Mortality),
length.out=length(D$Adult.Mortality))
y4 = predict(mod, data.frame(x4), interval = "confidence")
plot(D[,5], D[,4], col = as.factor(D$Status), pch = 16,
ylab = "Life expectancy", xlab = "Adult mortality")
lines(x4, y4[,1], col = "blue", lwd = 3)
What's wrong with my code? Why am I getting such a weird graph? Also, is there a better way to graph the model? I feel that my code is not the best, by some reason.