rocFn: ROC Curve Coordinates

View source: R/skill.R

rocFnR Documentation

ROC Curve Coordinates

Description

Calculates the coordinates for a Receiver Operating Characteristic (ROC) curve

Usage

rocFn(labels, scores)

## S4 method for signature 'numeric,numeric'
rocFn(labels, scores)

Arguments

labels

Binary vector of true labels

scores

Numeric vector of prediction scores

Value

A data frame containing:

  • TPR - True Positive Rate (Sensitivity)

  • FPR - False Positive Rate (1-Specificity)

  • labels - Ordered labels

  • reference - Sorted scores

Examples

## Not run: 
labels <- c(1,0,1,1,0)
scores <- c(0.9, 0.1, 0.8, 0.7, 0.3)
roc_coords <- rocFn(labels, scores)

## End(Not run)

# In this example, we first generate sample data for state and indicator vectors. 
# Generate sample data
state <- c(0.5, 2.3, 1.2, 1.8, 3.0, 0.7)
indicator <- c(0.6, 2.2, 1.1, 1.9, 2.8, 0.5)

# Then, we call the roc function to calculate ROC statistics and print the results.
# Calculate ROC statistics
roc_result=roc(state, indicator)

# Print the ROC statistics
roc_result

#Plot the ROC curve using the ggplot2 package. 

library(ggplot2)
ggplot(roc_result, aes(x = FPR, y = TPR)) +
  geom_line() +
  geom_abline(intercept = 0, slope = 1, linetype = "dashed") +
  labs(x = "False Positive Rate (FPR)", y = "True Positive Rate (TPR)") +
  ggtitle("ROC Curve") +
  theme_minimal()
  
  

laurieKell/FLCandy documentation built on April 17, 2025, 5:23 p.m.