reportROC包绘制ROC曲线、计算约登指数及各种度
2022-07-30 本文已影响0人
灵活胖子的进步之路
reportROC包可以通过一行代码绘制ROC曲线及计算敏感性、特异性、准确率、阳性预测值,阴性预测值,AUC值及约登指数
#官网地址:https://rdrr.io/cran/reportROC/
rm(list = ls())
options(stringsAsFactors = F)
library(reportROC)
# 1.官网示例 ------------------------------------------------------------------
data(aSAH)#示例数据
head(aSAH)
#for continuous variables
res.num<- reportROC(gold=aSAH$outcome,#金标准
predictor=aSAH$s100b,#预测变量
important="sp",# 选择截断值时候哪个更重要
plot=TRUE,#绘制ROC曲线
xlab = "1-specificity",
ylab = "sensitivity")
res.num
#for binary variables
binary=rep(0,nrow(aSAH))
binary[aSAH$s100b>=0.205]=1
aSAH$binary <- binary
head(aSAH)
reportROC(gold=aSAH$outcome,
predictor.binary=aSAH$binary,
important="se",# 选择截断值时候哪个更重要
plot=TRUE,#绘制ROC曲线
xlab = "1-specificity",
ylab = "sensitivity")
# 2.逻辑回归绘制ROC曲线及计算各种指标 ----------------------------------------------------
library(rms)
library(survival)
library(tidyverse)
library(broom)
data("cancer")
head(colon)
model <- glm(status ~ sex + rx +age,
binomial(link="logit"),
data = colon)
colon$predict <- predict(model,
newdata = colon,
type = "response")
head(colon$predict)
reportROC(gold=colon$status,
predictor=colon$predict,
important="se",# 选择截断值时候哪个更重要
plot=TRUE,#绘制ROC曲线
xlab = "1-specificity",
ylab = "sensitivity")
自测数据结果如下图
ROC曲线 数据化计算结果