R語言(pROC)
阿新 • • 發佈:2018-11-09
> library(pROC)
Type 'citation("pROC")' for a citation.
載入程輯包:‘pROC’
The following objects are masked from ‘package:stats’:
cov, smooth, var
> data("aSAH")
> aSAH
gos6 outcome gender age wfns s100b ndka
29 5 Good Female 42 1 0.13 3.01
30 5 Good Female 37 1 0.14 8.54
31 5 Good Female 42 1 0.10 8.09
32 5 Good Female 27 1 0.04 10.42
33 1 Poor Female 42 3 0.13 17.40
34 1 Poor Male 48 2 0.10 12.75
//# Build a ROC object and compute the AUC
> roc(aSAH$outcome,aSAH$s100b)
Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b)
Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Area under the curve: 0.7314
//# Smooth ROC curve
> roc(aSAH$outcome,aSAH$s100b,smooth = TRUE)
Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b, smooth = TRUE)
Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal
Area under the curve: 0.74
> levels(aSAH$outcome)
[1] "Good" "Poor"
//# more options, CI and plotting
> roc1 <- roc(aSAH$outcome,aSAH$s100b,smooth = TRUE,percent = TRUE,partial.auc = c(100,90),partial.auc.correct = TRUE,partial.auc.focus = "sens",ci = TRUE,boot.n = 100,ci.alpha = 0.9,stratified = FALSE,plot = TRUE,auc.polygon = TRUE,max.auc.polygon = TRUE,grid = TRUE)
Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b, percent = TRUE, smooth = TRUE, ci = TRUE, plot = TRUE, partial.auc = c(100, 90), partial.auc.correct = TRUE, partial.auc.focus = "sens", boot.n = 100, ci.alpha = 0.9, stratified = FALSE, auc.polygon = TRUE, max.auc.polygon = TRUE, grid = TRUE)
Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Smoothing: binormal
Corrected partial area under the curve (sensitivity 100%-90%): 55.63%
95% CI: 50.02%-66.08% (100 stratified bootstrap replicates)
//計算曲線下面積和部分曲線下面積
> auc(roc1)
Area under the curve: 74%>
> auc(roc1,partial.auc =c(1,10))
Partial area under the curve (specificity 10%-1%): 8.857%
> auc(roc1,partial.auc =c(1,0))
Partial area under the curve (specificity 1%-0%): 0.9985%
> auc(roc1,partial.auc =c(0,100))
Partial area under the curve (specificity 100%-0%): 74%