[R] fitting a distribution using glm
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Wed Mar 8 15:32:11 CET 2006
"Vumani Dlamini" <dvumani at hotmail.com> writes:
> 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. I use
>
> 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, the freq values in that setup are not independent Poisson
variates. For a start, they sum to constant!
Try instead
exp(coef(glm(poisdata~1,family=poisson)))
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list