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 |
y |
A numeric vector of length |
k |
A numeric vector of length |
lambda |
A user-supplied numeric vector of tuning parameters. The function will compute the solution
for each value in |
alpha |
The shape parameter for the Gamma distribution (default is 1). |
eps |
Convergence tolerance for updating |
maxit |
An integer specifying the maximum number of iterations (default is |
eps2 |
Convergence tolerance for updating |
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 |
int_beta |
Optional numeric vector or matrix providing initial values for |
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 |
gamma |
A |
lambda |
The (sorted) sequence of |
npass_beta |
Total number of iterations used to update |
npass_gamma |
Total number of iterations used to update |
jerr |
An integer flag for warnings or errors; |
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))