Using R in Insurance

Markus Gesmann, GIRO Brussels, 19 September 2012

Markus Gesmann, GIRO Brussels, 19 September 2012

Creative Commons Licence
Valid XHTML 1.0 Strict

Hello - About me

Agenda

Why I started using R

mages blog

What is R?

R project

R made its way from academia to industry

R made its way from academia to industry

Why R in insurance?

John D Cook talk about Why and how people
use R

But why use a computing language?

Geeks vs Non-Geeks

By Bruno Oliveira

Typical use cases for R in insurance

Three R examples

Reserving: Mack chain-ladder

library(ChainLadder) ## load ChainLadder functions
data(GenIns) ## Famous Taylor / Ashe triangle
## For the purpose of the presentation we change the data slightly
dimnames(GenIns)$origin=2002:2011 ## original 1:10
GenIns <- GenIns/1000 ## Requires less space on slide
round(GenIns, 0) ## Display rounded figures
##       dev
## origin   1    2    3    4    5    6    7    8    9   10
##   2002 358 1125 1735 2218 2746 3320 3466 3606 3834 3901
##   2003 352 1236 2170 3353 3799 4120 4648 4914 5339   NA
##   2004 291 1292 2219 3235 3986 4133 4629 4909   NA   NA
##   2005 311 1419 2195 3757 4030 4382 4588   NA   NA   NA
##   2006 443 1136 2128 2898 3403 3873   NA   NA   NA   NA
##   2007 396 1333 2181 2986 3692   NA   NA   NA   NA   NA
##   2008 441 1288 2420 3483   NA   NA   NA   NA   NA   NA
##   2009 359 1421 2864   NA   NA   NA   NA   NA   NA   NA
##   2010 377 1363   NA   NA   NA   NA   NA   NA   NA   NA
##   2011 344   NA   NA   NA   NA   NA   NA   NA   NA   NA

Reserving: Mack chain-ladder


Chart created with googleVis

Reserving: Mack chain-ladder

M <- MackChainLadder(GenIns, est.sigma = "Mack")
M
## MackChainLadder(Triangle = GenIns, est.sigma = "Mack")
## 
##      Latest Dev.To.Date Ultimate    IBNR Mack.S.E CV(IBNR)
## 2002  3,901      1.0000    3,901     0.0      0.0      NaN
## 2003  5,339      0.9826    5,434    94.6     75.5    0.798
## 2004  4,909      0.9127    5,379   469.5    121.7    0.259
## 2005  4,588      0.8661    5,298   709.6    133.5    0.188
## 2006  3,873      0.7973    4,858   984.9    261.4    0.265
## 2007  3,692      0.7223    5,111 1,419.5    411.0    0.290
## 2008  3,483      0.6153    5,661 2,177.6    558.3    0.256
## 2009  2,864      0.4222    6,785 3,920.3    875.3    0.223
## 2010  1,363      0.2416    5,642 4,279.0    971.3    0.227
## 2011    344      0.0692    4,970 4,625.8  1,363.2    0.295
## 
##               Totals
## Latest:    34,358.09
## Dev:            0.65
## Ultimate:  53,038.95
## IBNR:      18,680.86
## Mack S.E.:  2,447.09
## CV(IBNR):       0.13

Reserving: Mack chain-ladder

plot(M)  ## Default plot of a Mack chain-ladder output
Check for trends in the residuals plots to verify if the Mack-model is reasonable

Check for trends in the residuals plots to verify if the Mack-model is reasonable

Reserving: Mack chain-ladder

plot(M, lattice = TRUE)
Plot of developments, forecasts and standard errors

Plot of developments, forecasts and standard errors

Reserving: Bootstrap chain-ladder

B <- BootChainLadder(GenIns, R = 999)  ## 999 bootstrap replicates
B
## BootChainLadder(Triangle = GenIns, R = 999)
## 
##      Latest Mean Ultimate Mean IBNR SD IBNR IBNR 75% IBNR 95%
## 2002  3,901         3,901       0.0     0.0        0        0
## 2003  5,339         5,434      95.2    82.5      132      247
## 2004  4,909         5,367     457.5   163.8      559      741
## 2005  4,588         5,308     719.6   213.8      857    1,097
## 2006  3,873         4,862     988.7   244.8    1,146    1,410
## 2007  3,692         5,094   1,402.4   289.7    1,596    1,909
## 2008  3,483         5,668   2,185.0   374.0    2,436    2,855
## 2009  2,864         6,808   3,943.1   553.7    4,293    4,937
## 2010  1,363         5,650   4,286.8   617.2    4,681    5,370
## 2011    344         5,028   4,684.4   981.4    5,239    6,426
## 
##                 Totals
## Latest:         34,358
## Mean Ultimate:  53,121
## Mean IBNR:      18,763
## SD IBNR:         1,621
## Total IBNR 75%: 19,744
## Total IBNR 95%: 21,477

