R: Function for a receiver operating characteristic curve (ROC)...

plotROC {PredictABEL}R Documentation

Function for a receiver operating characteristic curve (ROC) plot and area under the ROC curve (AUC) value.


The function produces ROC curve and corresponding AUC value with 95% CI. The function can plot one or multiple ROC curves in a single plot.


plotROC(data, cOutcome, predrisk, labels, plottitle, xlabel, ylabel, 
fileplot, plottype)



Data frame or matrix that includes the outcome and predictors variables.


Column number of the outcome variable.


Vector of predicted risk. When multiple curves need to be presented in one plot, specify multiple vectors of predicted risks as predrisk=cbind(predrisk1, predrisk2,...,predriskn).


Label(s) given to the ROC curve(s). Specification of labels is optional. When specified, the labels should be in the same order as specified in predrisk.


Title of the plot. Specification of plottitle is optional. Default is "ROC plot".


Label of x-axis. Specification of xlabel is optional. Default is "1- Specificity".


Label of y-axis. Specification of ylabel is optional. Default is "Sensitivity".


Name of the output file that contains the plot. The file is saved in the working directory in the format specified under plottype. Example: fileplot="plotname". Note that the extension is not specified here. When fileplot is not specified, the plot is not saved.


The format in which the plot is saved. Available formats are wmf, emf, png, jpg, jpeg, bmp, tif, tiff, ps, eps or pdf. For example, plottype="eps" will save the plot in eps format. When plottype is not specified, the plot will be saved in jpg format.


The function requirs predicted risks or risk scores and the outcome of interest for all individuals. Predicted risks can be obtained using the functions fitLogRegModel and predRisk or be imported from other methods or packages.


The function creates ROC plot and returns AUC value with 95% CI.


Hanley JA, McNeil BJ. The meaning and use of the area under a receiver operating characteristic (ROC) curve. Radiology 1982;143:29-36.

Tobias Sing, Oliver Sander, Niko Beerenwinkel, Thomas Lengauer. ROCR: visualizing classifier performance in R. Bioinformatics 2005;21(20):3940-3941.

See Also

predRisk, plotRiskDistribution


# specify the arguments in the function to produce ROC plot
# specify dataset with outcome and predictor variables
# specify column number of the outcome variable
cOutcome <- 2

# fit logistic regression models
# all steps needed to construct a logistic regression model are written in a function
# called 'ExampleModels', which is described on page 4-5
riskmodel1 <- ExampleModels()$riskModel1
riskmodel2 <- ExampleModels()$riskModel2

# obtain predicted risks
predRisk1 <- predRisk(riskmodel1)
predRisk2 <- predRisk(riskmodel2)

# specify label of the ROC curve
labels <- c("without genetic factors", "with genetic factors")

# produce ROC curve
plotROC(data=ExampleData, cOutcome=cOutcome, 
predrisk=cbind(predRisk1,predRisk2), labels=labels)