forwardBackStepAIC: Function for forward and backward model selection algorithm...

Description Usage Arguments Value Note Author(s) Examples

Description

Function for forward and backward model selection algorithm using information criteria to obtain frequency and severity models for actuarial pricing models the routine also dynamically adjusts the categories for variables that are not significant. This function is intended for analysing categorical explanatory varibles.

Usage

1
2
3
forwardBackStepAIC(ratingFact, countVar, sevVar, factLevels=1, timeVar, IC="BIC", consistThresh=60, theData,
    analysisType="frequency", myDistr="poisson", theLink="log", exposureName="Exposure", handicap=0,
    myDocumentTitle="Automated Pricing GLM", theAlg="forward", plotCharts=TRUE, ...)

Arguments

ratingFact

this a character vector denoting the column headers of rating factors in your table (theData). Please be aware that the package autoPricing does not currently support interaction terms in your model.

countVar

this is a character denoting the claims count column

sevVar

this is a character denoting the column header of the severity variable

factLevels

this is a list of matrices (or data.frames) that denote the mapping of the rating factors from their current categories to their logical aggregatable variables

timeVar

this is a character denoting the column header of the year variable. This variable must be specified because time consistency analysis is carried out by using interaction terms with the year variable.

IC

This is a character string denoting whether the information criterion used should be AIC (Akaike Information Criterion) or BIC (Bayesian Information Criterion)

consistThresh

Set this to the threshold for median consistency, denoting that the model fit of interaction of the variables with Year is consistent to consistThresh or greater before it is accepted

theData

this is the data set that will be used for the analysis containing the rating factors, exposure, severity, claim counts, and year

myDistr

this is a character string denoting which distribution should be used in the analysis e.g. "poisson", "Gamma"

theLink

this is the link function to be used in the analysis

exposureName

this is a character string denoting the column name of the exposure (in Years)

handicap

extra penalty for the information criterion, it is added to the IC of the candiate model to alter how dificult it is to accept variables

myDocumentTitle

This is a character string for the title of the document

theAlg

this is the algorithm to be used either "forward" or "backward".

plotCharts

this is a logical variable as to whether the charts should be plotted

Value

The output is the frequency or severity model from the chosen algorithm theAlg

Note

please pay attention to the structure of the table requires, since it is non-standard as far as in most modelling systems a separate policy and claims table is used for the analysis

Author(s)

Chibisi Chima-Okereke cchima-okereke@mango-solutions.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#Loading the data
data(policyTable)

#Preparing rating factor names and mapping tables 
myRatingFactors <- c("BonusMalus", "WeightClass", "Region", "Age", "Mileage", "Usage")
ratingFactorLevels <- lapply(myRatingFactors, function(x){matrix(as.character(levels(policyTable[,x])))})
names(ratingFactorLevels) <- myRatingFactors
ratingFactorLevels$Mileage <- cbind(ratingFactorLevels$Mileage, c("0-12500", "0-12500", "> 12500"))

# Example 1: Executing forward algorithm for poisson risk model
outputModelForwardFreq <- forwardBackStepAIC(ratingFact = myRatingFactors, countVar = "NoClaims", 
sevVar = "GrossIncurred", factLevels = ratingFactorLevels, timeVar = "Year", IC = "BIC", 
consistThresh = 60, theData = policyTable, analysisType = "frequency",
myDistr = "poisson", theLink = "log", exposureName = "Exposure",
handicap = 0, myDocumentTitle  = "Automated Pricing GLM", theAlg = "forward", 
plotCharts = TRUE)


# Example 2: Writing process to PDF and log file for documentation purposes
myFolder <- getwd()

pdf(file = file.path(paste(myFolder, "GLMOutput.pdf", sep = "")), height = 7, width = 11)
par(mfrow = c(1,1), cex.main = 1, cex.axis = .9, cex.lab = 1, cex = 1)
sink(file = file.path(paste(myFolder, "GLMOutput.doc", sep = "")))
outputModelForwardFreq <- forwardBackStepAIC(ratingFact = myRatingFactors, countVar = "NoClaims", 
sevVar = "GrossIncurred", factLevels = ratingFactorLevels, timeVar = "Year", IC = "BIC", 
consistThresh = 60, theData = policyTable, analysisType = "frequency",
myDistr = "poisson", theLink = "log", exposureName = "Exposure",
handicap = 0, myDocumentTitle  = "Automated Pricing GLM", theAlg = "forward", 
plotCharts = TRUE)
sink()
dev.off()

MangoTheCat/autoPricing documentation built on May 7, 2019, 2:09 p.m.