Reserving: Boot chain-ladder

plot(B)  ## Default plot of a Bootstrap chain-ladder output
Check if the model is reasonable

Check if the model is reasonable

Automated reporting: Create PowerPoint slide with R output

myfile=tempfile()
win.metafile(file=myfile)
plot(M, lattice=TRUE)
dev.off()
## Load MS Office interface statconnDCOM
library(rcom)
## Run VBA code from R
ppt<-comCreateObject("Powerpoint.Application")
comSetProperty(ppt,"Visible",TRUE)
myPresColl<-comGetProperty(ppt,"Presentations")
myPres<-comInvoke(myPresColl,"Add")
mySlides<-comGetProperty(myPres,"Slides")
mySlide<-comInvoke(mySlides,"Add",1,12)
myShapes<-comGetProperty(mySlide,"Shapes")
myPicture<-comInvoke(myShapes,"AddPicture",
                     myfile, 0,1,100,10)

Check license requirement for commercial use of statconnDCOM interface.

Extracting data from a web page

library(XML)
library(googleVis)
## Source data diretly from the web
url <- "http://www.iris.edu/seismon/last30.html"
eq <- readHTMLTable(readLines(url),
 colClasses=c("factor", rep("numeric", 4), "factor"), which=2)
## Format location data
eq$loc=paste(eq$LAT, eq$LON, sep=":")

Display earth quake information of last 30 days

library(googleVis)
## Create a geo chart with the Google Chart API
G <- gvisGeoChart(eq, "loc", "DEPTH km", "MAG",
                   options=list(displayMode="Markers", 
                   colorAxis="{colors:['purple', 'red', 'orange', 'grey']}",
                   backgroundColor="lightblue"), chartid="EQ")
plot(G)

Getting started with R in actuarial work

R packages for actuaries on CRAN

Meet the R experts

London R photo London R user group meeting

How I created this presentation with RStudio, knitr, pandoc and slidy


Rscript -e "library(knitr); knit('Using_R_in_Insurance_GIRO_2012.Rmd')"
pandoc -s -S -i -t slidy --mathjax Using_R_in_Insurance_GIRO_2012.md 
  -o Using_R_in_Insurance_GIRO_2012.html

Conclusions

If you liked this presentation …

… you may also like:

Questions?

R version and packages used for this presentation

sessionInfo()
## R version 2.15.1 (2012-06-22)
## Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
## 
## locale:
## [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
## 
## attached base packages:
## [1] splines   methods   stats     graphics  grDevices utils     datasets 
## [8] base     
## 
## other attached packages:
##  [1] XML_3.9-4           tm_0.5-7.1          wordcloud_2.2      
##  [4] RColorBrewer_1.0-5  Rcpp_0.9.13         googleVis_0.2.18   
##  [7] RJSONIO_0.98-1      ChainLadder_0.1.5-3 tweedie_2.1.1      
## [10] statmod_1.4.15      cplm_0.6-4          lme4_0.999999-0    
## [13] ggplot2_0.9.2.1     coda_0.15-2         biglm_0.8          
## [16] DBI_0.2-5           actuar_1.1-4        RUnit_0.4.26       
## [19] systemfit_1.1-12    lmtest_0.9-30       zoo_1.7-7          
## [22] car_2.0-13          nnet_7.3-4          MASS_7.3-21        
## [25] Matrix_1.0-9        lattice_0.20-10     Hmisc_3.9-3        
## [28] survival_2.36-14    knitr_0.8          
## 
## loaded via a namespace (and not attached):
##  [1] amer_0.6.10      cluster_1.14.2   colorspace_1.1-1 dichromat_1.2-4 
##  [5] digest_0.5.2     evaluate_0.4.2   formatR_0.6      grid_2.15.1     
##  [9] gtable_0.1.1     labeling_0.1     memoise_0.1      minqa_1.2.1     
## [13] munsell_0.4      nlme_3.1-104     plyr_1.7.1       proto_0.3-9.2   
## [17] reshape2_1.2.1   scales_0.2.2     slam_0.1-25      stats4_2.15.1   
## [21] stringr_0.6.1    tools_2.15.1