6

glm() of the following data gives intercept 0.56916 and slope x .018. But the true slope should be 1/10. Does anybody know why glm() can not recover the true slope? Thanks.

R> tmp = data.frame(x=seq_len(100), y=rpois(100, lambda=seq_len(100)/10))
R> fit = glm(y ~ x, family=poisson, data=tmp)
R> fit

Call:  glm(formula = y ~ x, family = poisson, data = tmp)

Coefficients:
(Intercept)            x  
    0.56916      0.01812  

Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
Null Deviance:      252.6 
Residual Deviance: 125.1    AIC: 442.3
R> library(ggplot2)
R> p=qplot(tmp$x, predict(fit))
R> ggsave(p, file='/tmp/glm_poisson_fit.png')
Saving 7 x 7 in image
R> 
  • Try the identity link (you might need to supply start values). – Glen_b Apr 13 '20 at 06:37
  • @meriops this comment is confusing. Neither the example assume “different means”, nor GLM estimates “single mean”. In both cases we are talking about conditional mean being a function of X. – Tim Apr 13 '20 at 09:14