View source: R/weibull_helpers.R
| weibull_qp_score_function | R Documentation |
Calculates the gradient of log-likelihood for a Weibull accelerated failure time (AFT) survival model, supporting right-censored survival data.
weibull_qp_score_function(
X,
y,
mu,
order_list,
dispersion,
VhalfInv,
observation_weights,
status
)
X |
Design matrix |
y |
Response vector |
mu |
Predicted mean vector |
order_list |
List of observation indices per partition |
dispersion |
Dispersion parameter (sigma^2 = scale^2). The lgspline
framework stores and passes dispersion (sigma^2); the Weibull scale
(sigma) matching |
VhalfInv |
Inverse square root of correlation matrix; unused here and retained for interface compatibility. |
observation_weights |
Observation weights |
status |
Censoring indicator (1 = event, 0 = censored) |
Needed if using "blockfit", correlation structures, or quadratic programming with Weibull AFT models.
The gradient is computed on a scale that omits the 1/sigma prefactor.
Specifically, the true score is (1/sigma) * X^T diag(w) (exp(z) - status),
but both this function and the corresponding information matrix used
internally omit 1/sigma and 1/sigma^2 respectively, so the Newton-Raphson
step G*u remains correct. This matches the convention in
unconstrained_fit_weibull.
Numeric column vector representing the gradient with respect to coefficients.
set.seed(1234)
t1 <- rnorm(1000)
t2 <- rbinom(1000, 1, 0.5)
yraw <- rexp(exp(0.01*t1 + 0.01*t2))
status <- rbinom(1000, 1, 0.25)
yobs <- ifelse(status, runif(length(yraw), 0, yraw), yraw)
df <- data.frame(
y = yobs,
t1 = t1,
t2 = t2
)
## Example using blockfit for t2 as a linear term - output does not look
# different, but internal methods used for fitting change
model_fit <- lgspline(y ~ spl(t1) + t2,
df,
unconstrained_fit_fxn = unconstrained_fit_weibull,
family = weibull_family(),
need_dispersion_for_estimation = TRUE,
qp_score_function = weibull_qp_score_function,
dispersion_function = weibull_dispersion_function,
glm_weight_function = weibull_glm_weight_function,
schur_correction_function = weibull_schur_correction,
K = 1,
blockfit = TRUE,
opt = FALSE,
status = status,
verbose = TRUE)
print(summary(model_fit))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.