Function KScens computes the Kolmogorov-Smirnov statistic and p-value for complete and right-censored data against eight possible distributions using either bootsrapping or a modified test.

# Default S3 method
KScens(times, cens = rep(1, length(times)),
       distr = c("exponential", "gumbel", "weibull", "normal",
                 "lognormal", "logistic", "loglogistic", "beta"),
       betaLimits = c(0, 1), igumb = c(10, 10), BS = 999,
       params0 = list(shape = NULL, shape2 = NULL, location = NULL,
                      scale = NULL),
       tol = 1e-04, boot = TRUE, ...)
# S3 method for class 'formula'
KScens(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 name of the distribution 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.

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.

BS

Number of bootstrap samples.

params0

List specifying the parameters of the theoretical distribution. By default, parameters are set to NULL and estimated with the maximum likelihood method. This argument is only considered, if all parameters of the studied distribution are specified.

tol

Precision of survival times.

formula

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

data

Data frame for variables in formula.

boot

Logical to indicate if the p-value is computed using bootstrapping or using the the modified Kolmogorov-Smirnov test (see details). Default is TRUE.

...

Additional arguments.

Details

By default the p-value is computed via bootstrapping methods.

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

To avoid long computation times due to bootstrapping, an alternative with complete data is the function ks.test of the stats package.

The precision of the survival times is important mainly in the data generation step of the bootstrap samples.

If boot = FALSE a modified test is used to compute the p-value. Fleming et al. (1980) proposed a modified Kolmogorov-Smirnov test to use with right-censored data. This function reproduces this test for a given survival data and a theorical distribution. The approximation for the p-value is acceptable when it is smaller than 0.8 and excellent when it is smaller than 0.2. The output of the function follows the notation of Fleming et al. (1980).

In presence of ties, different authors provide slightly different definitions of \(\widehat{F}_n(t)\), with which other values of the test statistic might be obtained.

Value

KScens returns an object of class "KScens".

An object of class "KScens" is a list containing the following components:

Distribution

Null distribution.

Hypothesis

Parameters under the null hypothesis (if params0 is provided).

Test

Vector containing the value of the modified Kolmogorov-Smirnov statistic (A), the estimated p-value (p-value), the estimation of the image of the last recorded time (F(y_m)) and the last recorded time (y_m).

Estimates

Vector with the maximum likelihood estimates of the parameters of the distribution under study.

StdErrors

Vector containing the estimated standard errors.

aic

The Akaike information criterion.

bic

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

BS

The number of bootstrap samples used. If the modified test is used, a 0 is returned.

References

T. R. Fleming et al. Modified Kolmogorov-Smirnov test procedure with application to arbitrarily right-censored data. In: Biometrics 36 (1980), 607-625.

Author

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

See also

Function ks.test (Package stats) for complete data and gofcens for statistics and p-value of Kolmogorov-Smirnov, Cramér von-Mises and Anderson-Darling together for right-censored data.

Examples

# Complete data with bootstrapping
set.seed(123)
KScens(times = rweibull(100, 12, scale = 4), distr = "weibull", BS = 99)
#> Distribution: weibull 
#> 
#> KS Test results:
#>       A p-value 
#>   0.528   0.670 
#> 
#> Parameter estimates (se):
#> shape             scale             
#> 12.241 (0.938)     4 (0.034)     
#> 
#> AIC: 84.375 
#> BIC: 89.585 
#> 

# Censored data with bootstrapping
KScens(Surv(time, status) ~ 1, colon, distr = "norm", BS = 99)
#> Distribution: normal 
#> 
#> KS Test results:
#>       A p-value 
#>   8.707   0.010 
#> 
#> Parameter estimates (se):
#> location          scale             
#> 2189.942 (47.565)     1662.442 (44.129)     
#> 
#> AIC: 17621.96 
#> BIC: 17633.01 
#> 

# Censored data using the modified test
KScens(Surv(time, status) ~ 1, colon, distr = "norm", boot = FALSE)
#> Distribution: normal 
#> 
#> KS Test results:
#>       A p-value 
#>   8.707   0.000 
#> 
#> Parameter estimates (se):
#> location          scale             
#> 2189.942 (47.565)     1662.442 (44.129)     
#> 
#> AIC: 17621.96 
#> BIC: 17633.01 
#> 

data(nba)
print(KScens(Surv(survtime, cens) ~ 1, nba, "logis", boot = FALSE), degs = 2)
#> Distribution: logistic 
#> 
#> KS Test results:
#>       A p-value 
#>     2.1     0.0 
#> 
#> Parameter estimates (se):
#> location        scale           
#> 53.08 (0.46)     9.01 (0.22)     
#> 
#> AIC: 8460.3 
#> BIC: 8472.87 
#> 
KScens(Surv(survtime, cens) ~ 1, nba, "beta", betaLimits = c(0, 80),
       boot = FALSE)
#> Distribution: beta 
#> 
#> KS Test results:
#>       A p-value 
#>   3.739   0.000 
#> 
#> Parameter estimates (se):
#> shape             shape2            
#> 2.523 (0.091)     1.316 (0.064)     
#> 
#> AIC: 1126.562 
#> BIC: 1139.131 
#>