[R] Extract fitted values with and without offset from glm

Chris Beeley chris.beeley at gmail.com
Thu Apr 5 10:00:17 CEST 2012


Hello-

In the notes for the lm function it states " Offsets specified by offset 
will not be included in predictions by predict.lm, whereas those 
specified by an offset term in the formula will be." I would like to 
extract fitted values in just this way from a glm model, those with the 
offset and those without. I have tried doing things like this:

predict.glm(glm(Incident~Numbers, offset=logit(Numbers), 
family=binomial, data=violdata))

predict.glm(glm(Incident~Numbers+offset(logit(Numbers)), 
family=binomial, data=violdata))

As well as like this:

glm(Incident~Numbers, offset=logit(Numbers), family=binomial, 
data=violdata)$fitted.values

glm(Incident~Numbers+offset(logit(Numbers)), family=binomial, 
data=violdata)$fitted.values

But they return the same result. The first 50 lines of my data look like 
this:

structure(list(Incident = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1), Numbers = c(13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L)), .Names = c("Incident",
"Numbers"), row.names = c(NA, 50L), class = "data.frame")


Any assistance gratefully recieved.

Many thanks,
Chris Beeley, Institute of Mental Health, UK



More information about the R-help mailing list