This function takes a “roc” or “smooth.roc” object as
first argument, on which the coordinates will be determined. The
coordinates are defined by the x
and input
arguments. “threshold” coordinates cannot be determined in a
smoothed ROC.
If input="threshold"
, the coordinates for the threshold
are reported, even if the exact threshold do not define the ROC
curve. The following convenience characters are allowed: “all”,
“local maximas” and “best”. They will return all the
thresholds, only the thresholds defining local maximas (upper angles of the
ROC curve), or only the threshold(s) corresponding to the best sum of
sensitivity + specificity respectively. Note that “best” can
return more than one threshold. If x
is a character, and
ignore.partial.auc=TRUE
, the coordinates are limited to the
thresholds within the partial AUC if it has been defined, and not
necessarily to the whole curve.
For input="specificity"
and input="sensitivity"
,
the function checks if the specificity or sensitivity is one of the
points of the ROC curve (in roc$sensitivities
or
roc$specificities
). More than one point may match (in
step curves), then only the upper-left-most point coordinates
are returned. Otherwise,
the specificity and specificity of the point is interpolated and
NA
is returned as threshold.
The coords function in this package is a generic, but it might be
superseded by functions in other packages such as
colorspace or spatstat if they are loaded after
pROC. In this case, call the pROC::coords
explicitly.
Best thresholds
If x="best"
, the best.method
argument controls how the
optimal threshold is determined.
- “youden”
Youden's J statistic (Youden, 1950) is employed (default). The optimal
cut-off is the threshold that maximizes the distance to the identity
(diagonal) line. Can be shortened to “y”.
The optimality criterion is:
$$max(sensitivities + specificities)$$
- “closest.topleft”
The optimal threshold is the point closest to the top-left part of
the plot with perfect sensitivity or specificity. Can be shortened
to “c” or “t”.
The optimality criterion is:
$$min((1 - sensitivities)^2 + (1- specificities)^2)$$
In addition, weights can be supplied if false positive and false
negative predictions are not equivalent: a numeric vector of length 2
to the best.weights
argument. The elements define
the relative cost of of a false negative classification (as compared with a false positive classification)
the prevalence, or the proportion of cases in the population (\(\frac{n_{cases}}{n_{controls}+n_{cases}}\)).
The optimality criteria are modified as proposed by Perkins and Schisterman:
- “youden”
$$max(sensitivities + r * specificities)$$
- “closest.topleft”
$$min((1 - sensitivities)^2 + r * (1- specificities)^2)$$
with
$$r = \frac{1 - prevalence}{cost * prevalence}$$
By default, prevalence is 0.5 and cost is 1 so that no weight is
applied in effect.
Note that several thresholds might be equally optimal.
Available coordinates
The following table lists the coordinates that are available in the ret
and input
arguments.
Value | Description | Formula | Synonyms | Valid input |
threshold | The threshold value | - | - | Yes |
tn | True negative count | - | - | Yes |
tp | True positive count | - | - | Yes |
fn | False negative count | - | - | Yes |
fp | False positive count | - | - | Yes |
specificity | Specificity | tn / (tn + fp) | tnr | Yes |
sensitivity | Sensitivity | tp / (tp + fn) | recall, tpr | Yes |
accuracy | Accuracy | (tp + tn) / N | - | No |
npv | Negative Predictive Value | tn / (tn + fn) | - | No |
ppv | Positive Predictive Value | tp / (tp + fp) | precision | No |
precision | Precision | tp / (tp + fp) | ppv | No |
recall | Recall | tp / (tp + fn) | sensitivity, tpr | Yes |
tpr | True Positive Rate | tp / (tp + fn) | sensitivity, recall | Yes |
fpr | False Positive Rate | fp / (tn + fp) | 1-specificity | Yes |
tnr | True Negative Rate | tn / (tn + fp) | specificity | Yes |
fnr | False Negative Rate | fn / (tp + fn) | 1-sensitivity | Yes |
fdr | False Discovery Rate | fp / (tp + fp) | 1-ppv | No |
lr_pos | Positive Likelihood Ratio | se / (1 - sp) | - | No |
lr_neg | Negative Likelihood Ratio | (1 - se) / (sp) | - | No |
youden | Youden Index | se + r * sp | - | No |
closest.topleft | Distance to the top left corner of the ROC space | - ((1 - se)^2 + r * (1 - sp)^2) | - | No |
The value “threshold” is not allowed in coords.smooth.roc
.
Values can be shortenend (for example to “thr”, “sens” and “spec”, or even to
“se”, “sp” or “1-np”). In addition, some values can be prefixed with
1-
to get their complement:
1-specificity
, 1-sensitivity
, 1-accuracy
, 1-npv
, 1-ppv
.
The values npe
and ppe
are automatically replaced with
1-npv
and 1-ppv
, respectively (and will therefore not appear
as is in the output, but as 1-npv
and 1-ppv
instead).
These must be used verbatim in ROC curves with percent=TRUE
(ie. “100-ppv” is never accepted).
The “youden” and “closest.topleft” are weighted with r
,
according to the value of the best.weights
argument. See the
“Best thresholds” section above for more details.
For ret
, the single value “all” can be used to return
every coordinate available.