[S] predict.glm for binomial family with log link

ballr@rimu.fri.cri.nz
Fri, 3 Jul 1998 12:32:34 +1200


I have been fitting some data using glm with binomial family and log link.

> predict(...type="response")

appears to be using the wrong link function:-

> version
Version 3.4 Release 1 for Silicon Graphics Iris, IRIX 5.3 : 1996

> test.fit <- glm(y==0 ~ x - 1,family=binomial(link=log),data=a)
> summary(test.fit,disp=0)

Call: glm(formula = y == 0 ~ x - 1, family = binomial(link = log), data =
a)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.17741 -0.5894189 1.17741 1.226762 1.509146

Coefficients:
Value Std. Error t value
x -0.716061 0.3987636 -1.795703

(Dispersion Parameter for Binomial family taken to be 0.9623867 )

Null Deviance: 55.45177 on 40 degrees of freedom

Residual Deviance: 50.51698 on 39 degrees of freedom

Number of Fisher Scoring Iterations: 4
> # predict seems to be using the logit link function here
> # should be 1
> predict(test.fit,newdata=list(x=0),type="response")
1
0.5

> exp(predict(test.fit,newdata=list(x=0)))
1
1

> # try a few more points
> predict(test.fit,newdata=list(x=c(-1,0,1)),type="response") # wrong
1 2 3
0.671739 0.5 0.328261

> # un-backtransform using logit(), get same answer as predictions on log
scale
> logit(predict(test.fit,newdata=list(x=c(-1,0,1)),type="response"))
1 2 3
0.716061 0 -0.716061
> # predictions on log scale
> predict(test.fit,newdata=list(x=c(-1,0,1)),type="link")
1 2 3
0.716061 0 -0.716061

Rod Ball

Dr Roderick D. Ball Ph 64-7-3475899
Statistician, Fx 64-7-3479380
New Zealand Forest Research Institute email: ballr@fri.cri.nz
P.B. 3020, Rotorua, New Zealand

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news