[R] glm with family binomial and link identity

Ralf Goertz r_goertz @end|ng |rom web@de
Thu Apr 28 09:53:39 CEST 2022


> Am Wed, 27 Apr 2022 10:27:33 +0200 schrieb Ralf Goertz
> 
> > Hi,
> >
> > I just noticed that (with my version 4.2.0) it is no longer possible
> > to use glm with family=binomial(link=identity). Why is that? It was
> > possible with 4.0.x as a colleague of mine just confirmed. After all
> > it is useful to compute risk differences with factors.  
> 
> Sorry about the noise. It still works with "identity" but it has to be
> quoted (whereas "log" and "logit" also work unquoted).

On the other hand why do I get this following error at all?

Error in binomial(link = identity) : 
  link "identity" not available for binomial family; available links are ‘logit’, ‘probit’, ‘cloglog’, ‘cauchit’, ‘log’

This is a bit misleading since identity is a legitimate link function
and works perfectly when quoted. The results of that call are in
agreement with what you get with the risk difference approach (for
convenience computed using the meta package)

> d=data.frame(y=c(0, 1, 0, 1), trt=c(0, 0, 1, 1), w=c(97, 3, 90, 10))
> d
  y trt  w
1 0   0 97
2 1   0  3
3 0   1 90
4 1   1 10

> res=glm(y~trt,data=d,weights=w,family=binomial(link="identity"))
> summary(res)

Call: glm(formula = y ~ trt, family = binomial(link = "identity"), data
= dd, weights = w)

Deviance Residuals: 
     1       2       3       4  
-2.431   4.587  -4.355   6.786  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)  
(Intercept)  0.03000    0.01706   1.759   0.0786 .
trt          0.07000    0.03451   2.028   0.0425 *
…

> confint.default(res)[2,]
      2.5 %      97.5 % 
0.002359942 0.137640058 

This is exactly the same as 

> meta::metabin(10,100,3,100,sm="RD")
Number of observations: o = 200
Number of events: e = 13

     RD           95%-CI    z p-value
 0.0700 [0.0024; 0.1376] 2.03  0.0425

So why the error?



More information about the R-help mailing list