You've got it right. Just multiply the predicted values by the exposure time
or number of cases and that will get you what you want. Note that, depending on
the scale of the predictions, you might want to do all the predictions and
+log(offset) on the log scale and then exponentiate it. Should be more stable
numerically.
Greg
________________________________________
From: Markus Loecher [mailto:markus.loecher at gmail.com]
Sent: Tuesday, September 21, 2010 11:15 AM
To: r-help at r-project.org
Cc: Ridgeway, Greg
Subject: package gbm, predict.gbm with offset
Dear all,
the help file for predict.gbm? states that "The predictions from gbm do not
include the offset term. The user may add the value of the offset to the
predicted value if desired." I am just not sure how exactly, especially for
a Poisson model, where I believe the offset is multiplicative ?
For example:
library(MASS)
fit1 <- glm(Claims ~ District + Group + Age + offset(log(Holders)),
??? data = Insurance, family = poisson)
head(predict(fit1, data = Insurance, type = "response"))
#glm.predict includes the offset:
head(predict(fit1, newdata = Insurance, type = "response"))
#??????? 1???????? 2???????? 3???????? 4???????? 5???????? 6
# 31.86358? 35.27587? 28.18080 158.87829? 53.97772? 84.16012
library(gbm)
fit2 <- gbm(Claims ~ District + Group + Age + offset(log(Holders)),
??? data = Insurance, distribution ="poisson", n.trees = 600)
head(predict(fit2, newdata = Insurance, type = "response",
n.trees=600))
#[1] 0.1378249 0.1378249 0.1314991 0.1284441 0.1389563 0.1389563
#Warning message:
#In predict.gbm(fit2, newdata = Insurance, type = "response", n.trees
= 600) :
#? predict.gbm does not add the offset to the predicted values.
Would the answer be simple multiplication such as:
head(predict(fit2, newdata = Insurance, type = "response",
n.trees=600)*Insurance[,"Holders"])
[1]? 27.15151? 36.38577? 32.34878 215.78607? 39.46359? 74.48058
Any help would be immensely useful.
Thx,
Markus
__________________________________________________________________________
This email message is for the sole use of the intended r...{{dropped:6}}