2
$\begingroup$

I have understood that one commonly adds log(exposure) as an offset in the formula for GLMs, when dealing with poisson distributed rate data. I am dealing with insurance claim data where I want to predict the frequency i.e. #Claims/Exposure using a regression tree in R. My question is whether it is reasonable to add an log(exposure) offset here aswell? See code below for an example of what I would like to do.

CODE

tree <- rpart ( claims ~ age + ac + power + gas + brand + area + dens + ct
+ offset ( log ( expo )) ,
data = dat , method =" poisson ", parms = list ( shrink =1) ,
control = rpart . control ( xval =10 , minbucket =10000 , cp =0.001))
$\endgroup$

1 Answer 1

1
$\begingroup$

You can check out section 8 of the rpart vignette, and they write:

The y variable for Poisson partitioning may be a two column
matrix containing the observation time in column 1 and the number of events in column 2

So we can try that for an example:

library(rpart)
library(rpart.plot)

dat = MASS::Insurance
mdl = rpart(as.matrix(dat[,c("Holders","Claims")]) ~ District + Group + Age,data=dat,method="poisson")
rpart.plot(mdl)

enter image description here

And we can check the fit versus the rate:

plot(predict(fit),dat$Claims/dat$Holders)

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.