Skip to contents

Fit a single-level random effects model using Ohlsson's methodology combined with Buhlmann-Straub credibility. This function estimates the power parameter p. For fixed p, see buhlmannStraubGLM.

Usage

buhlmannStraubTweedie(
  formula,
  data,
  weights,
  muHatGLM = FALSE,
  epsilon = 1e-04,
  maxiter = 500,
  verbose = FALSE,
  returnData = TRUE,
  cpglmControl = list(bound.p = c(1.01, 1.99)),
  balanceProperty = TRUE,
  optimizer = "bobyqa",
  y = TRUE,
  ...
)

Arguments

formula

object of type formula that specifies which model should be fitted. Syntax follows lmer: e.g., Y ~ x1 + x2 + (1 | Cluster). Only one random effect is allowed.

data

an object that is coercible by as.data.table, containing the variables in the model.

weights

variable name of the exposure weight.

muHatGLM

indicates which estimate has to be used in the algorithm for the intercept term. Default is TRUE, which uses the intercept as estimated by the GLM. If FALSE, the estimate of the Buhlmann-Straub credibility model is used.

epsilon

positive convergence tolerance \(\epsilon\); the iterations converge when \(||\theta[k] - \theta[k - 1]||^2_2/||\theta[k - 1]||^2_2 < \epsilon\). Here, \(\theta[k]\) is the parameter vector at the \(k^{th}\) iteration.

maxiter

maximum number of iterations.

verbose

logical indicating if output should be produced during the algorithm.

returnData

logical indicating if input data has to be returned.

cpglmControl

a list of parameters to control the fitting process in the GLM part. By default, cpglmControl = list(bound.p = c(1.01, 1.99)) which restricts the range of the power parameter p to [1.01, 1.99] in the fitting process. This list is passed to cpglm.

balanceProperty

logical indicating if the balance property should be satisfied.

optimizer

a character string that determines which optimization routine is to be used in estimating the index and the dispersion parameters. Possible choices are "nlminb" (the default, see nlminb), "bobyqa" (bobyqa) and "L-BFGS-B" (optim).

y

logical indicating whether the response vector should be returned as a component of the returned value.

...

arguments passed to cpglm.

Value

An object of type buhlmannStraubTweedie with the following slots:

call

the matched call

CredibilityResults

results of the Buhlmann-Straub credibility model.

fitGLM

the results from fitting the GLM part.

iter

total number of iterations.

Converged

logical indicating whether the algorithm converged.

LevelsCov

object that summarizes the unique levels of each of the contract-specific covariates.

fitted.values

the fitted mean values, resulting from the model fit.

prior.weights

the weights (exposure) initially supplied.

y

if requested, the response vector. Default is TRUE.

Details

When estimating the GLM part, this function uses the cpglm function from the cplm package.

References

Campo, B.D.C. and Antonio, Katrien (2023). Insurance pricing with hierarchically structured data an illustration with a workers' compensation insurance portfolio. Scandinavian Actuarial Journal, doi: 10.1080/03461238.2022.2161413

Ohlsson, E. (2008). Combining generalized linear models and credibility models in practice. Scandinavian Actuarial Journal 2008(4), 301–314.

Examples

# \donttest{
data("hachemeister", package = "actuar")
X = as.data.frame(hachemeister)
Df = reshape(X, idvar = "state",
             varying = list(paste0("ratio.", 1:12), paste0("weight.", 1:12)),
             direction = "long")
Df$time_factor = factor(Df$time)
fit = buhlmannStraubTweedie(ratio.1 ~ time_factor + (1 | state), Df,
                            weights = weight.1, epsilon = 1e-6)
