Function cumhazPlot uses the cumulative hazard plot to check if a certain distribution is an appropiate choice for the data.

# Default S3 method
cumhazPlot(times, cens = rep(1, length(times)), distr = "all6", colour = 1,
           betaLimits = c(0, 1), igumb = c(10, 10), ggp = FALSE, m = NULL,
           prnt = TRUE, degs = 3, print.AIC = TRUE, print.BIC = TRUE,...)
# S3 method for class 'formula'
cumhazPlot(formula, data, ...)

Arguments

times

Numeric vector of times until the event of interest.

cens

Status indicator (1, exact time; 0, right-censored time). If not provided, all times are assumed to be exact.

distr

A string specifying the names of the distributions to be studied. The possible distributions are the exponential ("exponential"), the Weibull ("weibull"), the Gumbel ("gumbel"), the normal ("normal"), the lognormal ("lognormal"), the logistic ("logistic"), the loglogistic ("loglogistic"), and the beta ("beta") distribution. By default, distr is set to "all6", which means that the cumulative hazard plots are drawn for the Weibull, loglogistic, lognormal, Gumbel, logistic, and normal distributions.

colour

Colour of the points. Default colour: black.

betaLimits

Two-components vector with the lower and upper bounds of the Beta distribution. This argument is only required, if the beta distribution is considered.

igumb

Two-components vector with the initial values for the estimation of the Gumbel distribution parameters.

ggp

Logical to use or not the ggplot2 package to draw the plots. Default is FALSE.

m

Optional layout for the plots to be displayed.

prnt

Logical to indicate if the maximum likelihood estimates of the parameters of all distributions considered should be printed. Default is TRUE.

degs

Integer indicating the number of decimal places of the numeric results of the output.

formula

A formula with a numeric vector as response (which assumes no censoring) or Surv object.

data

Data frame for variables in formula.

print.AIC

Logical to indicate if the AIC of the model should be printed. Default is TRUE

print.BIC

Logical to indicate if the BIC of the model should be printed. Default is TRUE

...

Optional arguments for function par, if ggplo = FALSE.

Details

The cumulative hazard plot is based on transforming the cumulative hazard function \(\Lambda\) in such a way that it becomes linear in \(t\) or \(\log(t)\). This transformation is specific for each distribution. The function uses the data to compute the Nelson-Aalen estimator of the cumulative hazard function, \(\widehat{\Lambda}\), and the maximum likelihood estimators of the parameters of the theoretical distribution under study. If the distribution fits the data, the plot is expected to be a straight line.

The parameter estimation is acomplished with the fitdistcens function of the fitdistrplus package.

Value

If prnt = TRUE, the following output is returned:

Distribution

Distribution under study.

Estimates

A list with the maximum likelihood estimates of the parameters of all distributions considered.

StdErrors

Vector containing the estimated standard errors.

aic

The Akaike information criterion.

bic

The so-called BIC or SBC (Schwarz Bayesian criterion).

In addition, a list with the same contents is returned invisibly.

Author

K. Langohr, M. Besalú, M. Francisco, A. Garcia, G. Gómez.

Examples

# Complete data and default distributions
set.seed(123)
x <- rlogis(1000, 50, 5)
cumhazPlot(x, lwd = 2)
#> Parameter estimates
#>   
#> weibull
#>    Shape (se): 5.934 (0.136)
#>    Scale (se): 53.593 (0.302)
#>    AIC: 7287.137 
#>    BIC: 7296.952 
#> 
#> loglogistic
#>    Shape (se): 9.732 (0.258)
#>    Scale (se): 49.592 (0.277)
#>    AIC: 7258.912 
#>    BIC: 7268.728 
#> 
#> lognormal
#> Location (se): 3.892 (0.006)
#>    Scale (se): 0.197 (0.004)
#>    AIC: 7374.022 
#>    BIC: 7383.838 
#> 
#> gumbel
#> Location (se): 45.364 (0.334)
#>    Scale (se): 9.963 (0.205)
#>    AIC: 7512.212 
#>    BIC: 7522.028 
#> 
#> logistic
#> Location (se): 49.919 (0.272)
#>    Scale (se): 4.962 (0.131)
#>    AIC: 7207.713 
#>    BIC: 7217.529 
#> 
#> normal
#> Location (se): 49.899 (0.285)
#>    Scale (se): 9.002 (0.201)
#>    AIC: 7236.688 
#>    BIC: 7246.504 
#> 


# Censored data comparing three distributions
data(nba)
cumhazPlot(Surv(survtime, cens) ~ 1, nba, distr = c("expo", "normal", "gumbel"))
#> Parameter estimates
#>   
#> exponential
#>    Scale (se): 123.133 (4.189)
#>    AIC: 10047.32 
#>    BIC: 10053.6 
#> 
#> normal
#> Location (se): 53.004 (0.518)
#>    Scale (se): 16.977 (0.368)
#>    AIC: 8512.579 
#>    BIC: 8525.148 
#> 
#> gumbel
#> Location (se): 47.493 (0.626)
#>    Scale (se): 22.362 (0.489)
#>    AIC: 8773.697 
#>    BIC: 8786.266 
#>