Skip to content

Commit

Permalink
Effects names and exponentiation of the effects updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
gpitt71 committed Apr 24, 2024
1 parent b4ffb2c commit 261cf0a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
9 changes: 8 additions & 1 deletion R/clmplusAggregateDataPP.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#' age terms, \code{"1"} for \eqn{\beta_x^{(0)}=1}, a predefined parametric
#' function of age (see details) or \code{NULL} if there is no cohort effect.
#' To be disregarded unless the practitioner specifies his own hazard model in StMoMo.
#' @param effect_log_scale \code{logical}, whether effects should be on the logarithmic scale. By default, \code{TRUE}.
#' @param constFun \code{function}, it defines the identifiability constraints of the
#' model. It must be a function of the form
#' \code{constFun <- function(ax, bx, kt, b0x, gc, wxt, ages)} taking a set
Expand Down Expand Up @@ -59,6 +60,7 @@ clmplus <- function(AggregateDataPP,
staticAgeFun = TRUE,
periodAgeFun = "NP",
cohortAgeFun = NULL,
effect_log_scale=TRUE,
constFun = function(ax, bx, kt, b0x, gc, wxt, ages) list(ax = ax, bx = bx, kt = kt, b0x = b0x, gc = gc),
...){

Expand Down Expand Up @@ -96,6 +98,7 @@ clmplus <- function(AggregateDataPP,
#' age terms, \code{"1"} for \eqn{\beta_x^{(0)}=1}, a predefined parametric
#' function of age (see details) or \code{NULL} if there is no cohort effect.
#' To be disregarded unless the practitioner specifies his own hazard model in StMoMo.
#' @param effect_log_scale \code{logical}, whether effects should be on the logarithmic scale. By default, \code{TRUE}.
#' @param constFun \code{function}, it defines the identifiability constraints of the
#' model. It must be a function of the form
#' \code{constFun <- function(ax, bx, kt, b0x, gc, wxt, ages)} taking a set
Expand All @@ -122,6 +125,7 @@ clmplus.default <- function(AggregateDataPP,
staticAgeFun = TRUE,
periodAgeFun = "NP",
cohortAgeFun = NULL,
effect_log_scale=TRUE,
constFun = function(ax, bx, kt, b0x, gc, wxt, ages) list(ax = ax, bx = bx, kt = kt, b0x = b0x, gc = gc),
...){message('The object provided must be of class AggregateDataPP')}

Expand Down Expand Up @@ -157,6 +161,7 @@ clmplus.default <- function(AggregateDataPP,
#' age terms, \code{"1"} for \eqn{\beta_x^{(0)}=1}, a predefined parametric
#' function of age (see details) or \code{NULL} if there is no cohort effect.
#' To be disregarded unless the practitioner specifies his own hazard model in StMoMo.
#' @param effect_log_scale \code{logical}, whether effects should be on the logarithmic scale. By default, \code{TRUE}.
#' @param constFun \code{function}, it defines the identifiability constraints of the
#' model. It must be a function of the form
#' \code{constFun <- function(ax, bx, kt, b0x, gc, wxt, ages)} taking a set
Expand Down Expand Up @@ -197,6 +202,7 @@ clmplus.AggregateDataPP <- function(AggregateDataPP,
staticAgeFun = TRUE,
periodAgeFun = "NP",
cohortAgeFun = NULL,
effect_log_scale=TRUE,
constFun = function(ax, bx, kt, b0x, gc, wxt, ages) list(ax = ax, bx = bx, kt = kt, b0x = b0x, gc = gc),
...){

Expand Down Expand Up @@ -278,7 +284,8 @@ clmplus.AggregateDataPP <- function(AggregateDataPP,
fitted_effects <- pkg.env$find.fitted.effects(J,
age.eff= model$ax,
cohort.eff= model$gc,
period.eff=model$kt)
period.eff=model$kt,
effect_log_scale=effect_log_scale)

}

Expand Down
9 changes: 6 additions & 3 deletions R/globalVariables.R
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,13 @@ pkg.env$find.development.factors <- function(J,
pkg.env$find.fitted.effects <- function(J,
age.eff,
period.eff,
cohort.eff){
cohort.eff,
effect_log_scale){

# Function that finds the fitted effects.

ax <- c(NA,age.eff[!is.na(age.eff)])
names(ax) <- c(1:length(ax))
names(ax) <- c(0:(length(ax)-1))

if(!is.null(cohort.eff)){
gc <- c(cohort.eff[!is.na(cohort.eff)],NA) #last cohort effect will be extrapolated
Expand All @@ -688,7 +689,7 @@ pkg.env$find.fitted.effects <- function(J,
if(!is.null(period.eff)){

kt <- c(NA,period.eff[!is.na(period.eff)]) #the first period is disregarded
names(kt) <- c(1:length(kt))
names(kt) <- c(0:(length(kt)-1))

}else{kt<-NULL}

Expand All @@ -698,6 +699,8 @@ pkg.env$find.fitted.effects <- function(J,
fitted_accident_effect= gc
)

if(effect_log_scale==FALSE){out<-lapply(out,exp)}

return(out)


Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ datapp = AggregateDataPP(cumulative.payments.triangle = dataset, eta= 1/2)
```
a.model.fit=clmplus(datapp,
hazard.model = "a") # age-model replicates the chain ladder
ac.model.fit=clmplus(datapp,
hazard.model = "ac")
Expand All @@ -85,21 +86,28 @@ plot(apc.model.fit)
Predictions are performed with the `predict` function.

```
a.model=predict(a.model.fit)
# clmplus reserve (age model)
sum(a.model$reserve)
#226875.5
ac.model=predict(ac.model.fit,
gk.fc.model = 'a',
gk.order = c(1,1,0))
# clmplus reserve (age-cohort model)
sum(ac.model$reserve)
#38126.05
#205305.7
ap.model<- predict(ap.model.fit,
ckj.fc.model = 'a',
ckj.order = c(0,1,0))
# clmplus reserve (age-period model)
sum(ap.model$reserve)
#37375.01
#215602.8
apc.model<-predict(apc.model.fit,
Expand All @@ -109,7 +117,7 @@ apc.model<-predict(apc.model.fit,
ckj.order = c(0,1,0))
# clmplus reserve (age-period-cohort model)
sum(apc.model$reserve)
#38498.54
#213821.6
```

The fitted effect (and extrapolated) effects can be inspected with the `plot` function. We continue below the example with the `apc` model.
Expand Down
3 changes: 3 additions & 0 deletions man/clmplus.AggregateDataPP.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/clmplus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/clmplus.default.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 261cf0a

Please sign in to comment.