Receiver Operator Characteristic calculator
Arguments
- object
A fitted
rfsrc,predict.rfsrc, orrandomForestclassification object containing predicted class probabilities.- dta
A factor (or coercible to factor) of the true observed class labels, one per observation. Typically
object$yvarfor rfsrc orobject$yfor randomForest.- which_outcome
Integer index of the class for which the ROC curve is computed (e.g.
1for the first class,2for the second). Use"all", or its numeric spelling0, to request all classes. TherandomForestmethod returns a macro-averaged one-vs-rest curve; therfsrcmethod warns and falls back to class 1 (see #72).- oob
Logical; if
TRUE(default for rfsrc) use OOB predicted probabilities. Forced toFALSEforrandomForestobjects.- ...
Extra arguments passed to helper functions (currently unused).
Value
A gg_roc data.frame with columns sens
(sensitivity), spec (specificity), and pct (the probability
threshold), with one row per unique prediction value. Suitable for passing
to calc_auc or plot.gg_roc.
Details
For a randomForestSRC prediction and the actual response value, calculate the specificity (1-False Positive Rate) and sensitivity (True Positive Rate) of a predictor.
This is a helper function for the gg_roc functions, and
not intended for use by the end user.
Examples
## Taken from the gg_roc example
rfsrc_iris <- randomForestSRC::rfsrc(Species ~ ., data = iris, ntree = 100)
gg_dta <- calc_roc(rfsrc_iris, rfsrc_iris$yvar,
which_outcome = 1, oob = TRUE
)
gg_dta <- calc_roc(rfsrc_iris, rfsrc_iris$yvar,
which_outcome = 1, oob = FALSE
)
rf_iris <- randomForest::randomForest(Species ~ ., data = iris)
# randomForest stores the response in $y (rfsrc uses $yvar); pass the
# original training factor so calc_roc has the class labels.
gg_dta <- calc_roc(rf_iris, iris$Species,
which_outcome = 1
)
gg_dta <- calc_roc(rf_iris, iris$Species,
which_outcome = 2
)