safe {SAFEPG}R Documentation

Solve the sign-aligned frequency-severity (SAFE) model

Description

This function fits a Poisson-Gamma regression framework that aligns the signs of certain predictors in both the Poisson frequency component and the Gamma severity component. The solution path is computed at a sequence of tuning parameter values (lambda).

Usage

safe(
  x,
  y,
  k,
  lambda,
  alpha = 1,
  eps = 1e-08,
  maxit = 1e+05,
  eps2 = 1e-08,
  ind_p,
  int_gam = NULL,
  int_beta = NULL
)

Arguments

x

A numeric matrix of dimensions n \times p, where n is the number of observations and p is the number of predictors.

y

A numeric vector of length n, representing the loss values (severity). These are assumed to follow a Gamma distribution with shape parameter alpha and scale parameter \theta = \exp(x^\top \gamma) / \alpha.

k

A numeric vector of length n, representing the number of claims (frequency), assumed to follow a Poisson distribution with mean \mu = x^\top \beta.

lambda

A user-supplied numeric vector of tuning parameters. The function will compute the solution for each value in lambda.

alpha

The shape parameter for the Gamma distribution (default is 1).

eps

Convergence tolerance for updating beta (default is 1e-8).

maxit

An integer specifying the maximum number of iterations (default is 1e5).

eps2

Convergence tolerance for updating gamma (default is 1e-8).

ind_p

A user-provided vector specifying which predictors should share the same sign across frequency and severity.

int_gam

Optional numeric vector or matrix providing initial values for gamma; defaults to NULL.

int_beta

Optional numeric vector or matrix providing initial values for beta; defaults to NULL.

Details

The function uses an **accelerated proximal gradient descent** algorithm to simultaneously estimate beta (for the Poisson frequency model) and gamma (for the Gamma severity model) under a sign-alignment constraint for selected predictors (controlled by ind_p).

Value

An object of class safe, which is a list containing:

beta

A p \times L matrix of frequency-model coefficients, where p is the number of predictors and L is the number of lambda values.

gamma

A p \times L matrix of severity-model coefficients, with the same dimensions as beta.

lambda

The (sorted) sequence of lambda values used in the estimation.

npass_beta

Total number of iterations used to update beta across all lambda values.

npass_gamma

Total number of iterations used to update gamma across all lambda values.

jerr

An integer flag for warnings or errors; 0 indicates no issues encountered.

Examples

set.seed(1)
n <- 100
p <- 5
x <- matrix(rnorm(n * p), nrow = n, ncol = p)
beta_true <- rep(0.1, 5)
gamma_true <- c(rep(1, 3), -1, -1)
mu <- x %*% beta_true
k <- rpois(n, lambda = exp(mu))
alpha_val <- 1
theta <- exp(x %*% gamma_true) / alpha_val
y <- rgamma(n, shape = alpha_val, scale = theta)
lambda_val <- 1
fit <- safe(x, y, k, 1, ind_p = c(1, 1, 1, 0, 0))


[Package SAFEPG version 0.0.1 Index]