Say I have this data:
n = 1e3
x = rnorm(n)
linear_process = 1 + 5*x
y = rbinom(n = n, size = 1, prob = plogis(linear_process))
plot(x,y)
I fit a GLM and make predictions:
m = glm(y~x, family = binomial(link = 'logit'))
y_hat = predict(m, type = 'response')
and when I plot y_hat
as points I get what I expected:
plot(x,y)
points(x,y_hat, col = 'blue')
but when I plot the predicted probabilities as a line I get this weird thing:
plot(x,y)
lines(x,y_hat, col = 'blue')
Am I doing something wrong with predict
? or plot
?