roc_analysis: Carry out the ROC analysis

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/roc_analysis.R

Description

Do the ROC (receiver operating characteristic) analysis and calculate vector of cut-off values and associated number of true positives (TP), false negatives (FN), false positives (FP), and true negatives (TN) as well as performance measures such as sensitivity, specificity, etc.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## S3 method for class 'as_str'
print(x, ...)

## S3 method for class 'roc_df'
print(x, ..., show_all = FALSE, perf_digits = 2,
  fmt = "%.3g")

## S3 method for class 'roc_opt_result'
print(x, digits = 3, ...)

## S3 method for class 'roc_info'
print(x, ...)

roc_analysis(x, gr, pos_label = levels(gr)[2], pos_is_larger = NULL,
  optimize_by = "bac", results = "all", ...)

## Default S3 method:
roc_analysis(x, gr, pos_label = levels(gr)[2],
  pos_is_larger = NULL, optimize_by = "bac", results = "all", ...)

## S3 method for class 'data.frame'
roc_analysis(x, gr, pos_label = levels(gr)[2],
  pos_is_larger = NULL, optimize_by = "bac", results = "all", ...)

## S3 method for class 'matrix'
roc_analysis(x, gr, pos_label = levels(gr)[2],
  pos_is_larger = NULL, optimize_by = "bac", results = "all", ...)

Arguments

x

(numeric)
A numeric vector.
(in print function) An object to print.

...

[!!!] Passed to further methods.

show_all

(logical(1))
A flag if whole dataset should be printed. If FALSE, only a few fisrt and last rows will be printed.

perf_digits

(integer(1))
A number of decimals to display for performance measures. Default is 2.

fmt

(character(1))
A string indicating number display format for other numeric columns excluding performance measures. The string will be passed to sprintf. Default is "%.3g".

digits

(integer(1))
Number of significant digits to display.

gr

(factor)
A factor vector with two levels.

pos_label

(character(1))
A string with the name of positive group.

pos_is_larger

(NULL|TRUE|FALSE)
A flag indicating, if values of positive group are on avedage are expected to be larger than values of negative group. If NULL, this option is determined basing on data using group medians.

optimize_by

(string(1))
[!!!] Method to determine the optimal cut-off value. Current options: "bac", "youden", "kappa".

results

(character(1))
A string indicating which results should be returned: either "all" (as described in section "Values") or just "optimal".

Value

A list (which also inherits from class "roc_result_list") with three fields: $info, $optimal, $all_results.



Note

This function is inspired by functions predict and .compute.unnormalized.roc.curve from ROCR package.

Author(s)

Vilmantas Gegzna

See Also

Other functions for ROC: access_elements, calculate_performance, roc_performance_measures, roc_predict

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
library(manyROC)
library(ggplot2)

# Make some data

set.seed(1)
(x <- rnorm(10))

(gr <- gl(n = 2, k = 5, length = 10, labels = c("H","S")))


# Explore the functions

roc_analysis(x, gr)

roc_analysis(x, gr, pos_label = "H")


# --- Example 2 ---

set.seed(1)
x2 = c(rnorm(50, mean = 14), rnorm(50, mean = 20))
gr2 = gl(2, 50, labels = c("Neg", "Pos"))

(roc_rez<- roc_analysis(x2, gr2))

optimal_cutoff2 <- roc_rez$optimal[1]

qplot(x2, fill = gr2, color = gr2,
      geom = c("density", "rug"), alpha = I(0.3)) +
   geom_vline(xintercept = optimal_cutoff2)


# --- Example 3 ---

set.seed(1)
x3 = c(rnorm(100, mean = 11), rnorm(100, mean = 14))
gr3 = gl(2, 100, labels = c("Neg", "Pos"))

(roc_rez3 <- roc_analysis(x3, gr3))

optimal_cutoff3 <- roc_rez3$optimal[1]

qplot(x3, fill = gr3, color = gr3,
     geom = c("density", "rug"), alpha = I(0.3)) +
    geom_vline(xintercept = roc_rez3$optimal[1])

GegznaV/manyROC documentation built on Oct. 3, 2017, 11:05 p.m.