% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/weibull_helpers.R
\name{weibull_family}
\alias{weibull_family}
\title{Weibull Family for Survival Model Specification}
\usage{
weibull_family()
}
\value{
A family-like list containing the link functions and Weibull-specific
methods used by \code{lgspline}.
}
\description{
Creates a family-like object for Weibull accelerated failure time (AFT)
models, including custom log-likelihood, AIC, and deviance helpers.

This both provides a tool for actually fitting Weibull AFT Models, and
boilerplate code for users who wish to incorporate Lagrangian multiplier
smoothing splines into their own custom models.
}
\details{
Provides a comprehensive family specification for Weibull AFT models,
including family name, link function, inverse link function, custom loss
function for model tuning, and methods for AIC and log-likelihood
computation compatible with \code{logLik.lgspline}.

Supports right-censored survival data with flexible parameter estimation.

Note on scale vs. dispersion: throughout this package, the lgspline object
stores \code{sigmasq_tilde} which equals sigma^2 (dispersion), where
sigma is the Weibull scale parameter matching \code{survreg$scale}.
Functions that accept a \code{dispersion} argument receive sigma^2;
functions that accept a \code{scale} argument receive sigma.
}
\examples{

## Simulate survival data with covariates
set.seed(1234)
n <- 1000
t1 <- rnorm(n)
t2 <- rbinom(n, 1, 0.5)

## Generate survival times with Weibull-like structure
lambda <- exp(0.5 * t1 + 0.3 * t2)
yraw <- rexp(n, rate = 1/lambda)

## Introduce right-censoring
status <- rbinom(n, 1, 0.75)
y <- ifelse(status, yraw, runif(length(yraw), 0, yraw))

## Prepare data
df <- data.frame(y = y, t1 = t1, t2 = t2, status = status)

## Fit model using custom Weibull family
model_fit <- lgspline(y ~ spl(t1) + t2,
                      df,
                      unconstrained_fit_fxn = unconstrained_fit_weibull,
                      family = weibull_family(),
                      need_dispersion_for_estimation = TRUE,
                      dispersion_function = weibull_dispersion_function,
                      glm_weight_function = weibull_glm_weight_function,
                      schur_correction_function = weibull_schur_correction,
                      status = status,
                      opt = FALSE,
                      K = 1)

summary(model_fit)

## Log-likelihood now works via logLik.lgspline:
# logLik(model_fit)

}
