三线表本来是微软公司的word编辑器里面的概念,就是表属性中,边框里只留上、下内框和标题/层分隔符,其他都选择无就可以了。
但是迁移到临床数据里面,就稍微复杂了一点,就是把条目繁多的临床资料整理一下,比如下面这些信息:
应该是前年,唐医生就提到过有一个R包,名字就是tableone可以做,所以我当时就写了教程,发在GitHub的TCGA视频课程上面,全部代码如下:
代码语言:javascript复制step00-install-packages.R
step01-getData-from-GDC.R
step01-getData-from-RTCGA.R
step01-getData-from-Xena.R
step01-getData-from-firehose.R
step02-DEG-3-packages.R
step03-batch-logRank.R
step04-batch-coxp.R
step05-lasso.R
step06-coxph-forest.R
step07-risk-score-distribution.R
step08-Random-foreast.R
step09-miRNA-downstream.R
step10-maftools.R
step11-boxplot.R
step12-correlation.R
step13-split-cohort.R
step14-timeROC.R
step15-choose_lncRNA.R
step16-clinical-tables.R
step17-mutation-signatures.R
step17-others.R
step18-SVM.R
测试数据的临床信息
文章开头展示的就是tableone的临床数据咯
代码语言:javascript复制library(tableone)
## survival pcakge for Mayo clinical_infoic's PBC data
library(survival)
data(pbc)
head(pbc)
其实一行代码就可以输出最简易的临床三线表啦
代码语言:javascript复制CreateTableOne(data = pbc)
一般来说,临床数据需要仔细调整
使用别人的R包,测试数据的运行,当然很简单啊, 但是大部分情况下,都得仔细认真读R包文档,把自己的数据折腾清洗成为测试数据的样子。
下面就是数据清洗的代码,直接复制粘贴到R里面就可以运行哦,不过tableone包需要你自行安装。
代码语言:javascript复制tmpf=tempfile()
download.file('http://bio-info-trainee.com/tmp/TCGA-LUAD-phe_clinical_tables.Rdata', tmpf)
load(tmpf)
clinical_info=phe
head(clinical_info)
#首先对需要观测的临床特质值进行重新编码
clinical_info$age<-as.numeric(clinical_info$age)
clinical_info$AGE<-factor(ifelse(clinical_info$age>60,'>60','<=60'),ordered = T)
clinical_info$gender<-factor(toupper(clinical_info$gender),levels=c("MALE", "FEMALE"),ordered = T)
clinical_info$stage<-factor(toupper(clinical_info$stage),ordered = T)
clinical_info$t<-factor(clinical_info$t,ordered = T)
clinical_info$n<-factor(clinical_info$n,ordered = T)
clinical_info$m<-factor(clinical_info$m,ordered = T)
clinical_info$vital_status<-factor(toupper(clinical_info$vital_status),ordered = T)
clinical_info$race<-factor(clinical_info$race,ordered = T)
# 去除不需要的临床信息
clinical_info=clinical_info[,-c(1,10:12)]
dput(names(clinical_info))
## Vector of variables to summarize
myVars <- dput(names(clinical_info))
## Vector of categorical variables that need transformation
catVars <- myVars[c(1,2,4:8,10)]
## ------------------------------------------------------------------------
##三线表类型之一 切割数据
library(caret)
set.seed(123456789)
sam<- createDataPartition(clinical_info$vital_status, p = .5,list = FALSE)
train <- clinical_info[sam,]
test <- clinical_info[-sam,]
#查看两组一些临床参数切割比例
prop.table(table(train$stage))
prop.table(table(test$stage))
#添加分组
train$group<-'training datasets'
test$group<-'testing datasets'
clinical_info<-rbind(train,test)
clinical_info$group<-factor(clinical_info$group)
##生成三线表
vars <-colnames(clinical_info)[c(2:9,12,14,15)]
library(tableone)
## 最重要的三线表通常是以训练集和数据集来区分:group
tb_group<-CreateTableOne(vars = myVars, strata = c("group"), data = clinical_info,
factorVars = catVars)
tab1<-print(tb_group, nonnormal = c('age','time'),
exact = c(myVars,'AGE'), smd = TRUE)
summary(tab1)
tab_out<-print(tb_group, catDigits = 1, contDigits = 2, pDigits = 3,
quote = FALSE, missing = T, explain = TRUE, printToggle = TRUE,
test = TRUE, smd = T, noSpaces = FALSE, padColnames = FALSE,
varLabels = FALSE, format = c("fp", "f", "p", "pf")[1],
showAllLevels = FALSE, cramVars = NULL, dropEqual = FALSE,
exact = NULL, nonnormal = NULL, minMax = FALSE)
## Save to a CSV file
write.csv(tab_out, file = "TCGA-LUAD-phe_clinical_tables1.csv")
才能得到下面的临床三线表:
这样的数据就可以在Excel或者word里面慢慢调整成为发表级别啦!