Range of statistics associated with a ROC curve with confidence interval where applicable. This function is faster than the alternatives provided by the package pROC.
rocperf(
x,
y = NULL,
sensitivities = NULL,
specificities = NULL,
conf.level = 0.95,
fun = NULL,
seed = 1,
boot.n = 2000,
median = FALSE,
attr = FALSE,
parallel = FALSE,
simplify = TRUE,
direction = "auto",
quiet = FALSE,
...
)A data frame with the following columns:
n.control: Number of control patients
n.case: Number of case patients
MannWhitney.pvalue: Mann Whitney U test p-value
AUC.pvalue: p-value for the null hypothesis that AUC=0.5
AUC: Area under the ROC curve (point estimate)
AUC.lCI: Lower limit of 95% confidence interval for AUC
AUC.uCI: Upper limit of 95% confidence interval for AUC
AUC.lQuart: Lower limit of 50% confidence interval for AUC
AUC.uQuart: Upper limit of 50% confidence interval for AUC
Se@SpX: Sensitivity at X% specificity
Se@SpX.lCI: Lower limit of 95% confidence interval for sensitivity at X% specificity
Se@SpX.uCI: Upper limit of 95% confidence interval for sensitivity at X% specificity
Se@SpX.lQuart: Lower limit of 95% confidence interval for sensitivity at X% specificity
Se@SpX.uQuart: Upper limit of 95% confidence interval for sensitivity at X% specificity
Sp@SeX: Specificity at X% sensitivity
Sp@SeX.lCI: Lower limit of 95% confidence interval for specificity at X% sensitivity
Sp@SeX.uCI: Upper limit of 95% confidence interval for specificity at X% sensitivity
Sp@SeX.lQuart: Lower limit of 50% confidence interval for specificity at X% sensitivity
Sp@SeX.uQuart: Upper limit of 50% confidence interval for specificity at X% sensitivity
direction: Direction of the ROC curve, see pROC::roc
Additional columns for statistics computed by the function fun if provided
data.frame with one row with computed statistics in columns.
Numeric vector containing the predicted value for each observation, or a matrix with boot.n columns containing bootstrap predicted values, or a na object of type pROC::roc.
Factor, numeric, logical or character vector encoding the response. Ignore is x is of type pROC::roc.
Vector of sensitivity thresholds. Default NULL.
Vector of specificity thresholds. Default NULL.
Width of the confidence interval. Default: 0.95 (i.e., 95% CI).
Function to compute additional statistics. Default NULL.
Random seed for bootstrapping. Default 1.
Number of bootstrap samples. Default 2e3.
If TRUE, return median bootstrap statistics, otherwise return observed values, otherwise the observe value is provided. Default FALSE.
Return bootstrap results and ROC curve as attributes. Default FALSE.
Parallelise bootstrap. Default FALSE.
If TRUE, return only median for results of the function fun having one value across bootstraps. Default TRUE.
Direction of the ROC curve, see pROC::roc. Default "auto".
Disable validity check of boot.n. Default TRUE.
Additional arguments passed to fun if not NULL.
This function computes the area under the ROC curve (AUC) and its confidence interval, the Mann-Whitney U test p-value, and the p-value for the null hypothesis that the AUC is equal to 0.5 (DeLong et al. 1988).
The function also computes the sensitivity at specified specificities and the specificity at specified sensitivities, with confidence intervals and interquartile ranges if bootstrapping is performed.
If the argument boot.n is greater than 1, the function performs bootstrapping
to compute confidence intervals for the AUC, sensitivities, and specificities.
The bootstrapping is done by resampling the control and case patients with
replacement. The interquartile range (25th and 75th percentiles) and the confidence
intervals (based on the specified conf.level) are computed from the
bootstrap samples. If median is TRUE, the median of the bootstrap samples is returned
instead of the observed value. If boot.n is equal to 1, no bootstrapping is performed
and only the interquartile ranges and confidence intervals are not returned.
The function uses the pROC package to compute the ROC curve and
confidence intervals, and it can handle parallel processing for bootstrapping.
The function returns a data frame with the computed statistics, including:
Number of control and case patients
Mann Whitney U test p-value
AUC and its confidence intervals
Sensitivity at specified specificities and their confidence intervals
Specificity at specified sensitivities and their confidence intervals
The function fun must take the following arguments:
controls: vector of control values
cases: vector of case values
thresholds: vector of thresholds used for the ROC curve
sensitivities: vector of sensitivities
specificities: vector of specificities
...: additional arguments
and return a named vector of values.
if (FALSE) { # interactive()
fu <- function(controls,cases,thr,se,sp,...) {
r <- pROC::roc(c(rep(0,length(controls)),
rep(1,length(cases))),
c(controls,cases),
quiet=TRUE)
c(AUC_fun=r$auc)
}
set.seed(1)
n <- 123
y <- runif(n)<.5
x <- rnorm(n)+y*1
ans <- rocperf(x,y,fun=fu)
ans <- rocperf(x,y,fun=fu,
senitivities=c(.5,.75,.9),
specificities=c(.5,.75,.9))
}
Run the code above in your browser using DataLab