[R] glm: quasi models with logit link function and binary data
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Mon Nov 28 13:20:16 CET 2005
Björn Stollenwerk wrote:
> # Hello R Users,
> #
> # I would like to fit a glm model with quasi family and
> # logistical link function, but this does not seam to work
> # with binary data.
> #
> # Please don't suggest to use the quasibinomial family. This
> # works out, but when applied to the true data, the
> # variance function does not seams to be
> # appropriate.
> #
> # I couldn't see in the
> # theory why this does not work.
> # Is this a bug, or are there theoretical reasons?
> # One problem might be, that logit(0)=-Inf and logit(1)=Inf.
> # But I can't see how this disturbes the calculation of quasi-Likelihood.
> #
> # Thank you very much,
> # best,
> #
> # Björn
>
> set.seed(0)
> y <- sample(c(0,1), size=100, replace=T)
>
> # the following models work:
> glm(y ~ 1)
> glm(y ~ 1, family=binomial(link=logit))
> glm(y ~ 1, family=quasibinomial(link=logit))
>
> # the next model doesn't work:
> glm(y ~ 1, family=quasi(link=logit))
>
This is an issue with the starting values provided to glm. Take a look
at the difference between:
quasibinomial()$initialize
and
quasi("logit")$initialize
and where this is used in glm.fit and you should see the why the error
occurs. To avoid this, you can supply your own starting values from a
call to glm
mustart <- predict(glm(y ~ 1, binomial), type = "response")
glm(y ~ 1, quasi("logit"), mustart = mustart)
or just use:
glm(y ~ 1, quasi("logit"), mustart = rep(0.5, length(y)))
HTH,
--sundar
More information about the R-help
mailing list