Learn R Programming

ModelGood (version 1.0.9)

plot.Roc: ROC curves for risk prediction models

Description

ROC curves for risk prediction models

Usage

"plot"(x, ylab = "Sensitivity", xlab = "1-Specificity", models, type = "l", shadow = FALSE, simu = FALSE, control, grid = FALSE, diag = TRUE, box = FALSE, lwd = 2, lty, col, add = FALSE, axes = TRUE, legend, auc, percent = TRUE, ...)

Arguments

x
object obtained with Roc
ylab
Label y-axis
xlab
Label x-axis
models
Selection of models to plot. Should be a subset of names(x$models). Makes sense when x contains multiple ROC curves.
type
The line type
shadow
Experimental. Show results of cross-validation.
simu
Experimental. Show noinformation results.
control
Control which estimates of the ROC curves to draw.
grid
If TRUE add a grid in the background of the graph.
diag
If TRUE add a diagonal line.
box
If TRUE add a box around the graph.
lwd
Vector of line widths for the ROC curves.
lty
Vector of line types for the ROC curves.
col
Vector of colours for the ROC curves.
add
If TRUE add ROC curves to existing plot.
axes
If TRUE draw axes.
legend
If TRUE draw a legend.
auc
If TRUE add the area under the curve to the legend.
percent
If TRUE show percent axes.
...
Use for smart control of some plot elements.

Value

ROC curves

Details

Multiple ROC curves are shown in one graph.

See Also

Roc

Examples

Run this code
# generate som data
set.seed(40)
N=40
Y=rbinom(N,1,.5)
X1=rnorm(N)
X1[Y==1]=rnorm(sum(Y==1),mean=rbinom(sum(Y==1),1,.5))
X2=rnorm(N)
X2[Y==0]=rnorm(sum(Y==0),mean=rbinom(sum(Y==0),1,.5))
dat <- data.frame(Y=Y,X1=X1,X2=X2)

# fit two logistic regression models
lm1 <- glm(Y~X1,data=dat,family="binomial")
lm2 <- glm(Y~X2+X1,data=dat,family="binomial")
plot(Roc(list(lm1,lm2),data=dat))

# add the area under the curves

plot(Roc(list(lm1,lm2),data=dat),auc=TRUE)

# alternatively, one can directly work with formula objects:
plot(Roc(list(LR.X1=Y~X1,LR.X1.X2=Y~X2+X1),data=dat),auc=TRUE)

# beyond the logistic regression model.
# the following example is optimized for speed
# illustrating the syntax,
# and not for optimized for performance of the
# randomForest or elastic net
library(randomForest)
library(glmnet)
dat$Y=factor(dat$Y)
rf <- randomForest(Y~X1+X2,data=dat,ntree=10)
en <- ElasticNet(Y~X1+X2,data=dat,nfolds=10,alpha=0.1)
set.seed(6)
rocCV=Roc(list(RandomForest=rf,ElasticNet=en,LogisticRegression=lm2),
  data=dat,
  verbose=FALSE,
  splitMethod="bootcv",
  B=4,
  cbRatio=1)
plot(rocCV,yaxis.las=2,legend.title="4 bootstrap-crossvalidation steps")

Run the code above in your browser using DataLab