I was plotting the results of a logistic regression, but instead of the expected S curve, I got a straight line like this:
This was the code that I was using:
I created a range of data from the original x-axis, converted it to data frame, and then predicted and drew the lines.
model = glm(SHOT_RESULT~SHOT_DISTANCE,family='binomial',data = df_2shot)
#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,r,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")
Haha, I see what happened. It is because of the range you plot. I saw the functional form of the curve from your comment line, and I define it as a function:
f <- function (x) 1 / (1 + exp(-0.306 + 0.0586 * x))
Now, if we plot
x <- -100 : 100 plot(x, f(x), type = "l")
Logistic curve has a near linear shape in the middle. That is what you arrived at!