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
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
plot(M) ## Default plot of a Mack chain-ladder output
plot(M, lattice=TRUE)
B <- BootChainLadder(GenIns, R=999) ## 999 bootstrap replicates
B
## BootChainLadder(Triangle = GenIns, R = 999)
##
## Latest Mean Ultimate Mean IBNR IBNR.S.E IBNR 75% IBNR 95%
## 2002 3,901 3,901 0.0 0 0 0
## 2003 5,339 5,435 95.9 114 151 315
## 2004 4,909 5,392 482.7 232 615 911
## 2005 4,588 5,287 698.5 263 867 1,163
## 2006 3,873 4,860 987.2 296 1,183 1,531
## 2007 3,692 5,133 1,441.6 384 1,692 2,091
## 2008 3,483 5,641 2,158.1 473 2,461 2,966
## 2009 2,864 6,840 3,975.2 793 4,466 5,367
## 2010 1,363 5,613 4,249.5 1,055 4,905 6,110
## 2011 344 5,031 4,687.2 2,001 5,817 8,047
##
## Totals
## Latest: 34,358
## Mean Ultimate: 53,134
## Mean IBNR: 18,776
## IBNR.S.E 2,861
## Total IBNR 75%: 20,596
## Total IBNR 95%: 23,505
plot(B) ## Default plot of a Bootstrap chain-ladder 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.
library(XML)
## Warning: package 'XML' was built under R version 3.4.1
library(googleVis)
## Source data diretly from the web
url <- "http://ds.iris.edu/sm2/eventlist/"
eq <- readHTMLTable(readLines(url),
colClasses=c("factor", rep("numeric", 4), "factor"))$evTable
names(eq) <- c("DATE", "LAT", "LON", "MAG",
"DEPTH", "LOCATION_NAME", "IRIS_ID")
##Format location data
eq$loc=paste(eq$LAT, eq$LON, sep=":")
library(googleVis)
## Create a geo chart with the Google Chart API
G <- gvisGeoChart(eq, "loc", "DEPTH", "MAG",
options=list(displayMode="Markers",
colorAxis="{colors:['purple', 'red', 'orange', 'grey']}",
backgroundColor="lightblue"), chartid="EQ")
plot(G)
London R user group meeting |
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
sessionInfo()
## R version 3.4.0 (2017-04-21)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS Sierra 10.12.5
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
##
## 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] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] XML_3.98-1.9 tm_0.7-1 NLP_0.1-10
## [4] wordcloud_2.5 RColorBrewer_1.1-2 googleVis_0.6.3
## [7] ChainLadder_0.2.4
##
## loaded via a namespace (and not attached):
## [1] biglm_0.9-1 statmod_1.4.30 zoo_1.8-0
## [4] slam_0.1-40 reshape2_1.4.2 splines_3.4.0
## [7] lattice_0.20-35 colorspace_1.3-2 htmltools_0.3.6
## [10] stats4_3.4.0 yaml_2.1.14 mgcv_1.8-17
## [13] rlang_0.1.1 nloptr_1.0.4 tweedie_2.2.5
## [16] plyr_1.8.4 stringr_1.2.0 MatrixModels_0.4-1
## [19] munsell_0.4.3 cplm_0.7-5 gtable_0.2.0
## [22] expint_0.1-4 codetools_0.2-15 coda_0.19-1
## [25] evaluate_0.10 systemfit_1.1-20 knitr_1.16
## [28] SparseM_1.77 lmtest_0.9-35 quantreg_5.33
## [31] pbkrtest_0.4-7 parallel_3.4.0 highr_0.6
## [34] Rcpp_0.12.11 scales_0.4.1 backports_1.1.0
## [37] jsonlite_1.5 lme4_1.1-13 ggplot2_2.2.1
## [40] digest_0.6.12 stringi_1.1.5 grid_3.4.0
## [43] rprojroot_1.2 tools_3.4.0 sandwich_2.3-4
## [46] magrittr_1.5 lazyeval_0.2.0 tibble_1.3.3
## [49] car_2.1-4 MASS_7.3-47 Matrix_1.2-10
## [52] actuar_2.1-1 minqa_1.2.4 rmarkdown_1.6
## [55] nnet_7.3-12 nlme_3.1-131 compiler_3.4.0