Learn R Programming

cNORM (version 3.6.2)

gradient_shash: Analytic gradient of the negative log-likelihood for a shash regression model

Description

Computes the exact gradient of log_likelihood_shash with respect to all regression coefficients. Supplying this gradient to optim (method "L-BFGS-B") avoids costly and noisy finite-difference approximations, typically yielding a speedup and more reliable convergence.

Usage

gradient_shash(
  params,
  X_mu,
  X_sigma,
  X_epsilon,
  X_delta = NULL,
  y,
  weights = NULL,
  fixed_delta = NULL
)

Value

Numeric vector: gradient of the negative log-likelihood with respect to params.

Arguments

params

A numeric vector containing all model parameters

X_mu

Design matrix for location parameter

X_sigma

Design matrix for scale parameter

X_epsilon

Design matrix for skewness parameter

X_delta

Design matrix for tail weight parameter (or NULL for fixed delta)

y

Response vector

weights

Observation weights

fixed_delta

If not NULL, the delta parameter is fixed to this value

Details

With \(z = (y - \mu)/\sigma\) and \(A = \delta \, \mathrm{asinh}(z) + \epsilon\), the per-observation log-density is $$\ell = \log\delta - \log\sigma - \tfrac{1}{2}\log(2\pi) - \tfrac{1}{2}\log(1+z^2) - \tfrac{1}{2}\sinh^2(A) + \log\cosh(A).$$ The gradient uses the chain rule through the linear predictors: $$\partial\ell/\partial A = \tanh(A) - \sinh(A)\cosh(A)$$ $$\partial\ell/\partial z = -z/(1+z^2) + (\partial\ell/\partial A)\,\delta/\sqrt{1+z^2}$$ $$\partial\ell/\partial\mu = -(\partial\ell/\partial z)/\sigma$$ $$\partial\ell/\partial\log\sigma = -1 - z\,(\partial\ell/\partial z)$$ $$\partial\ell/\partial\epsilon = \partial\ell/\partial A$$ $$\partial\ell/\partial\log\delta = 1 + (\partial\ell/\partial A)\,\delta\,\mathrm{asinh}(z)$$ Coefficient gradients follow as \(-X^\top (w \cdot \partial\ell/\partial\eta)\) for the negative log-likelihood. Contributions of observations whose linear predictor is clamped (see log_likelihood_shash) are zeroed, which is the exact subgradient of the clamped objective. In extreme regions where \(\sinh(A)\cosh(A)\) would overflow, the gradient magnitude is capped at a large finite value; these regions coincide with the penalty branch of the objective, so the capped direction remains correct.