ROC_func: Plot the ROC curve and calculate the AUC

View source: R/bsnsing.R

ROC_funcR Documentation

Plot the ROC curve and calculate the AUC

Description

This is a general utility function, not part of the bsnsing functionality.

Usage

ROC_func(
  df,
  label_colnum,
  score_colnum,
  pos.label = "1",
  plot.ROC = F,
  add_on = F,
  color = "black",
  lty = 1
)

Arguments

df

a data frame which must contain at least these two columns: the prediction scores (numeric values, not necessarily be between 0 and 1) and the true class labels.

label_colnum

the column index of the scores column in df

score_colnum

the column index of the true class labels column in df

pos.label

a character string matching the positive class label used in the class labels column

plot.ROC

a logical value indicating whether the ROC curve should be plotted

add_on

a logical value indicating whether the ROC curve should be added to an existing plot

color

a character string specifying the color of the ROC curve in the plot

lty

line type used in the plot (1 solid, 2 dashed, etc.)

Value

the area under the curve (AUC) value

Examples

## Not run: 
n <- nrow(BreastCancer)
trainset <- sample(1:n, 0.7*n)  # randomly sample 70\
testset <- setdiff(1:n, trainset)  # the remaining is for testing
# Build a tree to predict Class, using all default options
bs <- bsnsing(Class~., data = BreastCancer[trainset,])
summary(bs)  # display the tree structure
pred <- predict(bs, BreastCancer[testset,], type='class')
actual <- BreastCancer[testset, 'Class']
table(pred, actual)  # display the confusion matrix
# Plot the ROC curve and display the AUC
ROC_func(data.frame(predict(bs, BreastCancer[testset,]),
                    BreastCancer[testset,'Class']), 2, 1,
         pos.label = 'malignant', plot.ROC=TRUE)
# Plot the tree to PDF and generate the .tex file
plot(bs, file='../bsnsing_test/fig/BreastCancer.pdf')

## End(Not run)

profyliu/bsnsing documentation built on July 5, 2022, 8:10 a.m.