compare_distributions() fits each of several distributions with parametric() and ranks them
by AIC, lowest (best) first. AIC penalizes the log-likelihood by twice the number of parameters,
and BIC by the number of parameters times the log of the number of observations, so BIC favors
simpler distributions more strongly.
Arguments
- formula
A formula with a right-censored
Surv()response on the left and either1or the grouping variables on the right, such asSurv(time, status) ~ 1orSurv(time, status) ~ sex.- 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.
- dists
The distributions to compare. The default is all four:
"weibull","exponential","lognormal", and"loglogistic".
Value
A data frame with one row per distribution, sorted by AIC: dist, n_params, loglik,
aic, and bic.
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)
)
compare_distributions(Surv(time, status) ~ 1, data = lung)
#> dist n_params loglik aic bic
#> 1 lognormal 2 -93.42253 190.8451 192.2612
#> 2 loglogistic 2 -93.57332 191.1466 192.5627
#> 3 exponential 1 -94.99435 191.9887 192.6967
#> 4 weibull 2 -94.12652 192.2530 193.6691