[R] glm with binomial errors in R and GLIM

Prof Brian D Ripley ripley at stats.ox.ac.uk
Fri Mar 1 18:17:16 CET 2002


On Fri, 1 Mar 2002, Ronaldo Reis Jr. wrote:

> In my continuous transition of GLIM to R I try to make a glm with binomial
> errors.
>
> The data file have 3 vectors:
> h -> the factor that is ajusted (have 3 levels)
> d -> number of animais alive (the response)
> n -> total number of animals
>
> To test proportion of alive, make d/n.
>
> In GLIM:
>
> $yvar d$
>
> $error binomial n$
>
> $fit +h$
>
> scale deviance = 25.730 (change = -9.138) at cycle 4
>           d.f. = 15     (change = -2)
>
> factor h is significant by chisq² with 2df fron tables = 5.99
>
> $disp e$
>
>    estimate  se       parameter
> 1  -0.1054   0.2055   1
> 2   0.7985   0.2961   h(2)
> 3   0.08827  0.26764  h(3)
> Scale parameter taken as 1.000
>
> In R:
>
> > modelo.glex24.1 <- glm((d/n)~h,family=binomial)
> Warning message:
> non-integer #successes in a binomial glm! in: eval(expr, envir, enclos)

Please don't ignore warnings.

> > summary(modelo.glex24.1)
>
> Call:
> glm(formula = (d/n) ~ h, family = binomial)
>
> Deviance Residuals:
>      Min        1Q    Median        3Q       Max
> -0.66227  -0.09918  -0.06041   0.18103   0.64740
>
> Coefficients:
>             Estimate Std. Error z value Pr(>|z|)
> (Intercept) -0.06119    0.81688  -0.075    0.940
> h2h          0.57994    1.17433   0.494    0.621
> h3h          0.07761    1.15499   0.067    0.946
>
> (Dispersion parameter for binomial family taken to be 1)
>
>     Null deviance: 2.0737  on 17  degrees of freedom
> Residual deviance: 1.7843  on 15  degrees of freedom
> AIC: 31.147
>
> Number of Fisher Scoring iterations: 2
>
> > anova.glm(modelo.glex24.1,test="Chisq")
> Analysis of Deviance Table
>
> Model: binomial, link: logit
>
> Response: (d/n)
>
> Terms added sequentially (first to last)
>
>
>      Df Deviance Resid. Df Resid. Dev P(>|Chi|)
> NULL                    17    2.07368
> h     2  0.28935        15    1.78433   0.86530
> >
>
> The values calculate by GLIM and R is very different, in GLIM h is
> significant and in R no.
>
> What is my error????

You forgot the weights, the analogue of `binomial n'.  You want either

glm(cbind(d, n-d) ~ h, family = binomial)

or

glm(d/n ~ h, weights = n, family = binomial)


This is discussed in lots of places in the R literature, too many for me to
point you to them all, but Venables & Ripley springs to mind ....

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list