summary(fit)
#> Call:
#> buhlmannStraubTweedie(formula = ratio.1 ~ time_factor + (1 | 
#>     state), data = Df, weights = weight.1, epsilon = 1e-06)
#> 
#> Buhlmann-Straub GLM credibility model
#> 
#> Convergence: YES 
#> Number of iterations: 1 
#> 
#> GLM Summary:
#> 
#> Call:
#> cpglm(formula = FormulaGLM, link = "log", data = data, weights = wijt, 
#>     control = cpglmControl, optimizer = optimizer)
#> 
#> Deviance Residuals: 
#>     Min       1Q   Median       3Q      Max  
#> -7.2786  -3.3640  -0.2093   2.7724   7.3722  
#>               Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)    7.29185    0.03283 222.110  < 2e-16 ***
#> time_factor2  -0.02806    0.04496  -0.624  0.53559    
#> time_factor3   0.03713    0.04563   0.814  0.41979    
#> time_factor4   0.13948    0.04581   3.045  0.00377 ** 
#> time_factor5   0.10482    0.04675   2.242  0.02961 *  
#> time_factor6   0.20275    0.04621   4.388 6.25e-05 ***
#> time_factor7   0.11751    0.04469   2.630  0.01145 *  
#> time_factor8   0.12363    0.04656   2.655  0.01072 *  
#> time_factor9   0.14512    0.04749   3.056  0.00366 ** 
#> time_factor10  0.21735    0.04637   4.688 2.31e-05 ***
#> time_factor11  0.21841    0.04621   4.726 2.03e-05 ***
#> time_factor12  0.26804    0.04499   5.957 2.91e-07 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Estimated dispersion parameter: 12.816
#> Estimated index parameter: 1.99 
#> 
#> Residual deviance: 770.48  on 48  degrees of freedom
#> AIC:  783.6 
#> 
#> Number of Fisher Scoring iterations:  3 
#> 
#> $call
#> cpglm(formula = FormulaGLM, link = "log", data = data, weights = wijt, 
#>     control = cpglmControl, optimizer = optimizer)
#> 
#> $deviance
#> [1] 770.478
#> 
#> $aic
#> [1] 783.6048
#> 
#> $contrasts
#> NULL
#> 
#> $df.residual
#> [1] 48
#> 
#> $iter
#> [1] 3
#> 
#> $na.action
#> NULL
#> 
#> $deviance.resid
#>        Min         1Q     Median         3Q        Max 
#> -7.2786310 -3.3640231 -0.2093476  2.7724228  7.3722355 
#> 
#> $coefficients
#>                  Estimate Std. Error     t value     Pr(>|t|)
#> (Intercept)    7.29184528 0.03282995 222.1095403 5.803464e-74
#> time_factor2  -0.02805756 0.04496471  -0.6239906 5.355882e-01
#> time_factor3   0.03713326 0.04563054   0.8137808 4.197892e-01
#> time_factor4   0.13948337 0.04580521   3.0451420 3.769762e-03
#> time_factor5   0.10482312 0.04675199   2.2421103 2.961096e-02
#> time_factor6   0.20274576 0.04620709   4.3877632 6.250758e-05
#> time_factor7   0.11751226 0.04468803   2.6296136 1.145192e-02
#> time_factor8   0.12363370 0.04656070   2.6553229 1.071958e-02
#> time_factor9   0.14512278 0.04749198   3.0557324 3.660300e-03
#> time_factor10  0.21735047 0.04636633   4.6876786 2.314848e-05
#> time_factor11  0.21840927 0.04621094   4.7263540 2.033516e-05
#> time_factor12  0.26804259 0.04499488   5.9571792 2.914561e-07
#> 
#> $dispersion
#> [1] 12.81641
#> 
#> $vcov
#>                (Intercept) time_factor2 time_factor3 time_factor4 time_factor5
#> (Intercept)    0.001077806 -0.001077806 -0.001077806 -0.001077806 -0.001077806
#> time_factor2  -0.001077806  0.002021825  0.001077806  0.001077806  0.001077806
#> time_factor3  -0.001077806  0.001077806  0.002082147  0.001077806  0.001077806
#> time_factor4  -0.001077806  0.001077806  0.001077806  0.002098117  0.001077806
#> time_factor5  -0.001077806  0.001077806  0.001077806  0.001077806  0.002185749
#> time_factor6  -0.001077806  0.001077806  0.001077806  0.001077806  0.001077806
#> time_factor7  -0.001077806  0.001077806  0.001077806  0.001077806  0.001077806
#> time_factor8  -0.001077806  0.001077806  0.001077806  0.001077806  0.001077806
#> time_factor9  -0.001077806  0.001077806  0.001077806  0.001077806  0.001077806
#> time_factor10 -0.001077806  0.001077806  0.001077806  0.001077806  0.001077806
#> time_factor11 -0.001077806  0.001077806  0.001077806  0.001077806  0.001077806
#> time_factor12 -0.001077806  0.001077806  0.001077806  0.001077806  0.001077806
#>               time_factor6 time_factor7 time_factor8 time_factor9 time_factor10
#> (Intercept)   -0.001077806 -0.001077806 -0.001077806 -0.001077806  -0.001077806
#> time_factor2   0.001077806  0.001077806  0.001077806  0.001077806   0.001077806
#> time_factor3   0.001077806  0.001077806  0.001077806  0.001077806   0.001077806
#> time_factor4   0.001077806  0.001077806  0.001077806  0.001077806   0.001077806
#> time_factor5   0.001077806  0.001077806  0.001077806  0.001077806   0.001077806
#> time_factor6   0.002135095  0.001077806  0.001077806  0.001077806   0.001077806
#> time_factor7   0.001077806  0.001997020  0.001077806  0.001077806   0.001077806
#> time_factor8   0.001077806  0.001077806  0.002167899  0.001077806   0.001077806
#> time_factor9   0.001077806  0.001077806  0.001077806  0.002255488   0.001077806
#> time_factor10  0.001077806  0.001077806  0.001077806  0.001077806   0.002149837
#> time_factor11  0.001077806  0.001077806  0.001077806  0.001077806   0.001077806
#> time_factor12  0.001077806  0.001077806  0.001077806  0.001077806   0.001077806
#>               time_factor11 time_factor12
#> (Intercept)    -0.001077806  -0.001077806
#> time_factor2    0.001077806   0.001077806
#> time_factor3    0.001077806   0.001077806
#> time_factor4    0.001077806   0.001077806
#> time_factor5    0.001077806   0.001077806
#> time_factor6    0.001077806   0.001077806
#> time_factor7    0.001077806   0.001077806
#> time_factor8    0.001077806   0.001077806
#> time_factor9    0.001077806   0.001077806
#> time_factor10   0.001077806   0.001077806
#> time_factor11   0.002135451   0.001077806
#> time_factor12   0.001077806   0.002024540
#> 
#> $p
#> [1] 1.99
#> 
#> 
#> Variance parameters from Buhlmann-Straub model:
#>   Sigma (within-group variance): 27306678 
#>   Tau (between-group variance): 68336.47 
#> 
#> Random effects at the state level:
#> 
#> Key: <state>
#>    state        zj        Uj
#>    <num>     <num>     <num>
#> 1:     1 0.9960315 1.2268815
#> 2:     2 0.9803370 0.9056788
#> 3:     3 0.9717653 1.0806732
#> 4:     4 0.9123138 0.8281616
#> 5:     5 0.9890701 0.9586048
ranef(fit)
#> $MLFj
#> Key: <state>
#>    state        Uj
#>    <num>     <num>
#> 1:     1 1.2268815
#> 2:     2 0.9056788
#> 3:     3 1.0806732
#> 4:     4 0.8281616
#> 5:     5 0.9586048
#> 
fixef(fit)
#>   (Intercept)  time_factor2  time_factor3  time_factor4  time_factor5 
#>    7.29184528   -0.02805756    0.03713326    0.13948337    0.10482312 
#>  time_factor6  time_factor7  time_factor8  time_factor9 time_factor10 
#>    0.20274576    0.11751226    0.12363370    0.14512278    0.21735047 
#> time_factor11 time_factor12 
#>    0.21840927    0.26804259 
# }