aft() fits a parametric accelerated failure time (AFT) model by maximum likelihood. The log of
the event time is modeled as \(\log T = x^\top \beta + \sigma \varepsilon\), where the error
\(\varepsilon\) has a fixed distribution and \(\sigma\) is the scale. A coefficient
\(\beta_j\) multiplies every quantile of the survival time by \(\exp(\beta_j)\) for a
one-unit increase in its covariate, so \(\exp(\beta_j)\) is a time ratio.
Arguments
- formula
A formula with a right-censored
Surv()response on the left and the covariates on the right, such asSurv(time, status) ~ age + sex. Factors are coded with treatment contrasts, and an intercept is always included.- data
A data frame holding the variables in
formula.- weights
Optional case weights, a column of
dataor a numeric vector.- subset
An optional expression selecting the rows of
datato use.- na.action
What to do with rows that have missing values. The default drops them.
- dist
The error distribution:
"weibull"(the default),"exponential","lognormal","loglogistic", or"gengamma"(the generalized gamma).- threshold
Estimate a threshold (a third, location parameter). Not available for the generalized gamma. The default is
FALSE.- conf_level
The confidence level, between 0 and 1. The default is
0.95.- max_iter
The largest number of Newton-Raphson iterations. The default is
50.- tol
The convergence tolerance: iterations stop once the log-likelihood changes by less than
toltimes its size. The default is1e-10.
Value
An aft object. Use as.data.frame() for the coefficient table, coef() and vcov()
for the estimates and their variance, predict() for linear predictors, quantiles, survival
curves, and means, and residuals() for diagnostics. logLik(), AIC(), BIC(), and
nobs() work as usual.
The object also holds scale (\(\sigma\)), Q (the generalized gamma's shape, NULL for
the other distributions), threshold (\(\gamma\), 0 without threshold = TRUE), loglik
(the log-likelihood of the intercept-only model and of the fit), the likelihood ratio test
lr_test (with statistic, df, and p_value), n, n_event, iterations, and
converged. vcov() covers \(\beta\), \(\log \sigma\) (except for the exponential),
\(Q\) (for the generalized gamma), and \(\gamma\) (with threshold = TRUE).
Details
The distributions are the Weibull (an extreme-value error), the exponential (the Weibull with \(\sigma = 1\)), the log-normal (a normal error), the log-logistic (a logistic error), and the generalized gamma. The estimates come from Newton-Raphson iterations on \((\beta, \log \sigma)\), halving the step whenever it lowers the likelihood, and the variance is the inverse of the observed information on that scale. The log-likelihood is on the time scale, so it's comparable across distributions and with other parametric models.
The generalized gamma (Prentice's parameterization) has a third parameter, the shape \(Q\).
With \(k = Q^{-2}\), its error has the density
\(|Q| k^k \exp(k (Q \varepsilon - e^{Q \varepsilon})) / \Gamma(k)\). It's the Weibull at
\(Q = 1\), the exponential at \(Q = 1\) and \(\sigma = 1\), and the log-normal in the
limit \(Q \to 0\), so test_distributions() can test those simpler distributions against it.
Newton-Raphson starts from the best of the fits with \(Q\) fixed on a grid from -3 to 3 and
then moves \((\beta, \log \sigma, Q)\) together. The derivatives in \(Q\) are numerical,
and those in the other parameters are exact.
With threshold = TRUE the model has a third parameter, a threshold \(\gamma \ge 0\) below
which no events happen: \(T = \gamma + T'\), where \(T'\) follows the AFT model. The
threshold is estimated by maximizing the profile likelihood over \(0 \le \gamma < t_{(1)}\),
the smallest observed time, and its variance comes from the observed information of all the
parameters. For some distributions the likelihood grows without bound as \(\gamma\) nears
\(t_{(1)}\), and a warning says so when the estimate lands there.
Examples
lung <- data.frame(
time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654, 728, 71, 567),
status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2),
age = c(74, 68, 56, 57, 60, 74, 68, 71, 53, 61, 57, 68, 68, 60, 57),
sex = c(1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1)
)
fit <- aft(Surv(time, status) ~ age + sex, data = lung)
fit
#> <aft> Surv(time, status) ~ age + sex
#> Weibull distribution. n = 15, events = 13
#>
#> estimate time_ratio std_error statistic p_value
#> (Intercept) 4.89736 133.9361 1.98678 2.4650 0.0137
#> age 0.02868 1.0291 0.03528 0.8130 0.4162
#> sex -0.29725 0.7429 0.50251 -0.5915 0.5542
#>
#> Scale: 0.714 (std. error of log(scale) 0.226)
#> Log-likelihood: -93.7272
#> Likelihood ratio test: 0.799 on 2 df, p = 0.671
# Time ratios with confidence limits
as.data.frame(fit, exponentiate = TRUE)
#> term estimate std_error statistic p_value conf_low conf_high
#> 1 (Intercept) 133.9360915 1.98677674 2.4649789 0.01370213 2.7274085 6577.26057
#> 2 age 1.0290976 0.03527749 0.8130474 0.41619091 0.9603472 1.10277
#> 3 sex 0.7428597 0.50251440 -0.5915216 0.55417100 0.2774379 1.98906
# A log-normal model, and the median survival time of two new subjects
fit_lognormal <- aft(Surv(time, status) ~ age + sex, data = lung, dist = "lognormal")
predict(fit_lognormal, newdata = data.frame(age = c(55, 70), sex = c(1, 2)), type = "quantile")
#> subject p estimate std_error conf_low conf_high
#> 1 1 0.5 286.4148 96.93185 147.5441 555.9927
#> 2 2 0.5 503.0527 203.71084 227.4678 1112.5177
# The generalized gamma, and tests of the distributions it nests
fit_gengamma <- aft(Surv(time, status) ~ age + sex, data = lung, dist = "gengamma")
test_distributions(fit_gengamma)
#> dist loglik aic lr_statistic df p_value
#> 1 weibull -93.72721 195.4544 2.568865 1 0.1089859
#> 2 lognormal -92.76129 193.5226 0.637024 1 0.4247905
#> 3 exponential -94.68633 195.3727 4.487104 2 0.1060810