Description Usage Arguments Details Value Examples
The AUC function calculates the numeric value of area under the ROC curve (AUC) with the trapezoidal rule and optionally plots the ROC curve
1 |
prob |
A numeric vector of predicted probability |
outcome |
A numeric vector of observed binary outcome |
cutoff |
Number between 0 and 1 to specify where threshold of ROC curve should be truncated. The default value is 1 (no truncation) |
ROC.plot |
Logical. Whether or not to plot ROC curve |
The ROC curve is created by plotting the true positive rate (TPR) against the false positive rate (FPR) at different threshold settings.
By default the total area under the curve is computed, but a truncated AUC statistics can be specified with the cutoff argument. It specifies the bounds of FPR. The common choice of cutoff can be 1 (i.e. no truncate) or 0.2 (i.e. specificity > 0.8)
The value of the area under the curve.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | set.seed(1)
# simulate predictors
x1 <- rnorm(200)
x2 <- rnorm(200)
# simulate outcome
pr <- 1/(1+exp(-(3 * x1 + 2 * x2 + 1)))
y <- rbinom(200, 1, pr)
df <- data.frame(y = y,x1 = x1, x2 = x2)
# fit logistic regression model on the first 100 observation
lg.model <- glm(y ~ x1 + x2, data = df[1 : 100, ], family="binomial")
# predict outcome for the last 100 observation
prob <- predict(lg.model, df[101:200, c("x1", "x2")], type = "response")
# calculate AUC and plot thr ROC Curve
AUC(prob, y[101:200], ROC=TRUE)
# calculate AUC and plot thr ROC Curve with cutoff
AUC(prob, y[101:200], cutoff=0.2, ROC=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.