## 安装pROC install.packages("pROC") ## 读取数据 data = read.table("示例数据.txt",sep = "\t",header = T, stringsAsFactors = F) ## 加载pROC包 library(pROC) ## 单个ROC分析 roc = roc(data$status, data$gene1, percent = TRUE, ci = TRUE) ## ROC分析 best = coords(roc, "best", ret = "all", transpose = F) ## 最佳分割点 outTab = data.frame( Gene = "gene1", AUC = round(roc$auc,3), "95% CI" = paste(round(roc$ci[c(1,3)],3),collapse = "-"), "Cutoff value" = round(best$threshold,3), Spensitivity = round(best$sensitivity,3), Specificity = round(best$specificity,3), check.names = FALSE ) write.table(outTab,"ROC.result.txt", row.names = F, sep = "\t", quote = F) ## 输出ROC分析结果 ## 输出ROC曲线 pdf("ROC.pdf",width = 5,height = 5) plot.roc(roc,col="red", identity.col = "blue", legacy.axes = TRUE) legend("bottomright", c(paste("AUC = ",round(roc$auc,3),sep = ""), ## AUC表示曲线下面积 paste("Cutoff value = ",round(best$threshold,3),sep = ""), ## Cutoff value表示最佳分割点 paste("Spensitivity = ",round(best$sensitivity,3),sep = ""), ## Spensitivity 表示最佳分割点对应的敏感性 paste("Specificity = ",round(best$specificity,3), sep = "")),## Specificity 表示最佳分割点对应的特异性 bty = "n" ) dev.off()