[R] fitting a distribution using glm

Thomas Lumley tlumley at u.washington.edu
Wed Mar 8 16:02:46 CET 2006


On Wed, 8 Mar 2006, Vumani Dlamini wrote:

> it is easy to fit a distribution using fitdistr
>
> poisdata <- rpois(n = 100, lambda = 2)
> poismle <- fitdistr(poisdata, "Poisson")
> poismle
>
> but i would like to know whether its possible to get an identical result
> using glm.

Yes. Easy.

  glm(poisdata ~ 1, family = poisson)

>
> poistab <- data.frame(table(poisdata))
> colnames(poistab) <- c("width","freq");
> poistab[,"width"] <- as.numeric(poistab[,"width"])
> glm(freq ~ 1-width, family = poisson, data = poistab)
>
> but the results are always different.

Well, they would be.  I don't know what this is doing, but it certainly 
isn't fitting a poisson distribution to poisdata.

 	-thomas




More information about the R-help mailing list