Function gofcens
computes the Kolmogorov-Smirnov, Cramér-von Mises, and
Anderson-Darling statistics ans p-values for complete and right-censored data against
eight possible distributions.
# S3 method for default
gofcens(times, cens = rep(1, length(times)),
distr = c("exponential", "gumbel", "weibull", "normal",
"lognormal", "logistic", "loglogistic", "beta"),
betaLimits = c(0, 1), igumb = c(10, 10), degs = 3, BS = 999,
params0 = list(shape = NULL, shape2 = NULL, location = NULL,
scale = NULL), ...)
# S3 method for formula
gofcens(formula, data,...)
gofcens
returns an object of class
"gofcens"
.
An object of class "gofcens"
is a list containing the following components:
Distribution
Null distribution.
Null hypothesis
Parameters under the null hypothesis (if params0
is provided).
Tests statistics
Values of the Kolmogovor-Smirnov, Cramér-von Mises, and Anderson-Darling test statistics.
p-value
P-values associated with each test.
Parameters
List with the maximum likelihood estimates of the parameters of the distribution under study.
Numeric vector of times until the event of interest.
Status indicator (1, exact time; 0, right-censored time). If not provided, all times are assumed to be exact.
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.
Two-components vector with the lower and upper bounds of the Beta distribution. This argument is only required, if the beta distribution is considered.
Two-components vector with the initial values for the estimation of the Gumbel distribution parameters.
Integer indicating the number of decimal places of the numeric results of the output.
Number of bootstrap samples.
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.
A formula with a numeric vector as response (which assumes no censoring) or Surv
object.
Data frame for variables in formula
.
Additional arguments.
K. Langohr, M. Besalú, M. Francisco, G. Gómez.
If the amount of data is large, the execution time of the
function can be elevated. The parameter BS
can
limit the number of random censored samples generated and
reduce the execution time.
Fleming et al. (1980) proposed a modified Kolmogorov-Smirnov test to be used with right-censored data. Koziol and Green (1976) proposed a Cramér-von Mises statistic for randomly censored data. This function reproduces this test for a given survival data and a theorical distribution. In presence of ties, different authors provide slightly different definitions of the product-limit estimator, what might provide different values of the test statistic.
When dealing with complete data, we recommend the use of functions
ks.test
of the stats package and
cvm.test
and ad.test
of the goftest package.
T. R. Fleming et al. Modified Kolmogorov-Smirnov test procedure with application to arbitrarily right-censored data. In: Biometrics 36 (1980), 607-625.
J. A. Koziol and S. B. Green. A Cramér-von Mises statistic for randomly censored data. In: Biometrika, 63 (3) (1976), 465-474.
A. N. Pettitt and M. A. Stephens. Modified Cramér-von Mises statistics for censored data. In: Biometrika, 63 (2) (1976), 291-298.
ks.test (Package stats
), cvm.test
(Package goftest
), and ad.test
(Package goftest
) for complete data, and KScens for the
Kolmogorov-Smirnov test for right-censored data, which returns the p-value.
if (FALSE) {
# Complete data
set.seed(123)
gofcens(times = rweibull(100, 12, scale = 4), distr = "weibull", BS = 499)
# Censored data
data(colon)
set.seed(123)
colonsamp <- colon[sample(nrow(colon), 300), ]
gofcens(Surv(time, status) ~ 1, colonsamp, distr = "normal")
}
Run the code above in your browser using DataLab