1

使用 pROC 包计算 TPR 和 FPR。我可以在使用包的计算中指定我想要的阈值吗?

我要计算阈值从 0 到 1 的 TPR 和 FPR,增量为 0.05。

这是我正在使用的数据集:

structure(list(prediction_resp_4 = c(0.0093660156194744, 0.63696691410065, 
0.693562340217509, 0.850026939982271, 0.0921374166454612, 0.223883311111169, 
0.000699258172241612, 0.117062385395824, 0.951947429014154, 0.714711536699156, 
0.230100717565363, 0.839895799034341, 0.149678433930086, 0.0913803675468538, 
0.86430898026459, 0.0807110314548418, 0.452757912184497, 0.819293921115556, 
0.0700190883640999, 0.44900095299551, 0.803772423123997, 0.373799624421601, 
0.122405205571954, 0.858831937028595, 0.276135791757235, 0.86129869300195, 
0.674060141486476, 0.303046534598074, 0.356020758015023, 0.0246899999008411, 
0.670342328628664, 0.0178170992678319, 0.0945567242524256, 0.0110559559742041, 
0.356077534809716, 0.0792480681507026, 0.630756724182966, 0.0165338433136149, 
0.816750535548877, 0.661098390528446, 0.0587373125478858, 0.315062410973728, 
0.831315518918304, 0.463520030831427, 0.725937488979879, 0.301643645590828, 
0.288625193696339, 0.9038875106375, 0.780722912230085, 0.37912106477669, 
0.136094212636133, 0.503643519530075, 0.544482442341009, 0.575738927352128, 
0.356077534809716, 0.722011034808203, 0.760550508601042, 0.603109270061287, 
0.793014589613734, 0.834485477242473, 0.783008040183127, 0.365330782046478, 
0.022358212647161, 0.0884525015278602, 0.200257196356859, 0.912502624283191, 
0.230100717565363, 0.112122111461138, 0.453938368209989, 0.704600061065344, 
0.224872418284352, 0.395491910748845, 0.999703986760998, 0.794479788600805, 
0.385076713799569, 0.0305635117938959, 0.92898574855535, 0.163314780984271, 
0.893410014409946, 0.496199240836053, 0.618023472980794, 0.584273518401166, 
0.295133623201644, 0.12042873699888, 0.251479713644139, 0.825885814333607, 
0.674317836386347, 0.371047453863054, 0.645239618141106, 0.00544077442795404, 
0.377910289600606, 0.936696423985203, 0.418497325382622, 0.871684421084382, 
0.345285714385491, 0.835470162627044, 0.0581701844461216, 0.612133334197249, 
0.675206715878502, 0.667971057122422), landslide.validation.lslpts = c(0, 
1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 
0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 
0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 
0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 
1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0)), row.names = c(NA, 
100L), class = "data.frame")

我有回应和预测。

这个 pROC 包允许我计算所有可能的阈值。

我当前的代码如下:

library(pROC)
myRoc <- roc(response = new_df$landslide.validation.lslpts, predictor = new_df$prediction_resp_4)

ROC <-data.frame(myRoc$sensitivities, myRoc$specificities, myRoc$thresholds)

预计以 0.05 的增量计算从 0 到 1 的阈值的 TPR 和 FPR。我该怎么做呢?

任何帮助将不胜感激。谢谢

4

1 回答 1

2

尽管您无法指定用于构建ROC 曲线本身的阈值(因为 ROC 曲线根据定义会超过所有阈值),但您可以使用该coords函数轻松提取所需的信息:

> coords(myRoc, seq(0, 1, 0.05))
            0      0.05       0.1      0.15       0.2      0.25       0.3 ...
threshold   0 0.0500000 0.1000000 0.1500000 0.2000000 0.2500000 0.3000000 ...
specificity 0 0.1568627 0.3333333 0.4509804 0.4705882 0.5098039 0.5882353 ...
sensitivity 1 0.9795918 0.9795918 0.9795918 0.9795918 0.9183673 0.9183673 ...

注意到:

  • TPR = 灵敏度
  • FPR = 1 - 特异性

请注意,尽管您有 FPR 和 TPR,但这不是 ROC 曲线,因为它不会超过所有可能的阈值。

于 2019-04-01T06:37:48.227 回答