2017-02-06 30 views
1

計算二分變量(a vs b)的ROC曲線後。我想計算最佳截止值來區分這個變量。 Youden指數是優化分化靈敏度和特異性的值。OptimalCutoff約登指數計算

顯然,包裝「OptimalCutpoints」應該能夠做到這一點。但是,我得到這個奇怪的錯誤。代碼插入如下:

library(pROC) 
library(OptimalCutpoints) 
df <- structure(list(value = c(1945.523629, 2095.549323, 2066.585153, 
         2445.878083, 2112.252632, 2115.92955, 2000.285032, 2224.611905, 
         1616.534694, 1668.017699, 1475.980978, 1940.849817, 1716.666667, 
         2153.284314, 2063.353635, 2163.070313, 1856.319149, 1499.986928, 
         2240.440449, 1869.083916, 1807.196078, 2025.603604, 1638.22973, 
         1781.602941, 2014.013809, 1906.027356, 2033.148718, 1923.403162, 
         1687.107744, 2632.280305, 1774.073084, 2196.162393, 2164.108659, 
         2055.031216, 2229.501425, 1273.872576, 2224.126126, 2006.858974, 
         1956.601942, 1808.214521, 1535.387136, 1382.15, 1596.69693, 1779.477273, 
         1577.174699, 1908.321526, 1833.124454, 1679.492978, 1777.31114, 
         1988.249023, 1736.75, 1985.68521, 1821.025974, 1745.325862, 1805.640777, 
         2326.821229, 1858.558824, 2025.622727, 2197.781321, 1475.685446, 
         2000.906423, 1714.749573, 1436.529412, 1981.15572, 1939.612779, 
         2007.679335, 2029.189536, 1644.298246, 1824.697342, 2281.990385, 
         2131.331776, 1143.722714, 1784.578076, 2143.131579, 982.4908457, 
         2217.021592, 1799.512346, 526.7047753, 1613.25, 951.9103079, 
         1006.241888, 1146.276835, 1651.474138, 1568.484778, 1938.867704, 
         792.5410822, 1602.037383, 1244.281863, 957.5739437, 819.6116071, 
         879.2128326, 1189.638632, 775.5525292, 1148.193333, 1130.812183, 
         902.34, 994.3302961), type = c("a", "a", "a", "a", "a", "a", 
                 "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", 
                 "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", 
                 "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", 
                 "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", 
                 "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", 
                 "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", 
                 "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b" 
         )), .Names = c("value", "type"), row.names = c(NA, -97L), class = "data.frame") 

rocobj <- plot.roc(df$type, df$value, percent = TRUE, main="ROC", col="#1c61b6", add=FALSE) 

optimal.cutpoint.Youden <- optimal.cutpoints(X = "value", status = "type", tag.healthy = 0, methods = "Youden", 
              data = df, pop.prev = NULL, 
              control = control.cutpoints(), ci.fit = FALSE, conf.level = 0.95, trace = FALSE) 
summary(optimal.cutpoint.Youden) 
plot(optimal.cutpoint.Youden) 

錯誤:您的數據集中沒有健康主題。請查看數據和 變量。流行率必須是高於0且低於1的值。

我可能在這裏丟失了一些非常明顯的東西。我試圖修改基於包幫助文件的代碼,但是我無法擺脫這個錯誤。

非常感謝你和我道歉我R「技能」

PS:我的理解定義「最佳截止」的限制,因爲它取決於你的敏感是多麼重要與你的特異性等我想知道我們使用這種技術會獲得什麼樣的價值。

+0

您可以通過手動計算閾值來驗證此軟件包的輸出,此處介紹的過程[最佳閾值](http://stats.stackexchange.com/questions/25389/obtaining-predicted-values-y-1-or- 0-from-a-logistic-regression-model-fit) – OdeToMyFiddle

回答

1

問題在於你如何定義tag.healthy的說法。它應該是'a''b',因爲它們在您的數據中。您已將其定義爲0

希望這會有所幫助。

+1

我真是個白癡。我認爲tag.healthy的論點反映了沒有a或b的主題。謝謝! – Hendrik

+0

@亨德里克您的歡迎,請記住幫助文件是您的朋友:) –