Offsets in predict.glm(), given that the fitted poisson model already considered offsets – R

I want to predict a fitted poisson glm on newdata, given that it was fitted using offset=log(Exposure), but I get confused with the inclusion of the term “offset” inside of predict.glm(). I do not understand if it is necessary to include it and, if I want to include it, how should I do that with an equal impact as the offset used in fitting?

To clear my doubts, I created a dataset from scratch and I decided to compare three possible approaches:

  • predict(glm.model, data=newdata, type=”response”, offset=log(Exposure));
  • predict(glm.model, data=newdata, type=”response”, offset=Exposure);
  • predict(glm.model, data=newdata, type=”response”);

However, when comparing the results, I was surprised to find all three approaches resulted in the same predictions. Conclusion: offset term in predict.glm() is ignored? I still ask this, because I am a new to R and my procedure to check it may be wrong.

Also, even though similar questions may have been posted, answers are scarce and inconsistent with this result.

set.seed(1)
exp<-c(1:100)/100
dummy<-rep(c(0,1), each=50)
y<-floor(rpois(100,dummy*exp*10)) #count data
DTtest<-as.data.frame(exp)
DTtest$D<-dummy
DTtest$y<-y
gtest<-glm(y~D, offset=log(exp), family=poisson(link="log"), data=DTtest, trace=TRUE)
DTtest1<-predict(gtest, newdata=DTtest, type="response", offset=log(exp)) #predict1
DTtest2<-predict(gtest, newdata=DTtest, type="response", offset=exp) #predict2
DTtest3<-predict(gtest, newdata=DTtest, type="response") #predict3
sum(DTtest1==DTtest2)
sum(DTtest2==DTtest3)
sum(DTtest1==DTtest3)

As a result for the sums I got: 100, 100, 100, which is equal to the length of the data used to predict (I also used DTtest as newdata). This means all predictions have the same value between the 3 approaches.

I was expecting the values to differ due to different impact of the offset explicit in predict(), but the result says otherwise.

Yes, offset is ignored.

The help package for ?predict.glm says only:

...: further arguments passed to or from other methods.

This is not very helpful. However, if we look at the code for predict.glm we don’t see ... used anywhere (it would be passed to another function). (If you insist on a code-based solution, we can search like this:

any(grepl("...", deparse(body(stats:::predict.glm)), fixed = TRUE))
## FALSE

If you wanted to predict with other values of the offset you would set up a newdata data frame with different values of exp. (By the way, it’s probably a bad idea to use exp as a variable name since it’s the same as the name of the built-in exponential function … most of the time you can get away with this but occasionally it will cause confusing errors.)

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật