Sunday 10 September 2017

Package ROCR in R

This is a work document. You can find this package here:

Downloads:

Reference manual: ROCR.pdf
Package source: ROCR_1.0-7.tar.gz
Windows binaries: r-devel: ROCR_1.0-7.zip, r-release: ROCR_1.0-7.zip, r-oldrel: ROCR_1.0-7.zip
OS X El Capitan binaries: r-release: ROCR_1.0-7.tgz
OS X Mavericks binaries: r-oldrel: ROCR_1.0-7.tgz
Old sources: ROCR archive



Package ‘ROCR’

performance Function to create performance objects

Description

All kinds of predictor evaluations are performed using this function.

Examples

## computing a simple ROC curve (x-axis: fpr, y-axis: tpr)
library(ROCR)
## Loading required package: gplots
## 
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
## 
##     lowess
data(ROCR.simple)
pred <- span=""> prediction( ROCR.simple$predictions, ROCR.simple$labels)
perf <- span=""> performance(pred,"tpr","fpr")
plot(perf)
## precision/recall curve (x-axis: recall, y-axis: precision)
perf1 <- span=""> performance(pred, "prec", "rec")
plot(perf1)
## sensitivity/specificity curve (x-axis: specificity,
## y-axis: sensitivity)
perf2 <- span=""> performance(pred, "sens", "spec")
plot(perf2)
# ROC curves: measure="tpr", x.measure="fpr".
perf <- span=""> performance(pred,"tpr","fpr")
plot(perf)
# Precision/recall graphs: measure="prec", x.measure="rec".
perf1 <- span=""> performance(pred, "prec", "rec")
plot(perf1)
# Sensitivity/specificity plots: measure="sens", x.measure="spec".
perf2 <- span=""> performance(pred, "sens", "spec")
plot(perf2)
# Lift charts: measure="lift", x.measure="rpp".
perf3 <- span=""> performance(pred, "lift", "rpp")
plot(perf3)

performance-class Class “performance”

Description

Object to capture the result of a performance evaluation, optionally collecting evaluations from several cross-validation or bootstrapping runs.

examples

# performance-class("pred")

plot-methods Plot method for performance objects

Description

This is the method to plot all objects of class performance. Usage

Examples

# plotting a ROC curve:
library(ROCR)
data(ROCR.simple)
pred <- span=""> prediction( ROCR.simple$predictions, ROCR.simple$labels )
perf <- span=""> performance( pred, "tpr", "fpr" )
plot( perf )
# To entertain your children, make your plots nicer
# using ROCR's flexible parameter passing mechanisms
# (much cheaper than a finger painting set)
par(bg="lightblue", mai=c(1.2,1.5,1,1))
# mai: A numerical vector of the form c(bottom, left, top, right) which gives the margin size specified in inches.

plot(perf, main="ROCR fingerpainting toolkit", colorize=TRUE,
xlab="Mary's axis", ylab="example", box.lty=7, box.lwd=5,
box.col="gold", lwd=17, colorkey.relwidth=0.5, xaxis.cex.axis=2,
xaxis.col='blue', xaxis.col.axis="blue", yaxis.col='green', yaxis.cex.axis=2, 
yaxis.at=c(0,0.5,0.8,0.85,0.9,1), yaxis.las=1, xaxis.lwd=2, yaxis.lwd=3,
yaxis.col.axis="orange", cex.lab=2, cex.main=2)

prediction Function to create prediction objects

Description

Every classifier evaluation using ROCR starts with creating a prediction object. This function is used to transform the input data (which can be in vector, matrix, data frame, or list form) into a standardized format.

Examples

# create a simple prediction object
library(ROCR)
data(ROCR.simple)
pred <- span=""> prediction(ROCR.simple$predictions,ROCR.simple$labels)

prediction-class Class “prediction”

Description

Object to encapsulate numerical predictions together with the corresponding true class labels, optionally collecting predictions and labels for several cross-validation or bootstrapping runs.

ROCR.hiv Data set: Support vector machines and neural networks applied to the prediction of HIV-1 coreceptor usage

Description

Linear support vector machines (libsvm) and neural networks (R package nnet) were applied to predict usage of the coreceptors CCR5 and CXCR4 based on sequence data of the third variable loop of the HIV envelope protein.

Examples

data(ROCR.hiv)
attach(ROCR.hiv)
pred.svm <- span=""> prediction(hiv.svm$predictions, hiv.svm$labels)
perf.svm <- span=""> performance(pred.svm, 'tpr', 'fpr')
pred.nn <- span=""> prediction(hiv.nn$predictions, hiv.svm$labels)
perf.nn <- span=""> performance(pred.nn, 'tpr', 'fpr')
plot(perf.svm, lty=3, col="red",main="SVMs and NNs for prediction of
HIV-1 coreceptor usage")
plot(perf.nn, lty=3, col="blue",add=TRUE)
plot(perf.svm, avg="vertical", lwd=3, col="red",
spread.estimate="stderror",plotCI.lwd=2,add=TRUE)
plot(perf.nn, avg="vertical", lwd=3, col="blue",
spread.estimate="stderror",plotCI.lwd=2,add=TRUE)
legend(0.6,0.6,c('SVM','NN'),col=c('red','blue'),lwd=3)

ROCR.simple Data set: Simple artificial prediction data for use with ROCR

Description

A mock data set containing a simple set of predictions and corresponding class labels.

Examples

# plot a ROC curve for a single prediction run
# and color the curve according to cutoff.
data(ROCR.simple)
pred <- span=""> prediction(ROCR.simple$predictions, ROCR.simple$labels)
perf <- span=""> performance(pred,"tpr","fpr")
plot(perf,colorize=TRUE)

ROCR.xval Data set: Artificial cross-validation data for use with ROCR

Description

A mock data set containing 10 sets of predictions and corresponding labels as would be obtained from 10-fold cross-validation.

Examples

# plot ROC curves for several cross-validation runs (dotted
# in grey), overlaid by the vertical average curve and boxplots
# showing the vertical spread around the average.
data(ROCR.xval)
pred <- span=""> prediction(ROCR.xval$predictions, ROCR.xval$labels)
perf <- span=""> performance(pred,"tpr","fpr")
plot(perf,col="grey82",lty=3)
plot(perf,lwd=3,avg="vertical",spread.estimate="boxplot",add=TRUE)