% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/weibull_helpers.R
\name{weibull_qp_score_function}
\alias{weibull_qp_score_function}
\title{Compute Gradient of Log-Likelihood of Weibull Accelerated Failure Model}
\usage{
weibull_qp_score_function(
  X,
  y,
  mu,
  order_list,
  dispersion,
  VhalfInv,
  observation_weights,
  status
)
}
\arguments{
\item{X}{Design matrix}

\item{y}{Response vector}

\item{mu}{Predicted mean vector}

\item{order_list}{List of observation indices per partition}

\item{dispersion}{Dispersion parameter (sigma^2 = scale^2). The lgspline
framework stores and passes dispersion (sigma^2); the Weibull scale
(sigma) matching \code{survreg$scale} is \code{sqrt(dispersion)}.}

\item{VhalfInv}{Inverse square root of correlation matrix; unused here and
retained for interface compatibility.}

\item{observation_weights}{Observation weights}

\item{status}{Censoring indicator (1 = event, 0 = censored)}
}
\value{
Numeric column vector representing the gradient with respect to
coefficients.
}
\description{
Calculates the gradient of log-likelihood for a Weibull accelerated failure
time (AFT) survival model, supporting right-censored survival data.
}
\details{
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
\code{\link{unconstrained_fit_weibull}}.
}
\examples{

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))

}
