Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
15c5b98
Merge remote-tracking branch 'refs/remotes/mages/master'
chiefmurph Oct 15, 2016
119173b
MackChainLadder argument checks
chiefmurph Oct 15, 2016
1035a54
NULL tail.se tail.sigma
chiefmurph Oct 15, 2016
bae2f7f
est.sigma can be a numeric vector
chiefmurph Oct 15, 2016
a061b7d
Merge branch 'refs/heads/tail.se.length'
chiefmurph Oct 15, 2016
b7b9024
first commit
chiefmurph Oct 17, 2016
b59d7a6
plotParms.ChainLadder
chiefmurph Oct 17, 2016
7749757
title with name of Triangle
chiefmurph Oct 17, 2016
a9ea0d0
Save inputs to MackChainLadder
chiefmurph Oct 17, 2016
30b3681
imports gridExtra
chiefmurph Oct 18, 2016
57f19bd
add roxygen comments
chiefmurph Oct 18, 2016
fecb124
create plotParms help file
chiefmurph Oct 18, 2016
b7f6647
Clean up R file so no NOTES
chiefmurph Oct 18, 2016
cd3e83e
plotParms changes
chiefmurph Oct 18, 2016
78de185
Fix TriangleName in Mack
chiefmurph Oct 19, 2016
8149623
First stab at plotParms.MackChainLadder
chiefmurph Oct 19, 2016
9a6d73e
add plot.MackChainLadder
chiefmurph Oct 20, 2016
04e0e53
Merge remote-tracking branch 'refs/remotes/mages/master' into PlotParms
chiefmurph Oct 20, 2016
fa0ef08
fix close paren, eliminate commented lines
chiefmurph Oct 20, 2016
e189862
Need to save more MackChainLadder input parameters
chiefmurph Oct 20, 2016
3d13b11
Merge remote-tracking branch 'refs/remotes/mages/master'
chiefmurph Oct 20, 2016
3f072b8
Save arguments
chiefmurph Oct 23, 2016
9bf5eb1
Close to final draft
chiefmurph Oct 23, 2016
5e8aaa4
Merge remote-tracking branch 'refs/remotes/mages/master' into PlotParms
chiefmurph Oct 23, 2016
1b22df6
Edits
chiefmurph Oct 24, 2016
855a556
Change lm to calc for chainladder cv estimates
chiefmurph Oct 24, 2016
190e9b6
Add "call" to chainladder output list
chiefmurph Oct 24, 2016
1ffc2d1
New default title
chiefmurph Oct 25, 2016
e5758fe
edits
chiefmurph Oct 25, 2016
4705832
final draft edits
chiefmurph Oct 25, 2016
b7bcb75
NA for f depends on f, not f.se
chiefmurph Oct 28, 2016
085dda3
Same for f-1
chiefmurph Oct 28, 2016
8f8312d
Merge remote-tracking branch 'refs/remotes/mages/master' into PlotParms
chiefmurph Feb 8, 2017
5e53dcd
Merge remote-tracking branch 'refs/remotes/origin/master' into PlotParms
chiefmurph Mar 12, 2017
48d1b20
Edited, updated date
chiefmurph Mar 12, 2017
4c918fc
final edits for the day
chiefmurph Mar 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Imports:
reshape2,
lattice,
grid,
gridExtra,
tweedie,
utils,
systemfit,
Expand Down
18 changes: 13 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import(stats)
importFrom(ggplot2, ggplot, geom_density, facet_wrap, aes, "scale_x_continuous")
import(ggplot2)
#importFrom(ggplot2, ggplot, geom_density, facet_wrap, aes, "scale_x_continuous")
importFrom(gridExtra, marrangeGrob)
importFrom(tweedie, rtweedie, "tweedie.profile")
importFrom(statmod, tweedie)
importFrom(systemfit, systemfit, systemfit.control)
Expand All @@ -20,7 +22,8 @@ importFrom(cplm, cpglm)
importFrom(MASS, glm.nb)

importClassesFrom(cplm, NullNum, NullList)
importMethodsFrom(cplm, show, predict, vcov, residuals, resid, coef, fitted, plot, terms)
importMethodsFrom(cplm, show, predict, vcov, residuals, resid, coef, fitted,
plot, terms)
importMethodsFrom(Matrix, summary)

export(MackChainLadder, MunichChainLadder, BootChainLadder,
Expand Down Expand Up @@ -59,7 +62,6 @@ S3method(print, ClarkLDF)
S3method(print, ClarkCapeCod)
S3method(print, ata)


S3method(as.triangle, matrix)
S3method(as.triangle, data.frame)
S3method(as.data.frame, triangle)
Expand Down Expand Up @@ -89,8 +91,10 @@ S3method(mean, BootChainLadder)
S3method(vcov, clark)

exportMethods(predict, Mse, summary, show, coerce,
"[", "$", "[[", "[<-", names, coef, vcov, residCov, residCor,
residuals, resid, rstandard, fitted, plot, cbind2, rbind2, dim)
"[", "$", "[[", "[<-", names, coef,
vcov, residCov, residCor,
residuals, resid, rstandard, fitted,
plot, cbind2, rbind2, dim)

