{"word_count": 944, "character_count": 7373}
During the course, we have seen that it is natural to assume that not only the individual claims frequency can be explained by some covariates, but individual costs too. Of course, appropriate families should be considered to model the distribution of the cost , given some covariates .Here is the dataset we'll use,&#62;  sinistre=read.table("http://freakonometrics.free.fr/sinistreACT2040.txt",+  header=TRUE,sep=";")&#62;  sinistres=sinistre[sinistre$garantie=="1RC",]&#62;  sinistres=sinistres[sinistres$cout&#62;0,]&#62;  contrat=read.table("http://freakonometrics.free.fr/contractACT2040.txt",+  header=TRUE,sep=";")&#62;  couts=merge(sinistres,contrat)&#62; tail(couts)     nocontrat    no garantie    cout exposition zone puissance agevehicule1919   6104006 11933      1RC 5376.04       0.37    E         6           11920   6107355 12349      1RC   51.63       0.74    E         4           11921   6108364 13229      1RC 1320.00       0.74    B         9           11922   6109171 11567      1RC 1320.00       0.74    B        13           11923   6111208 14161      1RC  970.20       0.49    E        10           51924   6111650 14476      1RC 1940.40       0.48    E         4           0     ageconducteur bonus marque carburant densite region1919            32    57     12         E      93     101920            45    57     12         E      72     101921            32   100     12         E      83      01922            56    50     12         E      93     131923            30    90     12         E      53      21924            69    50     12         E      93     13Here, each line is a claim. Usual families to model the cost are the Gamma distribution, or the inverse Gaussian. Or the lognormal distribution (which is not in the exponential family, but one can assume that the logarithm of the cost can be modeled with a Gaussian distribution). Consider here only one covariate, e.g. the age of the car, and two different models: a Gamma one, and a lognormal one.&#62; age=0:20&#62; reggamma.sp &#60;- glm(cout~agevehicule,family=Gamma(link="log"),+ data=couts)&#62; Pgamma &#60;- predict(reggamma.sp,newdata=data.frame(agevehicule=age),type="response")For the Gamma regression, it is a simple GLM, so it is not difficult. For a lognormal distribution, one should remember that the expected value of a lognormal distribution is not the exponential of the underlying Gaussian distribution. A correction should be made, here to get an unbiased estimator for the average cost,&#62; reglm.sp &#60;- lm(log(cout)~agevehicule,data=baseCOUT)&#62; sigma &#60;- summary(reglm.sp)$sigma&#62; mu &#60;- predict(reglm.sp,newdata=data.frame(agevehicule=age))&#62; Pln &#60;- exp(mu+sigma^2/2)We can plot those two predictions on a single graph,&#62; plot(age,Pgamma,xlab="",ylab="",col="red",type="b",pch=4)&#62; lines(age,Pln,col="blue",type="b")Here it is,Observe that it is also possible to use splines, since there might be no reason for the age to appear here in a multiplicative way,Here, the two models are rather close. Nevertheless, one should remember that the Gamma model can be extremely sensitive to large claims (I mean here really large claims). On the other hand, with the log-transformation for the lognormal model, it seams that this model is less sensitive to large events. Actually, if I use the complete dataset, the regressions are the following,i.e. with a lognormal distribution, the average cost is decreasing with the age of the car, while it is increasing with a Gamma model. The main reason here is that there is one large (not to say huge) claim in the dataset,&#62; couts[which.max(couts$cout),]         cout exposition zone puissance agevehicule ageconducteur7842  4024601       0.22    B         9          13            19     marque carburant densite region7842      2         E      93     24One young driver got a $ 4 million claim, with a 13 year old car. This is an outliers for the Gamma regression, that clearly influences the estimation (the second largest if only one third of this one). Since there is a clear influence of large claims on the estimation of the average cost, a natural idea might be to remove those large claims. Or perhaps to see them as different from normal claims: normal claims can be explained by some covariates, but perhaps that those large claims should be shared not only within its own class, but within all the insured on the portfolio. To formalize this idea, observe that we can writewhere the blue part is associated to normal-sized claims, while large ones correspond to the red part. It is then possible to run three regressions: one on normal sized claims, one on large claims, and one on the indicator of having a large claims, given that a claim occurred. The code here is something like that: a large claim - here - is above $ 10,000 (one has a fix it)&#62; s= 10000&#62; couts$normal=(couts$cout&#60;=s)&#62; mean(couts$normal)[1] 0.9818087which represent 2% of the claims in our dataset.We can run 3 sets of regressions, with smoothed regression on the age of the car. The first one to model large claims individual costs,&#62; indice = which(couts$cout&#62;s)&#62; mean(couts$cout[indice])[1] 34471.59&#62; library(splines)&#62; regB=glm(cout~bs(agevehicule),data=couts,+ subset=indice,family=Gamma(link="log"))&#62; ypB=predict(regB,newdata=data.frame(agevehicule=age),type="response")&#62; ypB2=mean(couts$cout[indice])the second one to model normal claims individual costs,&#62; indice = which(couts$cout&#60;=s)&#62; mean(couts$cout[indice])[1] 1335.878&#62; regA=glm(cout~bs(agevehicule),data=couts,+ subset=indice,family=Gamma(link="log"))&#62; ypA=predict(regA,newdata=data.frame(agevehicule=age),type="response")&#62; ypA2=mean(couts$cout[indice])And finally, a third one, on the probability of having a normal sized claim, given that a claim occurred&#62; regC=glm(normal~bs(agevehicule),data=couts,family=binomial)&#62; ypC=predict(regC,newdata=data.frame(agevehicule=age),type="response")&#62; regC2=glm(normal~1,data=couts,family=binomial)&#62; ypC2=predict(regC2,newdata=data.frame(agevehicule=age),type="response")Note that we to have, each time something that can be interpreted either as , or  - i.e. no covariate is considered on the later. On the graph below, we did plotwhere Gamma regressions - with splines - are considered for the average costs, while logistic regressions - again with splines - are considered to model probabilities.(but careful with splines: on borders, since we do not have a lot of observations, the behavior can be... odd. And adjustments should be made to obtain an adequate level of premium).  If it is legitimate to assume that normal-sized claims can be explained by some covariates, perhaps large claims (or extremely large ones) are just purely random, i.e. not function of any covariate, at all. I.e.To go one step further, it might also be possible to assume that not only the size of the claim (given that it is a large one) is not a function of any covariate, but perhaps neither is the probability of having an extremely large claim, tooFrom the first part, we've seen that the distribution considered had an impact on the prediction, and in the second, we've seen that the definition of large claims (and how to deal with them) also has an impact. So clearly, actuaries have some leverage when working on ratemaking...