I am trying to fit a glm line with geom_smooth but the fitting does not seem correct. I get a very straight line. I would expect a slight curve to the line of fit, since I am using 'generalized linear model' and not linear.
Here is how my data structure looks like:
$ treatment : int -20 -20 -40 -60 -60 -60 0 -100 -100 -40 ...
$ response : int 267 253 254 253 257 242 250 274 295 255 ...
$ early_late : Factor w/ 2 levels "early","late": 2 2 2 2 2 2 2 2 2 2 ...
And my code:
ggplot() +
geom_point(data = data, mapping = aes(x= treatment, y= response, color=early_late, fill = early_late), shape = 21, size = 2.5, alpha = 0.15) +
scale_y_continuous(breaks=seq(120,320, 40), limits=c(120, 320)) +
labs(x= "treatment",
y = "response (count)") +
geom_smooth(data = data, mapping = aes(x= treatment, y= response, color = early_late), method = "glm", method.args = list(family= poisson), formula = y ~ x, se = T)
Any insights on this will be very appreciated!