SlideShare a Scribd company logo
R for Car
Insurance
Product
Claudio G. Giancaterino
29/11/2016
Zurich R User Group - Meetup
Motor Third Party Liability
Pricing
By the Insurance contract, economic risk is transferred
from the policyholder to the Insurer
Theoretical Approach
 P=E(X)=E(N)*E(Z)
 P=Risk Premium
 X=Global Loss
 E(N)=claim frequency
 E(Z)=claim severity
 Hp:
 1) cost of claims are i.i.d.
 2) indipendence between number of claims
and cost of claims
From Technical Tariff to
Commercial Tariff
Tariff variables
 P=Pcoll*Yh*Xi*Zj=Technical Tariff
risk coefficients statistical models are employed
 Pt=P*(1+λ)/(1-H)=Commercial Tariff
 λ=Safety Loading Rate
 H=Loading Rate
 P is adjusted by tariff requirement
Dataset “ausprivauto0405”
within CASdatasets R
package
 Statistics
> str(ausprivauto0405)
'data.frame': 67856 obs. of 9 variables:
$ Exposure: num 0.304 0.649 0.569 0.318 0.649 ...
$ VehValue: num 1.06 1.03 3.26 4.14 0.72 2.01 1.6 1.47 0.52
$ VehAge: Factor w/ 4 levels "old cars","oldest cars",..: 1 3 3 3 2
$ VehBody: Factor w/ 13 levels "Bus","Convertible",..: 5 5 13 11 5
$ Gender: Factor w/ 2 levels "Female","Male": 1 1 1 1 1 2 2 2 1
$ DrivAge: Factor w/ 6 levels "old people","older work. people",..: 5 2 5 5
$ ClaimOcc: int 0 0 0 0 0 0 0 0 0 0 ...
$ ClaimNb: int 0 0 0 0 0 0 0 0 0 0 ...
$ ClaimAmount: num 0 0 0 0 0 0 0 0 0 0 ...
> table(VehAge,useNA="always")
VehAge
old cars oldest cars young cars youngest cars <NA>
20064 18948 16587 12257 0
> table(DrivAge,useNA="always")
DrivAge
old people older work. people oldest people working people
10736 16189 6547 15767
young people youngest people <NA>
12875 5742 0
> table(VehBody,useNA="always")
VehBody
Bus Convertible Coupe Hardtop
48 81 780 1579
Hatchback Minibus Motorized caravan Panel van
18915 717 127 752
Roadster Sedan Station wagon Truck
27 22233 16261 1750
Utility <NA>
4586 0
> library(Amelia)
> missmap(ausprivauto0405)
#mean frequency#
> MClaims<-with(rc, sum(ClaimNb)/sum(Exposure))
> MClaims
[1] 0.5471511
 
#mean severity#
> MACost<-with(rc, sum(ClaimAmount)/sum(ClaimNb))
> MACost
[1] 287.822
 
