We are working on a project where we want to find the pure premium for which we first want to fit Poisson regression. Data Used: data(dataCars) from insauranceData package in R We have an offset term exposure which takes value between 0 and 1 when I fit my model then I am getting rates between 0 and 1 but when I calculate the original rates to compare my prediction, there are values in 365claims/year (since few observations had claimed within 0.0027 exposure time) So is my interpretation of no of claims using Poisson GLM incorrect or is it wrong to compare the rates calculated using the model and calculated from the original data ? What is the right method to go about it? Please Help
Following are the codes attached:
library(insuranceData)
library(forcats)
library(caret)
data(dataCar)
data1 <- dataCar
#Data Cleaning & Pre-processing
data2 <- unique(data1)
data3 <- data2[data2$veh_value > quantile(data2$veh_value, 0.0001),]
data4 <- data3[data3$veh_value < quantile(data3$veh_value, 0.999), ]
#Regrouping vehicle categories
top9 <- c('SEDAN','HBACK','STNWG','UTE','TRUCK','HDTOP','COUPE','PANVN','MIBUS')
data4$veh_body <- fct_other(data4$veh_body, keep = top9, other_level = 'other')
#Converting catagorical variables into factors
names <- c('veh_body' ,'veh_age','gender','area','agecat')
data4[,names] <- lapply(data4[,names] , factor)
str(data4)
##data partition - original data
data <- data4
data_partition <- createDataPartition(data$numclaims, times = 1,p = 0.8,list = FALSE)
str(data_partition)
training <- data[data_partition,]
testing <- data[-data_partition,]
##data partition - re-sampled data
data <- data4
data_partition <- createDataPartition(data$numclaims, times = 1,p = 0.8,list = FALSE)
str(data_partition)
training <- data[data_partition,]
testing <- data[-data_partition,]
#Number of Claims(Orignal Data)
table(training$numclaims)
ggplot(training,aes(numclaims))+geom_bar(fill="deepskyblue4")+
geom_text(aes(label = ..count..), stat = "count", vjust = -0.3, colour = "black")+
xlab("No of Claims")+
ylab("Count of Claims")+
ggtitle("Histogram of Number of Claims(in given exposure)")+
theme(plot.title = element_text(hjust=0.5))+
theme_update()
#Poisson model with offset
poissonglm <- glm(numclaims ~veh_value+veh_body+veh_age+gender+ area+ agecat+offset(log(exposure)),data=training, family = "poisson")
summary(poissonglm)
predict(poissonglm,newdata=data,type="response")
Our Models Predicts the Rate but since now the exposure term is taken care of,so the Rates are No of claims per year so Rate=No of Claims (here)?
I want my predictions to be in some range of counts (i.e 0 1 2 4) which I can compare with the number of claims in my original data.