if (FALSE) {
# Let's fit a series of models and compare them using the Gini index
da <- subset(AutoClaim, IN_YY == 1)
da <- transform(da, CLM_AMT = CLM_AMT / 1000)
P1 <- cpglm(CLM_AMT ~ 1, data = da, offset = log(NPOLICY))
P2 <- cpglm(CLM_AMT ~ factor(CAR_USE) + factor(REVOLKED) +
factor(GENDER) + factor(AREA) +
factor(MARRIED) + factor(CAR_TYPE),
data = da, offset = log(NPOLICY))
P3 <- cpglm(CLM_AMT ~ factor(CAR_USE) + factor(REVOLKED) +
factor(GENDER) + factor(AREA) +
factor(MARRIED) + factor(CAR_TYPE) +
TRAVTIME + MVR_PTS + INCOME,
data = da, offset = log(NPOLICY))
da <- transform(da, P1 = fitted(P1), P2 = fitted(P2), P3 = fitted(P3))
# compute the Gini indices
gg <- gini(loss = "CLM_AMT", score = paste("P", 1:3, sep = ""),
data = da)
gg
# plot the Lorenz curves
theme_set(theme_bw())
plot(gg)
plot(gg, overlay = FALSE)
}
Run the code above in your browser using DataLab