Messy plot when plotting predictions of a polynomial regression using lm() in R

前端 未结 1 1637
生来不讨喜
生来不讨喜 2020-12-02 03:16

I am building a quadratic model with lm in R:

y <- data[[1]]
x <- data[[2]]
x2 <- x^2

quadratic.model = lm(y ~ x + x2)

Now I wan

相关标签:
1条回答
  • 2020-12-02 03:50

    You need order():

    P <- predict(quadratic.model)
    plot(y~x)
    reorder <- order(x)
    lines(x[reorder], P[reorder])
    

    My answer here is related: Problems displaying LOESS regression line and confidence interval

    0 讨论(0)
提交回复
热议问题