#====================================================== # Illustration of Poisson regression for ungrouped data # Example: Car insurance data #====================================================== # Read data on number of claims for private cars and select the sedans data="http://www.uio.no/studier/emner/matnat/math/STK3100/data/car.txt" car=read.table(data,header=T,sep=",") car0=car[car$veh_body=="SEDAN",c(2,7,8,10,4)] head(car0) # Definition of variables: # exposure: proportion of period insured # veh_age: age of vehicle: 1 (newest), 2, 3, 4 # gender: gender of driver: M, F # agecat: driver's age category: 1 (youngest), 2, 3, 4, 5, 6 # numclaims: number of claims # Summaries of number of claims: table(car0$numclaims) mean(car0$numclaims) var(car0$numclaim) # Fit Poisson GLM with logarithmic link: fit1=glm(numclaims~offset(log(exposure))+factor(veh_age)+gender +factor(agecat), family=poisson,data=car0) summary(fit1) drop1(fit1,test="LRT") # Omit gender: fit2=glm(numclaims~offset(log(exposure))+factor(veh_age) +factor(agecat),family=poisson,data=car0) summary(fit2) drop1(fit2,test="LRT") # Print rate ratios for age groups 2-6 (relative to the youngest) exp(fit2$coef[5:9]) # Print rate ratios for age of vehicle groups 2-4 (relative to the newest) exp(fit2$coef[2:4]) # Prediction for a driver in the oldest age category # who has a new car and has been insured the whole period new.covar=data.frame(exposure=1,veh_age=1,agecat=6) predict(fit2,newdata=new.covar,type="response") # Prediction for a driver in the youngest age category # who has an old car and has been insured the whole period new.covar=data.frame(exposure=1,veh_age=4,agecat=1) predict(fit2,newdata=new.covar,type="response")