Title: | Simple and Fast ROC Curves |
---|---|
Description: | A set of functions for receiver operating characteristic (ROC) curve estimation and area under the curve (AUC) calculation. All functions are designed to work with aggregated data; nevertheless, they can also handle raw samples. In 'ROCket', we distinguish two types of ROC curve representations: 1) parametric curves - the true positive rate (TPR) and the false positive rate (FPR) are functions of a parameter (the score), 2) functions - TPR is a function of FPR. There are several ROC curve estimation methods available. An introduction to the mathematical background of the implemented methods (and much more) can be found in de Zea Bermudez, Gonçalves, Oliveira & Subtil (2014) <https://www.ine.pt/revstat/pdf/rs140101.pdf> and Cai & Pepe (2004) <doi:10.1111/j.0006-341X.2004.00200.x>. |
Authors: | Daniel Lazar [aut, cre] |
Maintainer: | Daniel Lazar <[email protected]> |
License: | GPL-3 |
Version: | 1.0.1.9000 |
Built: | 2025-02-17 03:14:10 UTC |
Source: | https://github.com/da-zar/rocket |
Calculate the AUC
auc(x, ...) ## S3 method for class ''function'' auc(x, ...) ## S3 method for class 'curve' auc(x, lower, upper, n = 10000, ...) ## S3 method for class 'rkt_roc' auc(x, exact = TRUE, ...)
auc(x, ...) ## S3 method for class ''function'' auc(x, ...) ## S3 method for class 'curve' auc(x, lower, upper, n = 10000, ...) ## S3 method for class 'rkt_roc' auc(x, exact = TRUE, ...)
x |
An R object. |
... |
Further parameters. |
lower , upper
|
The limits of integration. |
n |
The number of integration points. |
exact |
Logical. If the exact formula should be used for calculating the AUC instead of numerical approximation. |
The area under the curve as a numeric value.
Performs the Mann-Whitney U test with a normal approximation.
mwu.test(prep, alternative = c("two.sided", "less", "greater"), correct = TRUE)
mwu.test(prep, alternative = c("two.sided", "less", "greater"), correct = TRUE)
prep |
A |
alternative |
The alternative hypothesis type. One of: "two.sided", "less", "greater". |
correct |
Logical. Whether to apply continuity correction. |
A list of the class "htest".
Calculate an empirical cumulative distribution function based on a sample x
and optionally a vector w
of weights.
rkt_ecdf(x, w) ## S3 method for class 'rkt_ecdf' print(x, ...) ## S3 method for class 'rkt_ecdf' mean(x, ...) ## S3 method for class 'rkt_ecdf' variance(x, ...) ## S3 method for class 'rkt_ecdf' plot(x, ...)
rkt_ecdf(x, w) ## S3 method for class 'rkt_ecdf' print(x, ...) ## S3 method for class 'rkt_ecdf' mean(x, ...) ## S3 method for class 'rkt_ecdf' variance(x, ...) ## S3 method for class 'rkt_ecdf' plot(x, ...)
x |
Numeric vector containing the sample. Alternatively, if |
w |
Optional. Numeric vector containing the weights of each value in |
... |
Further parameters. |
The weights vector w
can contain the counts of each distinct value in x
, this is the most natural use case.
In general the weights are describing the jumps of the final ecdf. Normalization is handled internally.
If x
contains duplicates, corresponding values in w
will be summed up.
Only positive weights are allowed. Elements in x
with non-positive weights will be ignored.
A function of class rkt_ecdf
.
require(ROCket) plot(rkt_ecdf(rnorm(100))) plot(rkt_ecdf(c(0, 1))) plot(rkt_ecdf(c(0, 1), c(1, 10)))
require(ROCket) plot(rkt_ecdf(rnorm(100))) plot(rkt_ecdf(c(0, 1))) plot(rkt_ecdf(c(0, 1), c(1, 10)))
Calculate the ROC points for all meaningful cutoff values based on predicted scores.
rkt_prep(scores, positives, negatives = totals - positives, totals = 1) ## S3 method for class 'rkt_prep' print(x, ...) ## S3 method for class 'rkt_prep' plot(x, ...)
rkt_prep(scores, positives, negatives = totals - positives, totals = 1) ## S3 method for class 'rkt_prep' print(x, ...) ## S3 method for class 'rkt_prep' plot(x, ...)
scores |
Numeric vector containing the predicted scores. |
positives |
Numeric vector of the same length as |
negatives |
Similar to |
totals |
How many times each score was predicted. Defaults to 1 (assuming data is not aggregated).
If any value in |
x |
An environment of class |
... |
Further parameters. |
In a situation where many of the predicted scores have the same value it might be easier and faster to use aggregated data.
An environment of class rkt_prep
.
require(ROCket) plot(rkt_prep(1:4, c(0, 1, 0, 1))) plot(rkt_prep(1:4, c(0, 1000, 0, 1000), totals = 1000)) plot(rkt_prep(1:4, c(100, 200, 300, 400), totals = c(1000, 800, 600, 400)))
require(ROCket) plot(rkt_prep(1:4, c(0, 1, 0, 1))) plot(rkt_prep(1:4, c(0, 1000, 0, 1000), totals = 1000)) plot(rkt_prep(1:4, c(100, 200, 300, 400), totals = c(1000, 800, 600, 400)))
Calculate the empirical estimate of the ROC from raw sample or aggregated data.
rkt_roc(prep, method = 1) ## S3 method for class 'rkt_roc' print(x, ...) ## S3 method for class 'rkt_roc' plot(x, ...)
rkt_roc(prep, method = 1) ## S3 method for class 'rkt_roc' print(x, ...) ## S3 method for class 'rkt_roc' plot(x, ...)
prep |
A |
method |
A number specifying the type of ROC estimate. Possible values can be viewed with |
x |
An object of class |
... |
An object of class rkt_roc
, i.e. a function or a list of two functions (for method = 1).
require(ROCket) scores <- c(1, 2, 3, 4) positives <- c(0, 1, 0, 1) prep <- rkt_prep(scores, positives) roc1 <- rkt_roc(prep, method = 1) roc2 <- rkt_roc(prep, method = 2) roc3 <- rkt_roc(prep, method = 3) plot(roc1) plot(roc2) plot(roc3)
require(ROCket) scores <- c(1, 2, 3, 4) positives <- c(0, 1, 0, 1) prep <- rkt_prep(scores, positives) roc1 <- rkt_roc(prep, method = 1) roc2 <- rkt_roc(prep, method = 2) roc3 <- rkt_roc(prep, method = 3) plot(roc1) plot(roc2) plot(roc3)
Show the implemented ROC estimation methods.
show_methods()
show_methods()
A data.table
containing the number and a short description of each implemented method.
Sample Variance
variance(x, ...) ## Default S3 method: variance(x, ...)
variance(x, ...) ## Default S3 method: variance(x, ...)
x |
An R object. |
... |
Further parameters. |
The (biased) sample variance as a numeric value.