R语言(pROC)

> 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%

你可能感兴趣的:(R,Project)