From 261cf0abb8c4260c83a6f093567081633a4f8e32 Mon Sep 17 00:00:00 2001 From: gpitt71 <93520106+gpitt71@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:36:35 +0200 Subject: [PATCH] Effects names and exponentiation of the effects updated. --- R/clmplusAggregateDataPP.R | 9 ++++++++- R/globalVariables.R | 9 ++++++--- README.md | 14 +++++++++++--- man/clmplus.AggregateDataPP.Rd | 3 +++ man/clmplus.Rd | 3 +++ man/clmplus.default.Rd | 3 +++ 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/R/clmplusAggregateDataPP.R b/R/clmplusAggregateDataPP.R index 5e4c3c1..a234c83 100644 --- a/R/clmplusAggregateDataPP.R +++ b/R/clmplusAggregateDataPP.R @@ -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 @@ -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), ...){ @@ -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 @@ -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')} @@ -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 @@ -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), ...){ @@ -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) } diff --git a/R/globalVariables.R b/R/globalVariables.R index aebc491..0747789 100644 --- a/R/globalVariables.R +++ b/R/globalVariables.R @@ -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 @@ -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} @@ -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) diff --git a/README.md b/README.md index c6e12cc..6d384d9 100644 --- a/README.md +++ b/README.md @@ -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") @@ -85,13 +86,20 @@ 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', @@ -99,7 +107,7 @@ ap.model<- predict(ap.model.fit, # clmplus reserve (age-period model) sum(ap.model$reserve) -#37375.01 +#215602.8 apc.model<-predict(apc.model.fit, @@ -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. diff --git a/man/clmplus.AggregateDataPP.Rd b/man/clmplus.AggregateDataPP.Rd index c543535..ccf4165 100644 --- a/man/clmplus.AggregateDataPP.Rd +++ b/man/clmplus.AggregateDataPP.Rd @@ -11,6 +11,7 @@ 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), ... @@ -50,6 +51,8 @@ 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.} +\item{effect_log_scale}{\code{logical}, whether effects should be on the logarithmic scale. By default, \code{TRUE}.} + \item{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 diff --git a/man/clmplus.Rd b/man/clmplus.Rd index cd9534b..b521ff6 100644 --- a/man/clmplus.Rd +++ b/man/clmplus.Rd @@ -11,6 +11,7 @@ clmplus( 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), ... @@ -50,6 +51,8 @@ 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.} +\item{effect_log_scale}{\code{logical}, whether effects should be on the logarithmic scale. By default, \code{TRUE}.} + \item{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 diff --git a/man/clmplus.default.Rd b/man/clmplus.default.Rd index c1e7484..8fcac6f 100644 --- a/man/clmplus.default.Rd +++ b/man/clmplus.default.Rd @@ -11,6 +11,7 @@ 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), ... @@ -50,6 +51,8 @@ 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.} +\item{effect_log_scale}{\code{logical}, whether effects should be on the logarithmic scale. By default, \code{TRUE}.} + \item{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