我正在绘制逻辑回归的结果,但不是预期的S曲线,我得到了这样的直线:
这是我正在使用的代码:
我从原始x轴创建了一系列数据,将其转换为数据框,然后预测并绘制线条。
model = glm(SHOT_RESULT~SHOT_DISTANCE,family='binomial',data = df_2shot)
summary(model)
#Eqn : P(SHOT_RESULT = True) = 1 / (1 + e^-(0.306 - 0.0586(SHOT_DISTANCE)))
r = range(df_2shot$SHOT_DISTANCE) # draws a curve based on prediction
x_range = seq(r[1],r[2],1)
x_range = as.integer(x_range)
y = predict(model,data.frame(SHOT_DISTANCE = x_range),type="response")
plot(df_2shot$SHOT_DISTANCE, df_2shot$SHOT_RESULT, pch = 16,
xlab = "SHOT DISTANCE", ylab = "SHOT RESULT")
lines(x_range,y)
旁注:我正在学习本教程:http://www.theanalysisfactor.com/r-glm-plotting/
任何见解都将不胜感激!谢谢! :)