S3method(CDR, MackChainLadder)
S3method(CDR, BootChainLadder)
Expand All @@ -101,4 +105,8 @@ export(tweedieReserve)
S3method(print, tweedieReserve)
S3method(summary, tweedieReserve)

export(plotParms)
S3method(plotParms, ChainLadder)
S3method(plotParms, MackChainLadder)

export(PaidIncurredChain)
6 changes: 5 additions & 1 deletion R/ChainLadder.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

chainladder <- function(Triangle, weights=1,
delta=1){

TriangleName <- deparse(substitute(Triangle))

Triangle <- checkTriangle(Triangle)
n <- dim(Triangle)[2]
Expand All @@ -27,7 +29,9 @@ chainladder <- function(Triangle, weights=1,
}
myModel <- lapply(c(1:(n-1)), lmCL, Triangle)

output <- list(Models=myModel, Triangle=Triangle, delta=delta, weights=weights)
output <- list(Models=myModel, Triangle=Triangle, delta=delta,
weights=weights, TriangleName = TriangleName)
output[["call"]] <- match.call(expand.dots = FALSE)
class(output) <- c("ChainLadder", "TriangleModel", class(output))
return(output)
}
Expand Down
53 changes: 48 additions & 5 deletions R/MackChainLadderFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ MackChainLadder <- function(
tail.sigma=NULL,
mse.method = "Mack")
{
TriangleName <- deparse(substitute(Triangle))
## idea: have a list for tail factor
## tail=list(f=FALSE, f.se=NULL, sigma=NULL, F.se=NULL)
##
# 2013-02-25 Parameter risk recursive formula may have a third term per
tail.input <- tail
tail.se.input <- tail.se
tail.sigma.input <- tail.sigma
mse.method.input <- mse.method
# 2013-02-25 Parameter risk recursive formula may have a third term per
# Murphy and BBMW
if (! mse.method %in% c("Mack", "Independence")) stop("mse.method must be 'Mack' or 'Independence'")
if (! est.sigma[1] %in% c("Mack", "log-linear")) {
if (!is.numeric(est.sigma))
stop("est.sigma must be 'Mack' or 'log-linear' or numeric")
}
if (!is.logical(tail) & !is.numeric(tail)) stop("tail must be logical or numeric")

Triangle <- checkTriangle(Triangle)
m <- dim(Triangle)[1]
Expand Down Expand Up @@ -118,6 +128,13 @@ MackChainLadder <- function(
output[["Total.ProcessRisk"]] <- attr(Total.SE, "processrisk")
output[["Total.ParameterRisk"]] <- attr(Total.SE, "paramrisk")
output[["tail"]] <- tail
output[["TriangleName"]] <- TriangleName
output[["est.sigma"]] <- est.sigma
output[["tail.input"]] <- tail.input
output[["tail.se.input"]] <- tail.se.input
output[["tail.sigma.input"]] <- tail.sigma.input
output[["mse.method"]] <- mse.method
output[["mse.method.input"]] <- mse.method.input
class(output) <- c("MackChainLadder", "TriangleModel", "list")
return(output)
}
Expand Down Expand Up @@ -347,15 +364,41 @@ tail.SE <- function(FullTriangle, StdErr, Total.SE, tail.factor, tail.se = NULL,

if(is.null(tail.se)){
.fse <- StdErr$f.se[start:(n-2)]
mse <- lm(log(.fse) ~ .dev)
tail.se <- exp(predict(mse, newdata=data.frame(.dev=tail.pos)))
ndx <- .fse > 0
numpos <- sum(ndx)
if (numpos) {
.devse <- .dev[ndx]
.fse <- .fse[ndx]
mse <- lm(log(.fse) ~ .devse)
if (numpos > 1) tail.se <- exp(predict(mse, newdata=data.frame(.devse=tail.pos)))
else {
warning("Only one column for estimating tail.se")
tail.se <- suppressWarnings(
exp(predict(mse, newdata=data.frame(.dev=tail.pos))))
}
}
else {
warning("No development variability in triangle. Setting tail.se = 0")
tail.se <- 0
}
}
StdErr$f.se <- c(StdErr$f.se, tail.se = tail.se)

if(is.null(tail.sigma)){
.sigma <- StdErr$sigma[start:(n-2)]
msig <- lm(log(.sigma) ~ .dev)
tail.sigma <- exp(predict(msig, newdata = data.frame(.dev = tail.pos)))
ndx <- .sigma > 0
numpos <- sum(ndx)
if (numpos) {
.devsigma <- .dev[ndx]
.sigma <- .sigma[ndx]
msig <- lm(log(.sigma) ~ .devsigma)
if (numpos > 1) tail.sigma <- exp(
predict(msig, newdata = data.frame(.devsigma = tail.pos)))
else {
warning("No development variability in triangle. Setting tail.sigma = 0")
tail.sigma <- 0
}
}
}
StdErr$sigma <- c(StdErr$sigma, tail.sigma = as.numeric(tail.sigma))

Expand Down
Loading