Plot logistic regression curve in R

后端 未结 1 933
面向向阳花
面向向阳花 2020-12-30 07:26

I want to plot a logistic regression curve of my data, but whenever I try to my plot produces multiple curves. Here\'s a picture of my last attempt:

last attempt

相关标签:
1条回答
  • 2020-12-30 07:47
    fit = glm(vs ~ hp, data=mtcars, family=binomial)
    newdat <- data.frame(hp=seq(min(mtcars$hp), max(mtcars$hp),len=100))
    newdat$vs = predict(fit, newdata=newdat, type="response")
    plot(vs~hp, data=mtcars, col="red4")
    lines(vs ~ hp, newdat, col="green4", lwd=2)
    

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