Skip to contents

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.

Usage

compare_distributions(
  formula,
  data,
  weights,
  subset,
  na.action = stats::na.omit,
  dists = c("weibull", "exponential", "lognormal", "loglogistic")
)

Arguments

formula

A formula with a right-censored Surv() response on the left and either 1 or the grouping variables on the right, such as Surv(time, status) ~ 1 or Surv(time, status) ~ sex.

data

A data frame holding the variables in formula.

weights

Optional case weights, a column of data or a numeric vector.

subset

An optional expression selecting the rows of data to 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