| Title: | Alternative and Fast ROC Analysis |
|---|---|
| Description: | Alternative and fast algorithms for the analysis of receiver operating characteristics curves (ROC curves) as described in Thomas et al. (2017) <doi:10.1186/s41512-017-0017-y> and Thomas et al. (2023) <doi:10.1016/j.ajogmf.2023.101110>. |
| Authors: | Gregoire Thomas [aut, cre] (ORCID: <https://orcid.org/0000-0002-6247-9438>), Robin Tuytten [ctb] (ORCID: <https://orcid.org/0000-0002-8734-7335>), Jef Moerman [ctb], Xavier Robin [cph] (Co-author of delong.cpp from package pROC), Stefan Siegert [cph] (Co-author of delong.cpp from package pROC) |
| Maintainer: | Gregoire Thomas <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.4 |
| Built: | 2026-05-31 06:51:43 UTC |
| Source: | https://bitbucket.org/sq4/alternativeroc |
Alternative analysis methods for the analysis of receiver operating characteristics curve (ROC curve) as described in Thomas et al. (2017) <doi:10.1186/s41512-017-0017-y>.
Gregoire Thomas <[email protected]>
Arguments used across the functions of the alternativeROC package.
roc |
Object of class pROC. |
se |
Sensitivity. |
sp |
Specificity. |
ppv |
Positive predictive value. |
npv |
Negative predictive value. |
prevalence |
Prevalence of the endpoint in the study population. |
boot.n |
Number of bootstrap replicates. Default: 2000. |
quantiles |
Quantiles. Default: c(0.5,.025,.975). |
conf.level |
Width of the confidence interval. Default: 0.95 (i.e., 95% CI). |
No return value, used for the documentation of the functions of the package.
This function computes a confidence interval for the negative predictive value from a ROC curve, given the prevalence of the negative outcome.
cinpv(roc, npv, prevalence, boot.n, quantiles = c(0.5, 0.025, 0.975), ...)cinpv(roc, npv, prevalence, boot.n, quantiles = c(0.5, 0.025, 0.975), ...)
roc |
Object of class pROC. |
npv |
Negative predictive value. |
prevalence |
Prevalence of the endpoint in the study population. |
boot.n |
Number of bootstrap replicates. Default: 2000. |
quantiles |
Quantiles. Default: c(0.5,.025,.975). |
... |
Not used. |
This function computes a confidence interval for the negative predictive value from a ROC curve, given the prevalence of the negative outcome. The confidence interval is computed using bootstrap resampling.
A numeric vector of length 3 containing the median, lower bound, and upper bound of the confidence interval.
This function computes a confidence interval for the positive predictive value from a ROC curve, given the prevalence of the positive outcome.
cippv( roc, ppv, prevalence, boot.n = 2000, quantiles = c(0.5, 0.025, 0.975), ... )cippv( roc, ppv, prevalence, boot.n = 2000, quantiles = c(0.5, 0.025, 0.975), ... )
roc |
Object of class pROC. |
ppv |
Positive predictive value. |
prevalence |
Prevalence of the endpoint in the study population. |
boot.n |
Number of bootstrap replicates. Default: 2000. |
quantiles |
Quantiles. Default: c(0.5,.025,.975). |
... |
Not used. |
This function computes a confidence interval for the positive predictive value from a ROC curve, given the prevalence of the positive outcome. The confidence interval is computed using bootstrap resampling.
A numeric vector of length 3 containing the median, lower bound, and upper bound of the confidence interval.
Diagnostic performance: Negative predictive values (NPV) from a ROC curve
npv(roc, prevalence)npv(roc, prevalence)
roc |
Object of class pROC. |
prevalence |
Prevalence of the endpoint in the study population. |
A matrix with the following columns:
threshold: The thresholds used to compute the sensitivity and specificity.
sensitivity: The sensitivities at the threshold.
specificity: The specificities at the threshold.
npv: The negative predictive values at the threshold.
prevalence: The prevalence of the endpoint in the study population, as provided in the input.
Diagnostic performance: Sensitivity from specificity, negative predictive value (NPV) and prevalence of the endpoint
npv.seatsp(sp, npv, prevalence)npv.seatsp(sp, npv, prevalence)
sp |
Specificity. |
npv |
Negative predictive value. |
prevalence |
Prevalence of the endpoint in the study population. |
Sensitivity from specificity, NPV and prevalence.
Diagnostic performance: Specificity from sensitivity, negative predictive value (NPV) and prevalence of the endpoint
npv.spatse(se, npv, prevalence)npv.spatse(se, npv, prevalence)
se |
Sensitivity. |
npv |
Negative predictive value. |
prevalence |
Prevalence of the endpoint in the study population. |
Specificity from sensitivity, NPV and prevalence.
p[AUC=0.5] using DeLong's methods (DeLong et al. 1988).
p.auc(roc, ref = 0.5)p.auc(roc, ref = 0.5)
roc |
Object of class pROC. |
ref |
Reference AUC. Default 0.5. |
p value.
Diagnostic performance: Plot ROC curve
plotROC( x, annotate = FALSE, col.diagonal = "#00000080", lty.diagonal = "solid", lwd.diagonal = 1, col = "#303030", lwd = 2, cex = 2, ppv = NULL, npv = NULL, prevalence = NULL, col.pvs = "#888888", col.ci = "#dd0000", lwd.ci = lwd, len.ci = 0.1, boot.n = 1000, conf.level = 0.95, ... )plotROC( x, annotate = FALSE, col.diagonal = "#00000080", lty.diagonal = "solid", lwd.diagonal = 1, col = "#303030", lwd = 2, cex = 2, ppv = NULL, npv = NULL, prevalence = NULL, col.pvs = "#888888", col.ci = "#dd0000", lwd.ci = lwd, len.ci = 0.1, boot.n = 1000, conf.level = 0.95, ... )
x |
Object of class roc. |
annotate |
Annotate plot. |
col.diagonal |
Color of the diagonal. |
lty.diagonal |
Line type of the diagonal. |
lwd.diagonal |
Line width of the diagonal. |
col |
Color. |
lwd |
Line width. |
cex |
Size of the symbols. |
ppv |
Positive predictive value cutoff |
npv |
Negative predictive value cutoff |
prevalence |
Prevalence of the positive outcome |
col.pvs |
Color of the predictive value triangles |
col.ci |
Color of the positive and negative predictive values. |
lwd.ci |
Line width for the positive and negative predictive values. |
len.ci |
Length of the end segment for positive and negative predictive values (see arrows). |
boot.n |
Number of bootstrap replicates for the computation of the confidence interval of the specificity at NPV and of the sensitivity at PPV. |
conf.level |
Width of the confidence interval of the specificity at NPV and of the sensitivity at PPV. |
... |
parameters to be passed to plot. |
A list with the following elements:
AUC: A numeric vector of length 3 containing the median, lower bound, and upper bound of the AUC.
PPV: The positive predictive value cutoff.
sensitivity@PPV: A numeric vector of length 3 containing the median, lower bound, and upper bound of the sensitivity at the specified PPV.
NPV: The negative predictive value cutoff.
specificity@NPV: A numeric vector of length 3 containing the median, lower bound, and upper bound of the specificity at the specified NPV.
set.seed(0) count.neg <- count.pos <- 200 sd.neg <- sd.pos <- 1 mean.neg <- .5 mean.pos <- 1 skew.neg <- -8 skew.pos <- 0 x <- c(sn::rsn(count.neg,mean.neg,sd.neg,skew.neg), sn::rsn(count.pos,mean.pos,sd.pos,skew.pos)) y <- ordered(c(rep("neg",count.neg),rep("pos",count.pos)),levels=c("neg","pos")) r1 <- roc(y,x) plotROC(r1,ppv=0.2,prevalence=0.05,boot.n=1e2) skew.neg <- 0 skew.pos <- 8 x <- c(sn::rsn(count.neg,mean.neg,sd.neg,skew.neg), sn::rsn(count.pos,mean.pos,sd.pos,skew.pos)) y <- ordered(c(rep("neg",count.neg),rep("pos",count.pos)),levels=c("neg","pos")) r2 <- roc(y,x) plotROC(r2,npv=0.995,prevalence=0.05,boot.n=1e2)set.seed(0) count.neg <- count.pos <- 200 sd.neg <- sd.pos <- 1 mean.neg <- .5 mean.pos <- 1 skew.neg <- -8 skew.pos <- 0 x <- c(sn::rsn(count.neg,mean.neg,sd.neg,skew.neg), sn::rsn(count.pos,mean.pos,sd.pos,skew.pos)) y <- ordered(c(rep("neg",count.neg),rep("pos",count.pos)),levels=c("neg","pos")) r1 <- roc(y,x) plotROC(r1,ppv=0.2,prevalence=0.05,boot.n=1e2) skew.neg <- 0 skew.pos <- 8 x <- c(sn::rsn(count.neg,mean.neg,sd.neg,skew.neg), sn::rsn(count.pos,mean.pos,sd.pos,skew.pos)) y <- ordered(c(rep("neg",count.neg),rep("pos",count.pos)),levels=c("neg","pos")) r2 <- roc(y,x) plotROC(r2,npv=0.995,prevalence=0.05,boot.n=1e2)
Diagnostic performance: Positive predictive values (PPV) from a ROC curve
ppv(roc, prevalence)ppv(roc, prevalence)
roc |
Object of class pROC. |
prevalence |
Prevalence of the endpoint in the study population. |
A matrix with the following columns:
threshold: The thresholds used to compute the sensitivity and specificity.
sensitivity: The sensitivities at the threshold.
specificity: The specificities at the threshold.
ppv: The positive predictive values at the threshold.
prevalence: The prevalence of the endpoint in the study population, as provided in the input.
Diagnostic performance: Sensitivity from specificity, positive predictive value (PPV) and prevalence of the endpoint
ppv.seatsp(sp, ppv, prevalence)ppv.seatsp(sp, ppv, prevalence)
sp |
Specificity. |
ppv |
Positive predictive value. |
prevalence |
Prevalence of the endpoint in the study population. |
Sensitivity from specificity, PPV and prevalence.
Diagnostic performance: Specificity from sensitivity, positive predictive value (PPV) and prevalence of the endpoint
ppv.spatse(se, ppv, prevalence)ppv.spatse(se, ppv, prevalence)
se |
Sensitivity. |
ppv |
Positive predictive value. |
prevalence |
Prevalence of the endpoint in the study population. |
Specificity from sensitivity, PPV and prevalence.
Diagnostic performance: Predictive values from a ROC curve
pvs( roc = NULL, prevalence, thresholds = roc$thresholds, sensitivities = roc$sensitivities, specificities = roc$specificities )pvs( roc = NULL, prevalence, thresholds = roc$thresholds, sensitivities = roc$sensitivities, specificities = roc$specificities )
roc |
Object of class pROC. |
prevalence |
Prevalence of the endpoint in the study population. |
thresholds |
Thresholds of the ROC curve, default is roc$thresholds. |
sensitivities |
Sensitivity values of the ROC curve, default is roc$sensitivities. |
specificities |
Specificity values of the ROC curve, default is roc$specificities. |
This function computes the positive and negative predictive values from a ROC curve, given the prevalence of the positive outcome.
A data frame with the following columns:
threshold: Thresholds of the ROC curve.
sensitivity: Sensitivity values of the ROC curve.
specificity: Specificity values of the ROC curve.
prevalence: Prevalence of the positive outcome.
ppv: Positive predictive value.
npv: Negative predictive value.
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, ... )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, ... )
x |
Numeric vector containing the predicted value for each observation, or a matrix with |
y |
Factor, numeric, logical or character vector encoding the response. Ignore is |
sensitivities |
Vector of sensitivity thresholds. Default NULL. |
specificities |
Vector of specificity thresholds. Default NULL. |
conf.level |
Width of the confidence interval. Default: 0.95 (i.e., 95% CI). |
fun |
Function to compute additional statistics. Default NULL. |
seed |
Random seed for bootstrapping. Default 1. |
boot.n |
Number of bootstrap samples. Default 2e3. |
median |
If TRUE, return median bootstrap statistics, otherwise return observed values, otherwise the observe value is provided. Default FALSE. |
attr |
Return bootstrap results and ROC curve as attributes. Default FALSE. |
parallel |
Parallelise bootstrap. Default FALSE. |
simplify |
If TRUE, return only median for results of the function |
direction |
Direction of the ROC curve, see |
quiet |
Disable validity check of |
... |
Additional arguments passed to |
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.
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
[email protected]: Lower limit of 95% confidence interval for sensitivity at X% specificity
[email protected]: Upper limit of 95% confidence interval for sensitivity at X% specificity
[email protected]: Lower limit of 95% confidence interval for sensitivity at X% specificity
[email protected]: Upper limit of 95% confidence interval for sensitivity at X% specificity
Sp@SeX: Specificity at X% sensitivity
[email protected]: Lower limit of 95% confidence interval for specificity at X% sensitivity
[email protected]: Upper limit of 95% confidence interval for specificity at X% sensitivity
[email protected]: Lower limit of 50% confidence interval for specificity at X% sensitivity
[email protected]: 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.
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))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))
Compute ROC sensitivity, specificity and threshold for a given cutoff.
rocthreshold(x, y, cut, input, prevalence = NULL, annotate = FALSE)rocthreshold(x, y, cut, input, prevalence = NULL, annotate = FALSE)
x |
either a ROC object or the predictor to build the ROC curve |
y |
if x is not a ROC object, the binary outcome of the ROC curve |
cut |
cutoff value |
input |
cutoff type, either sensitivity, specificity, threshold, PPV or NPV |
prevalence |
Prevalence of the endpoint in the study population. |
annotate |
if TRUE, the full ROC curve is returned as an attribute |
This function computes the sensitivity, specificity, threshold, PPV and NPV at a given cutoff value from a ROC curve.
NPV and PPV are computed only if a prevalence is provided as input.
If the ROC curve is not provided, it will be computed from the predictor and outcome.
a vector with sensitivity, specificity, threshold, PPV and NPV at the given cutoff.