#mean risk premium#
> MPremium<-with(rc, sum(ClaimAmount)/sum(Exposure))
> MPremium
[1] 157.4821
> actuallosses<-with(rc.f, sum(ClaimAmount))
> actuallosses
[1] 9342125
> library(ggplot2)
> ggplot(rc, aes(x = AgeCar))+geom_histogram(stat="bin", bins=30)
> ggplot(rc, aes(x = BodyCar))+geom_histogram(stat="bin", bins=30)
> ggplot(rc, aes(x = AgeDriver))+geom_histogram(stat="bin", bins=30)
> ggplot(rc, aes(x = VehValue))+geom_histogram(stat="bin", bins=30
> boxplot(rc$AgeCar,rc$BodyCar,rc$VehValue,rc$AgeDriver,
+ xlab="AgeCar BodyCar VehValue AgeDriver")
Cluster Analysis by k-means
#Prepare Data
> rc.stand<-scale(rc[-1]) # To standardize the variables
#Determine number of clusters
> nk = 2:10
> WSS = sapply(nk, function(k) {
+ kmeans(rc.stand, centers=k)$tot.withinss
+ })
> plot(nk, WSS, type="l", xlab="Number of Clusters",
+ ylab="Within groups sum of squares")
#k-means with k = 7 solutions
> k.means.fit <- kmeans(rc.stand, 7)
2 4 6 8 10
6000080000100000120000140000
Number of Clusters
Withingroupssumofsquares
Generalized Linear Models
(GLM)Yi~EF(b(θi);Φ/ωi) g(μi)=ηi ηi=Σjxijβj
Random Component Link Systematic Component
Linear Models are extended in
two directions:
Probability distribution:
Output variables are stochastically
independent with the same exponential
family distribution.
Expected value:
There is a link function between
expected value of outputs and covariates
that could be different from linear
regression.
GLM Analysis
Univariate Approach
#stochastic risk premium with GLM approach#
> PRSModglm1<-glm(RiskPremium1~AgeCar+BodyCar+VehValue+AgeDriver,
+ weights=Exposure, data=rc.f, family=gaussian(link=log))
> GLMSRiskPremium1<-predict(PRSModglm1,data=rc.f,type="response")
Multivariate Approach
#stochastic risk premium with GLM approach#
> PRSModglm2<-glm(RiskPremium2~AgeCar*BodyCar*VehValue*AgeDriver,
+ weights=Exposure, data=rc, family=gaussian(link=log))
> GLMSRiskPremium2<-predict(PRSModglm2,data=rc,type="response")
Generalized NonLinear
Models (GNM)
Yi~EF(b(θi);Φ/ωi) g(μi)=ηi(xij;βj) ηi=Σjxijβj
Random Component Link Systematic Component
Generalized Linear Models are extended
in the link function where the
systematic component is non linear
in the parameters βj.
It can be considered an extension of
nonlinear least squares model, where the
variance of the output depend on the mean.
Difficult are in starting values, they are
generated randomly for non linear
parameters and using a GLM fit for linear
parameters.
GNM Analysis
Univariate Approach
> library(gnm)
#stochastic risk premium with GNM approach#
> PRSModgnm1<-gnm(RiskPremium1~AgeCar+BodyCar+VehValue+AgeDriver,
+ weights=Exposure, data=rc.f, family=Gamma(link=log))
> GNMSRiskPremium1<-predict(PRSModgnm1,data=rc.f,type="response")
Multivariate Approach
> #stochastic risk premium with GNM approach#
> PRSModgnm2<-gnm(RiskPremium2~VehValue*AgeDriver*AgeCar*BodyCar,
+ weights=Exposure, data=rc, family=Gamma(link=log))
> GNMSRiskPremium2<-predict(PRSModgnm2,data=rc,type="response")
Generalized Additive
Models (GAM)
Yi~EF(b(θi);Φ/ωi) g(μi)=ηi ηi= Σpxipβip+Σjfj(xij)
Random Component Link Systematic Component
Generalized additive models extend
generalized linear models in the predictor:
systematic component is made up by one
parametric part and one non parametric part
built by the sum of unknown “smoothing”
functions of the covariates.
For the estimators are used splines,
functions made up by combination of
little polynomial segment joined in knots.
GAM Analysis
Univariate Approach
> library(mgcv)
#stochastic risk premium with GAM approach#
> PRSModgam1<-gam(RiskPremiumgam1~s(AgeCar, bs="cc", k=4)
+ +s(BodyCar, bs="cc", k=12)+s(VehValue, bs="cc", k=30)
+ +s(AgeDriver, bs="cc", k=6), weights=Exposure, data=rc,
+ family=Gamma(link=log))
> GAMSRiskPremium1<-predict(PRSModgam1,data=rc,type="response")
Multivariate Approach
> #stochastic risk premium with GAM approach#
> PRSModgam2<gam(RiskPremiumgam2~te(BodyCar,VehValue,AgeDriver,AgeCar,
+ k=4),weights=Exposure, data=rc, family="Gamma"(link=log))
> GAMSRiskPremium2<-predict(PRSModgam2,data=rc,type="response")
> rc$GAMSRiskPremium2<-with(rc, GAMSRiskPremium2)
Mean
commercial
tariff
Tariff
requirement
Loss Ratio
Residuals
degrees of
freedom
Expected
Losses
Actual
Losses
Explained
Deviance
Risk
coefficients
Uni- GLM 234,4587 1,000490 1,447822 27.501 9.337.547 9.342.125 96,96% 20
Variate GNM 234,4647 1,000476 1,447785 27.501 9.337.683 9.342.125 96,96% 20
Analysis GAM 232,8702 1,001729 1,457698 27.476 9.325.999 9.342.125 96,20% 45
Multi-
GLM 234,6486 0,9981246 1,446650 27.505 9.359.678 9.342.125 87,64% 16
Variate
GNM 234,6165 0,9979703 1,446848 27.505 9.361.125 9.342.125 87,04% 16
Analysis
GAM 248,5732 0,8596438 1,365612 27.265 10.867.438 9.342.125 84,80% 256
Results
GLM vs GAM vs GNM
Approaches
GLM GAM GNM
Strengths: -User-friendly -Flexible to fit data -Afford some
-Faster elaboration -Realistic values elaboration
-Usually low level of excluded by GLM
residual deviance
-More risk coefficients -Better values
despite GLM
Weakness: -Poor flexibility -Complex to realize -Complex to use
to fit data
-Usually higher
values of residual
deviance
-Overestimed values
References
 C.G. Giancaterino - GLM, GNM and GAM Approaches on MTPL Pricing -
Journal of Mathematics and Statistical Science – 08/2016
http://www.ss-pub.org/journals/jmss/vol-2/vol-2-issue-8-august-2016/
 X.Marechal & S. Mahy – Advanced Non Life Pricing – EAA Seminar
 N. Savelli & G.P. Clemente – Lezioni di Matematica Attuariale delle
Assicurazioni Danni – Educatt
Many Thanks for your Attention!!!
Contact:
Claudio G. Giancaterino
c.giancaterino@gmail.com

More Related Content

What's hot

MITCOE 2011-12 conm-submission
MITCOE 2011-12 conm-submissionMITCOE 2011-12 conm-submission
MITCOE 2011-12 conm-submissionAshutosh Katti
 
Critical Path Method
Critical Path MethodCritical Path Method
Critical Path Method
Chandi Mohanty
 
Design of a novel controller to increase the frequency response of an aerospace
Design of a novel controller to increase the frequency response of an aerospaceDesign of a novel controller to increase the frequency response of an aerospace
Design of a novel controller to increase the frequency response of an aerospaceIAEME Publication
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
paramita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
paramita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
paramita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
paramita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
paramita30
 
HMPC for Upper Stage Attitude Control
HMPC for Upper Stage Attitude ControlHMPC for Upper Stage Attitude Control
HMPC for Upper Stage Attitude Control
Pantelis Sopasakis
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
paramita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
paramita30
 
Curve fitting and Optimization
Curve fitting and OptimizationCurve fitting and Optimization
Curve fitting and Optimization
Syahrul Senin
 
(Full MatLab Code) Image compression DCT
(Full MatLab Code) Image compression DCT(Full MatLab Code) Image compression DCT
(Full MatLab Code) Image compression DCT
Chaudhary Sarimurrab
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
paramita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
paramita30
 
Ceske budevice
Ceske budeviceCeske budevice
Ceske budevice
Kjetil Haugen
 

What's hot (20)

MITCOE 2011-12 conm-submission
MITCOE 2011-12 conm-submissionMITCOE 2011-12 conm-submission
MITCOE 2011-12 conm-submission
 
Critical Path Method
Critical Path MethodCritical Path Method
Critical Path Method
 
Design of a novel controller to increase the frequency response of an aerospace
Design of a novel controller to increase the frequency response of an aerospaceDesign of a novel controller to increase the frequency response of an aerospace
Design of a novel controller to increase the frequency response of an aerospace
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
HMPC for Upper Stage Attitude Control
HMPC for Upper Stage Attitude ControlHMPC for Upper Stage Attitude Control
HMPC for Upper Stage Attitude Control
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Curve fitting and Optimization
Curve fitting and OptimizationCurve fitting and Optimization
Curve fitting and Optimization
 
(Full MatLab Code) Image compression DCT
(Full MatLab Code) Image compression DCT(Full MatLab Code) Image compression DCT
(Full MatLab Code) Image compression DCT
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Topic 4.1
Topic 4.1Topic 4.1
Topic 4.1
 
Topic 2
Topic 2Topic 2
Topic 2
 
Ceske budevice
Ceske budeviceCeske budevice
Ceske budevice
 
Topic 1.2
Topic 1.2Topic 1.2
Topic 1.2
 
04 Algorithms
04 Algorithms04 Algorithms
04 Algorithms
 

Similar to How to use R in different professions: R for Car Insurance Product (Speaker: Claudio Giancaterino)

R logistic regression
R   logistic regressionR   logistic regression
R logistic regression
Learnbay Datascience
 
R/Finance 2009 Chicago
R/Finance 2009 ChicagoR/Finance 2009 Chicago
R/Finance 2009 Chicago
gyollin
 
Introducing R package ESG at Rmetrics Paris 2014 conference
Introducing R package ESG at Rmetrics Paris 2014 conferenceIntroducing R package ESG at Rmetrics Paris 2014 conference
Introducing R package ESG at Rmetrics Paris 2014 conference
Thierry Moudiki
 
Risk modeling prortfolio diversification 4.0
Risk modeling prortfolio diversification 4.0Risk modeling prortfolio diversification 4.0
Risk modeling prortfolio diversification 4.0
Nikhil Shrivastava, MS, SAFe PMPO
 
Relevance of Particle Swarm Optimization Technique for the Solution of Econom...
Relevance of Particle Swarm Optimization Technique for the Solution of Econom...Relevance of Particle Swarm Optimization Technique for the Solution of Econom...
Relevance of Particle Swarm Optimization Technique for the Solution of Econom...
IRJET Journal
 
Economic Dispatch of Generated Power Using Modified Lambda-Iteration Method
Economic Dispatch of Generated Power Using Modified Lambda-Iteration MethodEconomic Dispatch of Generated Power Using Modified Lambda-Iteration Method
Economic Dispatch of Generated Power Using Modified Lambda-Iteration Method
IOSR Journals
 
Generalized Nonlinear Models in R
Generalized Nonlinear Models in RGeneralized Nonlinear Models in R
Generalized Nonlinear Models in R
htstatistics
 
Efficient equity portfolios using mean variance optimisation in R
Efficient equity portfolios using mean variance optimisation in REfficient equity portfolios using mean variance optimisation in R
Efficient equity portfolios using mean variance optimisation in R
Gregg Barrett
 
COMBINED ECONOMIC AND EMISSION DISPATCH WITH AND WITHOUT CONSIDERING TRANSMIS...
COMBINED ECONOMIC AND EMISSION DISPATCH WITH AND WITHOUT CONSIDERING TRANSMIS...COMBINED ECONOMIC AND EMISSION DISPATCH WITH AND WITHOUT CONSIDERING TRANSMIS...
COMBINED ECONOMIC AND EMISSION DISPATCH WITH AND WITHOUT CONSIDERING TRANSMIS...
cscpconf
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
meerobertsonheyde608
 
Automated Sensing System for Monitoring Road Surface Condition Using Fog Comp...
Automated Sensing System for Monitoring Road Surface Condition Using Fog Comp...Automated Sensing System for Monitoring Road Surface Condition Using Fog Comp...
Automated Sensing System for Monitoring Road Surface Condition Using Fog Comp...
IJAEMSJORNAL
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RR Programming: Mathematical Functions In R
R Programming: Mathematical Functions In R
Rsquared Academy
 
MUMS: Transition & SPUQ Workshop - Practical Bayesian Optimization for Urban ...
MUMS: Transition & SPUQ Workshop - Practical Bayesian Optimization for Urban ...MUMS: Transition & SPUQ Workshop - Practical Bayesian Optimization for Urban ...
MUMS: Transition & SPUQ Workshop - Practical Bayesian Optimization for Urban ...
The Statistical and Applied Mathematical Sciences Institute
 
MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709
Min-hyung Kim
 
6.3.2 CLIMADA model demo
6.3.2 CLIMADA model demo6.3.2 CLIMADA model demo
6.3.2 CLIMADA model demo
NAP Events
 
BIometrics- plotting DET and EER curve using Matlab
BIometrics- plotting DET and EER curve using MatlabBIometrics- plotting DET and EER curve using Matlab
BIometrics- plotting DET and EER curve using MatlabShiv Koppad
 
presentation
presentationpresentation
presentation3ashmawy
 

Similar to How to use R in different professions: R for Car Insurance Product (Speaker: Claudio Giancaterino) (20)

R logistic regression
R   logistic regressionR   logistic regression
R logistic regression
 
R/Finance 2009 Chicago
R/Finance 2009 ChicagoR/Finance 2009 Chicago
R/Finance 2009 Chicago
 
Introducing R package ESG at Rmetrics Paris 2014 conference
Introducing R package ESG at Rmetrics Paris 2014 conferenceIntroducing R package ESG at Rmetrics Paris 2014 conference
Introducing R package ESG at Rmetrics Paris 2014 conference
 
Risk modeling prortfolio diversification 4.0
Risk modeling prortfolio diversification 4.0Risk modeling prortfolio diversification 4.0
Risk modeling prortfolio diversification 4.0
 
Relevance of Particle Swarm Optimization Technique for the Solution of Econom...
Relevance of Particle Swarm Optimization Technique for the Solution of Econom...Relevance of Particle Swarm Optimization Technique for the Solution of Econom...
Relevance of Particle Swarm Optimization Technique for the Solution of Econom...
 
Economic Dispatch of Generated Power Using Modified Lambda-Iteration Method
Economic Dispatch of Generated Power Using Modified Lambda-Iteration MethodEconomic Dispatch of Generated Power Using Modified Lambda-Iteration Method
Economic Dispatch of Generated Power Using Modified Lambda-Iteration Method
 
Generalized Nonlinear Models in R
Generalized Nonlinear Models in RGeneralized Nonlinear Models in R
Generalized Nonlinear Models in R
 
Efficient equity portfolios using mean variance optimisation in R
Efficient equity portfolios using mean variance optimisation in REfficient equity portfolios using mean variance optimisation in R
Efficient equity portfolios using mean variance optimisation in R
 
COMBINED ECONOMIC AND EMISSION DISPATCH WITH AND WITHOUT CONSIDERING TRANSMIS...
COMBINED ECONOMIC AND EMISSION DISPATCH WITH AND WITHOUT CONSIDERING TRANSMIS...COMBINED ECONOMIC AND EMISSION DISPATCH WITH AND WITHOUT CONSIDERING TRANSMIS...
COMBINED ECONOMIC AND EMISSION DISPATCH WITH AND WITHOUT CONSIDERING TRANSMIS...
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
 
Automated Sensing System for Monitoring Road Surface Condition Using Fog Comp...
Automated Sensing System for Monitoring Road Surface Condition Using Fog Comp...Automated Sensing System for Monitoring Road Surface Condition Using Fog Comp...
Automated Sensing System for Monitoring Road Surface Condition Using Fog Comp...
 
R Programming: Mathematical Functions In R
R Programming: Mathematical Functions In RR Programming: Mathematical Functions In R
R Programming: Mathematical Functions In R
 
report_2_v2
report_2_v2report_2_v2
report_2_v2
 
MUMS: Transition & SPUQ Workshop - Practical Bayesian Optimization for Urban ...
MUMS: Transition & SPUQ Workshop - Practical Bayesian Optimization for Urban ...MUMS: Transition & SPUQ Workshop - Practical Bayesian Optimization for Urban ...
MUMS: Transition & SPUQ Workshop - Practical Bayesian Optimization for Urban ...
 
MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709
 
6.3.2 CLIMADA model demo
6.3.2 CLIMADA model demo6.3.2 CLIMADA model demo
6.3.2 CLIMADA model demo
 
BIometrics- plotting DET and EER curve using Matlab
BIometrics- plotting DET and EER curve using MatlabBIometrics- plotting DET and EER curve using Matlab
BIometrics- plotting DET and EER curve using Matlab
 
presentation
presentationpresentation
presentation
 
Article 1
Article 1Article 1
Article 1
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 

More from Zurich_R_User_Group

Anomaly detection - database integrated
Anomaly detection - database integratedAnomaly detection - database integrated
Anomaly detection - database integrated
Zurich_R_User_Group
 
R at Sanitas - Workflow, Problems and Solutions
R at Sanitas - Workflow, Problems and SolutionsR at Sanitas - Workflow, Problems and Solutions
R at Sanitas - Workflow, Problems and Solutions
Zurich_R_User_Group
 
Modeling Bus Bunching
Modeling Bus BunchingModeling Bus Bunching
Modeling Bus Bunching
Zurich_R_User_Group
 
Visualizing the frequency of transit delays using QGIS and the Leaflet javasc...
Visualizing the frequency of transit delays using QGIS and the Leaflet javasc...Visualizing the frequency of transit delays using QGIS and the Leaflet javasc...
Visualizing the frequency of transit delays using QGIS and the Leaflet javasc...
Zurich_R_User_Group
 
Introduction to Renjin, the alternative engine for R
Introduction to Renjin, the alternative engine for R Introduction to Renjin, the alternative engine for R
Introduction to Renjin, the alternative engine for R
Zurich_R_User_Group
 
How to use R in different professions: R In Finance (Speaker: Gabriel Foix, M...
How to use R in different professions: R In Finance (Speaker: Gabriel Foix, M...How to use R in different professions: R In Finance (Speaker: Gabriel Foix, M...
How to use R in different professions: R In Finance (Speaker: Gabriel Foix, M...
Zurich_R_User_Group
 
Where South America is Swinging to the Right: An R-Driven Data Journalism Pr...
Where South America is Swinging to the Right:  An R-Driven Data Journalism Pr...Where South America is Swinging to the Right:  An R-Driven Data Journalism Pr...
Where South America is Swinging to the Right: An R-Driven Data Journalism Pr...
Zurich_R_User_Group
 
Visualization Challenge: Mapping Health During Travel
Visualization Challenge: Mapping Health During TravelVisualization Challenge: Mapping Health During Travel
Visualization Challenge: Mapping Health During Travel
Zurich_R_User_Group
 
Zurich R User group: Desc tools
Zurich R User group: Desc tools Zurich R User group: Desc tools
Zurich R User group: Desc tools
Zurich_R_User_Group
 
January 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table packageJanuary 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table package
Zurich_R_User_Group
 
December 2015 Meetup - Shiny: Make Your R Code Interactive - Craig Wang
December 2015 Meetup - Shiny: Make Your R Code Interactive - Craig WangDecember 2015 Meetup - Shiny: Make Your R Code Interactive - Craig Wang
December 2015 Meetup - Shiny: Make Your R Code Interactive - Craig Wang
Zurich_R_User_Group
 

More from Zurich_R_User_Group (11)

Anomaly detection - database integrated
Anomaly detection - database integratedAnomaly detection - database integrated
Anomaly detection - database integrated
 
R at Sanitas - Workflow, Problems and Solutions
R at Sanitas - Workflow, Problems and SolutionsR at Sanitas - Workflow, Problems and Solutions
R at Sanitas - Workflow, Problems and Solutions
 
Modeling Bus Bunching
Modeling Bus BunchingModeling Bus Bunching
Modeling Bus Bunching
 
Visualizing the frequency of transit delays using QGIS and the Leaflet javasc...
Visualizing the frequency of transit delays using QGIS and the Leaflet javasc...Visualizing the frequency of transit delays using QGIS and the Leaflet javasc...
Visualizing the frequency of transit delays using QGIS and the Leaflet javasc...
 
Introduction to Renjin, the alternative engine for R
Introduction to Renjin, the alternative engine for R Introduction to Renjin, the alternative engine for R
Introduction to Renjin, the alternative engine for R
 
How to use R in different professions: R In Finance (Speaker: Gabriel Foix, M...
How to use R in different professions: R In Finance (Speaker: Gabriel Foix, M...How to use R in different professions: R In Finance (Speaker: Gabriel Foix, M...
How to use R in different professions: R In Finance (Speaker: Gabriel Foix, M...
 
Where South America is Swinging to the Right: An R-Driven Data Journalism Pr...
Where South America is Swinging to the Right:  An R-Driven Data Journalism Pr...Where South America is Swinging to the Right:  An R-Driven Data Journalism Pr...
Where South America is Swinging to the Right: An R-Driven Data Journalism Pr...
 
Visualization Challenge: Mapping Health During Travel
Visualization Challenge: Mapping Health During TravelVisualization Challenge: Mapping Health During Travel
Visualization Challenge: Mapping Health During Travel
 
Zurich R User group: Desc tools
Zurich R User group: Desc tools Zurich R User group: Desc tools
Zurich R User group: Desc tools
 
January 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table packageJanuary 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table package
 
December 2015 Meetup - Shiny: Make Your R Code Interactive - Craig Wang
December 2015 Meetup - Shiny: Make Your R Code Interactive - Craig WangDecember 2015 Meetup - Shiny: Make Your R Code Interactive - Craig Wang
December 2015 Meetup - Shiny: Make Your R Code Interactive - Craig Wang
 

Recently uploaded

Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
vrstrong314
 

Recently uploaded (20)

Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
 

How to use R in different professions: R for Car Insurance Product (Speaker: Claudio Giancaterino)

  • 1. R for Car Insurance Product Claudio G. Giancaterino 29/11/2016 Zurich R User Group - Meetup
  • 2. Motor Third Party Liability Pricing By the Insurance contract, economic risk is transferred from the policyholder to the Insurer
  • 3. Theoretical Approach  P=E(X)=E(N)*E(Z)  P=Risk Premium  X=Global Loss  E(N)=claim frequency  E(Z)=claim severity  Hp:  1) cost of claims are i.i.d.  2) indipendence between number of claims and cost of claims
  • 4. From Technical Tariff to Commercial Tariff Tariff variables  P=Pcoll*Yh*Xi*Zj=Technical Tariff risk coefficients statistical models are employed  Pt=P*(1+λ)/(1-H)=Commercial Tariff  λ=Safety Loading Rate  H=Loading Rate  P is adjusted by tariff requirement
  • 5. Dataset “ausprivauto0405” within CASdatasets R package  Statistics > str(ausprivauto0405) 'data.frame': 67856 obs. of 9 variables: $ Exposure: num 0.304 0.649 0.569 0.318 0.649 ... $ VehValue: num 1.06 1.03 3.26 4.14 0.72 2.01 1.6 1.47 0.52 $ VehAge: Factor w/ 4 levels "old cars","oldest cars",..: 1 3 3 3 2 $ VehBody: Factor w/ 13 levels "Bus","Convertible",..: 5 5 13 11 5 $ Gender: Factor w/ 2 levels "Female","Male": 1 1 1 1 1 2 2 2 1 $ DrivAge: Factor w/ 6 levels "old people","older work. people",..: 5 2 5 5 $ ClaimOcc: int 0 0 0 0 0 0 0 0 0 0 ... $ ClaimNb: int 0 0 0 0 0 0 0 0 0 0 ... $ ClaimAmount: num 0 0 0 0 0 0 0 0 0 0 ...
  • 6. > table(VehAge,useNA="always") VehAge old cars oldest cars young cars youngest cars <NA> 20064 18948 16587 12257 0 > table(DrivAge,useNA="always") DrivAge old people older work. people oldest people working people 10736 16189 6547 15767 young people youngest people <NA> 12875 5742 0 > table(VehBody,useNA="always") VehBody Bus Convertible Coupe Hardtop 48 81 780 1579 Hatchback Minibus Motorized caravan Panel van 18915 717 127 752 Roadster Sedan Station wagon Truck 27 22233 16261 1750 Utility <NA> 4586 0
  • 8. #mean frequency# > MClaims<-with(rc, sum(ClaimNb)/sum(Exposure)) > MClaims [1] 0.5471511   #mean severity# > MACost<-with(rc, sum(ClaimAmount)/sum(ClaimNb)) > MACost [1] 287.822   #mean risk premium# > MPremium<-with(rc, sum(ClaimAmount)/sum(Exposure)) > MPremium [1] 157.4821 > actuallosses<-with(rc.f, sum(ClaimAmount)) > actuallosses [1] 9342125
  • 9. > library(ggplot2) > ggplot(rc, aes(x = AgeCar))+geom_histogram(stat="bin", bins=30) > ggplot(rc, aes(x = BodyCar))+geom_histogram(stat="bin", bins=30) > ggplot(rc, aes(x = AgeDriver))+geom_histogram(stat="bin", bins=30) > ggplot(rc, aes(x = VehValue))+geom_histogram(stat="bin", bins=30
  • 10.
  • 12. Cluster Analysis by k-means #Prepare Data > rc.stand<-scale(rc[-1]) # To standardize the variables #Determine number of clusters > nk = 2:10 > WSS = sapply(nk, function(k) { + kmeans(rc.stand, centers=k)$tot.withinss + }) > plot(nk, WSS, type="l", xlab="Number of Clusters", + ylab="Within groups sum of squares") #k-means with k = 7 solutions > k.means.fit <- kmeans(rc.stand, 7)
  • 13. 2 4 6 8 10 6000080000100000120000140000 Number of Clusters Withingroupssumofsquares
  • 14. Generalized Linear Models (GLM)Yi~EF(b(θi);Φ/ωi) g(μi)=ηi ηi=Σjxijβj Random Component Link Systematic Component Linear Models are extended in two directions: Probability distribution: Output variables are stochastically independent with the same exponential family distribution. Expected value: There is a link function between expected value of outputs and covariates that could be different from linear regression.
  • 15. GLM Analysis Univariate Approach #stochastic risk premium with GLM approach# > PRSModglm1<-glm(RiskPremium1~AgeCar+BodyCar+VehValue+AgeDriver, + weights=Exposure, data=rc.f, family=gaussian(link=log)) > GLMSRiskPremium1<-predict(PRSModglm1,data=rc.f,type="response") Multivariate Approach #stochastic risk premium with GLM approach# > PRSModglm2<-glm(RiskPremium2~AgeCar*BodyCar*VehValue*AgeDriver, + weights=Exposure, data=rc, family=gaussian(link=log)) > GLMSRiskPremium2<-predict(PRSModglm2,data=rc,type="response")
  • 16. Generalized NonLinear Models (GNM) Yi~EF(b(θi);Φ/ωi) g(μi)=ηi(xij;βj) ηi=Σjxijβj Random Component Link Systematic Component Generalized Linear Models are extended in the link function where the systematic component is non linear in the parameters βj. It can be considered an extension of nonlinear least squares model, where the variance of the output depend on the mean. Difficult are in starting values, they are generated randomly for non linear parameters and using a GLM fit for linear parameters.
  • 17. GNM Analysis Univariate Approach > library(gnm) #stochastic risk premium with GNM approach# > PRSModgnm1<-gnm(RiskPremium1~AgeCar+BodyCar+VehValue+AgeDriver, + weights=Exposure, data=rc.f, family=Gamma(link=log)) > GNMSRiskPremium1<-predict(PRSModgnm1,data=rc.f,type="response") Multivariate Approach > #stochastic risk premium with GNM approach# > PRSModgnm2<-gnm(RiskPremium2~VehValue*AgeDriver*AgeCar*BodyCar, + weights=Exposure, data=rc, family=Gamma(link=log)) > GNMSRiskPremium2<-predict(PRSModgnm2,data=rc,type="response")
  • 18. Generalized Additive Models (GAM) Yi~EF(b(θi);Φ/ωi) g(μi)=ηi ηi= Σpxipβip+Σjfj(xij) Random Component Link Systematic Component Generalized additive models extend generalized linear models in the predictor: systematic component is made up by one parametric part and one non parametric part built by the sum of unknown “smoothing” functions of the covariates. For the estimators are used splines, functions made up by combination of little polynomial segment joined in knots.
  • 19. GAM Analysis Univariate Approach > library(mgcv) #stochastic risk premium with GAM approach# > PRSModgam1<-gam(RiskPremiumgam1~s(AgeCar, bs="cc", k=4) + +s(BodyCar, bs="cc", k=12)+s(VehValue, bs="cc", k=30) + +s(AgeDriver, bs="cc", k=6), weights=Exposure, data=rc, + family=Gamma(link=log)) > GAMSRiskPremium1<-predict(PRSModgam1,data=rc,type="response") Multivariate Approach > #stochastic risk premium with GAM approach# > PRSModgam2<gam(RiskPremiumgam2~te(BodyCar,VehValue,AgeDriver,AgeCar, + k=4),weights=Exposure, data=rc, family="Gamma"(link=log)) > GAMSRiskPremium2<-predict(PRSModgam2,data=rc,type="response") > rc$GAMSRiskPremium2<-with(rc, GAMSRiskPremium2)
  • 20. Mean commercial tariff Tariff requirement Loss Ratio Residuals degrees of freedom Expected Losses Actual Losses Explained Deviance Risk coefficients Uni- GLM 234,4587 1,000490 1,447822 27.501 9.337.547 9.342.125 96,96% 20 Variate GNM 234,4647 1,000476 1,447785 27.501 9.337.683 9.342.125 96,96% 20 Analysis GAM 232,8702 1,001729 1,457698 27.476 9.325.999 9.342.125 96,20% 45 Multi- GLM 234,6486 0,9981246 1,446650 27.505 9.359.678 9.342.125 87,64% 16 Variate GNM 234,6165 0,9979703 1,446848 27.505 9.361.125 9.342.125 87,04% 16 Analysis GAM 248,5732 0,8596438 1,365612 27.265 10.867.438 9.342.125 84,80% 256 Results
  • 21. GLM vs GAM vs GNM Approaches GLM GAM GNM Strengths: -User-friendly -Flexible to fit data -Afford some -Faster elaboration -Realistic values elaboration -Usually low level of excluded by GLM residual deviance -More risk coefficients -Better values despite GLM Weakness: -Poor flexibility -Complex to realize -Complex to use to fit data -Usually higher values of residual deviance -Overestimed values
  • 22. References  C.G. Giancaterino - GLM, GNM and GAM Approaches on MTPL Pricing - Journal of Mathematics and Statistical Science – 08/2016 http://www.ss-pub.org/journals/jmss/vol-2/vol-2-issue-8-august-2016/  X.Marechal & S. Mahy – Advanced Non Life Pricing – EAA Seminar  N. Savelli & G.P. Clemente – Lezioni di Matematica Attuariale delle Assicurazioni Danni – Educatt
  • 23. Many Thanks for your Attention!!! Contact: Claudio G. Giancaterino c.giancaterino@gmail.com