Function for ROC (Receiver Operating Characteristic) Curve Analysis. Calculates sensitivity, specificity, AUC, Youden index, and more.
Usage
roc(
data,
classvar,
classpos,
testvar,
direction = "greatpos",
ci = TRUE,
cimethod = "delong",
youden = TRUE,
optimcrit = TRUE,
pp = FALSE,
pprob = 0.5,
costratioFP = 1,
coords = TRUE,
plotroc = TRUE,
plotci = FALSE,
plotbars = FALSE,
plotprev = FALSE,
plotidr = TRUE
)
Arguments
- data
The data as a data frame.
- classvar
A string naming the variable from
data
that contains the actual status (gold standard / diagnosis), must be a factor with two levels.- classpos
The level of the classification variable that represents the positive status.
- testvar
A string naming the variable from
data
that contains the test result or measurement, must be numeric.- direction
Specify whether greater values of the test variable indicate a positive test (default) or if lower values indicate a positive test. Note: AUC will always be greater than 0.5, even if it means inverting the predictor internally.
- ci
Boolean selection whether to show 95\ Default is 'true'.
- cimethod
Method for calculating confidence intervals for the AUC. Default is 'delong'.
- youden
Boolean selection whether to calculate Youden index (J = sensitivity + specificity - 1). Default is 'true'.
- optimcrit
Boolean selection whether to calculate the optimal criterion value. Default is 'true'.
- pp
Boolean selection whether to use a specified disease prevalence for predictive values. Default is 'false'.
- pprob
Prior probability (disease prevalence in the population). Requires a value between 0.001 and 0.999, default 0.500.
- costratioFP
Cost ratio of false positive to false negative decisions. Default is 1.000 (equal costs).
- coords
Boolean selection whether to show the full list of coordinates of the ROC curve. This includes all possible thresholds with sensitivity, specificity, predictive values, and likelihood ratios. Default is 'true'.
- plotroc
Boolean selection whether to create a ROC curve plot. Default is 'true'.
- plotci
Boolean selection whether to show 95\ the ROC curve. Default is 'false'.
- plotbars
Boolean selection whether to create a plot of sensitivity and specificity versus criterion values. Default is 'false'.
- plotprev
Boolean selection whether to create a plot of positive and negative predictive values versus disease prevalence. Default is 'false'.
- plotidr
Boolean selection whether to create an interactive dot diagram Default is 'true'.
Value
A results object containing:
results$summary | a table | ||||
results$optimal | a table | ||||
results$coords | a table | ||||
results$plotroc | an image | ||||
results$plotbars | an image | ||||
results$plotprev | an image | ||||
results$plotidr | an image |
Tables can be converted to data frames with asDF
or as.data.frame
. For example:
results$summary$asDF
as.data.frame(results$summary)