任务描述:采取R语言绘制ROC曲线

参考文献:link.

专业背景:临床医学(心血管病学)

数据库:R语言的公共数据库

软件环境

R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
> library(pROC)
Type 'citation("pROC")' for a citation.载入程辑包:‘pROC’The following objects are masked from ‘package:stats’:cov, smooth, var> aSAHgos6 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%

绘图部分

#######  加载程序包  ########
> library(pROC)
> library(ggplot2)
######  查看数据库  #######
> summary(aSAH$outcome)
Good Poor 72   41
######  构建方程  #########
> rocs100b <- roc(aSAH$outcome, aSAH$s100b)
Setting levels: control = Good, case = Poor
Setting direction: controls < cases
> rocage <- roc(aSAH$outcome, aSAH$age)
Setting levels: control = Good, case = Poor
Setting direction: controls < cases
#########  1.0版本的图像  ############
> g <- ggroc(rocs100b)
#########  2.0版本的图像  ############
> ggroc(rocs100b, alpha = 0.5, colour = "red", linetype = 2, size = 2)
#########  3.0版本的图像  ############
> g + theme_minimal() + ggtitle("My ROC curve") +geom_segment(aes(x = 1, xend = 0, y = 0, yend = 1), colour = "grey", linetype = "dashed")
#########  4.0版本的图像(改变X轴) ########
> g1 <- ggroc(rocs100b, legacy.axes = TRUE)
> g1
> g1 + xlab("FRR") + ylab("TRR") +geom_segment(aes(x = 0, xend = 1, y = 0, yend = 1), colour = "darkgrey", linetype = "dashed")

######### 绘制多条曲线 ##########
> g2 <- ggroc(list(s100b = rocs100b, age = rocage), legacy.axes = TRUE)
> g2

R语言(pROC)绘图相关推荐

  1. R语言可视化绘图基础知识详解

    R语言可视化绘图基础知识详解 图形参数:字体.坐标.颜色.标签等: 图像符号和线条: 文本属性: 图像尺寸及边界: 坐标轴.图例自定义等: 图像的组合: #install.packages(c(&qu ...

  2. R语言画图/绘图/作图2

    R语言画图/绘图/作图2 动画气泡图 可以使用该gganimate包实现动画气泡图.它与气泡图相同,但是,您必须显示值如何在第五维(通常是时间)上变化. 要做的关键是将 设置为aes(frame)要在 ...

  3. 【R语言科研绘图】--- 柱状图

    R语言科研绘图--柱状图 柱状图 R语言科研绘图--柱状图 前言 一.柱状图 二.使用工具 1.所使用的包 2.数据特征 3.绘图 3.1 两组均值之间的比较 3.2 多组均值之间的比较 后记 前言 ...

  4. r语言各形状编号_190+张图片!吐血整理!搞定R语言基础绘图全部知识点

    转自:生信宝典|Bio_Data,不一样的生信学习平台 原文链接:ggplot2高效实用指南 (可视化脚本.工具.套路.配色) 作者:严涛 浙江大学作物遗传育种在读研究生(生物信息学方向)伪码农,R语 ...

  5. R语言-时间序列绘图

    使用R语言,在一个绘图窗口中绘制两个图形,使用布局管理器来实现. 1.绘制自相关和偏自相关图的命令为: > par(pin=c(4,2),mfrow=c(2,1))    #设置图形大小(长4英 ...

  6. R语言ggplot绘图

    一.R语言ggplot2绘折线图 读取文件放置的位置,赋予数组名称 library(ggplot2) setwd("E:\\Buffer\\My work\\ggplot_data" ...

  7. matlab中gen2par函数,R语言中绘图par()函数用法

    图形参数 当参数no.readonly=TRUE时,函数par()就只允许有这一个参数了,并且会返回当前绘图设备中各个参数的参数值. 每一个图形设备都有自己的绘图参数,如果当前还没有打开绘图设备,那么 ...

  8. R语言高级绘图命令(标题-颜色等)

    plot(x) 以x的元素值为纵坐标.以序号为横坐标绘图 plot(x,y) x(在x-轴上)与y(在y-轴上)的二元作图 sunflowerplot(x,y)同上,但是以相似坐标的点作为花朵,其花瓣 ...

  9. R语言ggplot2绘图——柱状图

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_34023608/article/details/51852211 </div>&l ...

  10. R语言ggplot2绘图教程——Pathway富集分析气泡图

    library(ggplot2) pathway = read.table("C://Users//Desktop//path.richFactor.head20.tsv",hea ...

最新文章

  1. Python读取文件夹下的所有文件,并获得文件中的2-10行的信息
  2. 夏日php登录系统源码,夏日PHP企业管理系统 v0.1
  3. oracle插入表为文件,将文本文件插入Oracle表中
  4. 在Ubuntu服务器上使用python3+selenium模块
  5. 【Git+Docker】Docker初期学习认识和安装配置详解
  6. 事物的开始和结束命令分别是什么_AutoCAD小秘密065:LOFT命令,创建天圆地方
  7. 修改无效_解决docker部署gitlab时,clone地址无效和修改默认端口
  8. poj1064 二分搜索 挑战程序设计竞赛
  9. Webstorm React Nodejs 整合
  10. 如何解决python 图表中文显示乱码问题(matlplotlib 包)
  11. android5.0百度地图,百度地图安卓版5.0.0 官方版
  12. cr2格式缩略图不显示,怎么把raw格式显示出缩略图
  13. html表格制作练习
  14. JQuery右下角弹窗广告
  15. H5 实现类似QQ消息列表(已读,未读)拖拽点击事件功能
  16. 苹果开发者中心如何上传构建版本
  17. 冬虫夏草之技术路线图之三【“路”——经营篇】
  18. O2O新猜想:如果商家这样做,还需要团购平台吗
  19. ipcam rtsp流生成 mp4( 附源码)
  20. 我和CSDN的故事--学无止境

热门文章

  1. 【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  2. MySQL系列数据库的安装和基本的使用方法笔记(MySQL,MariaDB)
  3. 微博营销技巧都有哪些?应该从哪些方面入手?
  4. 引爆寒假招生——圣诞节活动方案大放送
  5. 科技爱好者周刊(第 190 期):产品化思维
  6. 转-- 一位存储研发者的图书清单
  7. 新手都能用到的140个电脑技巧
  8. java 卸载工具_java卸载工具下载
  9. python允许无止境的循环_A-level Computer Science 计算机科学学习笔记/经验分享/教程 (12.6):PHP...
  10. C语言 由拼音字串获取拼音数量