R 语言COX分析—科研工具箱

请关注公众号【叨客学习资料】 在使用网站的过程中有疑问,请来公众号进行反馈哦

示例:

 

sample hsa-miR-339-5p hsa-miR-324-5p Event months
TCGA-NJ-A4YP 5.37649676 4.57839941 Alive 1.64
TCGA-86-8278 4.340845007 3.698656714 Alive 31.01
TCGA-62-A470 5.55662622 5.913658335 Dead 39.22
TCGA-44-6778 4.76629652 2.877071024 Alive 61.24
TCGA-49-AARQ 6.90221694 5.896734003 Alive 221.16
TCGA-97-A4M1 5.5758414 4.864950886 Alive 19.74
TCGA-99-8033 5.773618233 5.035791207 Dead 21.55
TCGA-78-7149 3.56912225 4.834641484 Alive 129.43
TCGA-50-6597 5.207816378 3.943285313 Dead 41.66
TCGA-69-8255 5.138845111 4.745133898 Alive 4.24

rm(list = ls())

setwd(“D:/”)

library(readxl)

library(survival)

library(plyr)

LUAD<-read_xlsx(“LUAD2.xlsx”)

attach(LUAD)

#单因素COX

#无NA

my.surv <- Surv(`months` ,Event==”Dead”)

m=coxph(my.surv~`hsa-miR-148a-3p`,data = LUAD)

sm<-summary(m)

HR <- round(sm$coefficients[,2],3)

HRCILL <- round(sm$conf.int[,3],3)

HRCIUL <- round(sm$conf.int[,4],3)

pValue <- round(sm$coefficients[,5],3)

tmp <- data.frame(“miRNAs” = colnames(LUAD0)[2],

 “N”= nrow(LUAD0),

 “pValue” = pValue,

 “HR” = HR,

 “HRCILL” = HRCILL,

 “HRCIUL” = HRCIUL)

unicox<-function(x){

 FML <- as.formula(paste0(“my.surv~”,x))

 m=coxph(FML,data = LUAD)

 sm<-summary(m)

 HR <- round(sm$coefficients[,2],3)

 HRCILL <- round(sm$conf.int[,3],3)

 HRCIUL <- round(sm$conf.int[,4],3)

 pValue <- round(sm$coefficients[,5],3)

 tmp <- data.frame(“miRNAs” = colnames(LUAD0)[2],

“N”= nrow(LUAD0),

“pValue” = pValue,

“HR” = HR,

“HRCILL” = HRCILL,

“HRCIUL” = HRCIUL)

 return(tmp)

}

varNames <- colnames(LUAD)[c(2:200)]

univar <- lapply(varNames, unicox)

univar <- ldply(univar,data.frame)

#有NA

unicox<-function(x){

 LUAD0 <- LUAD[,c(1,x,201,202)]

 LUAD0 <- na.omit(LUAD0)

 if(length(which((LUAD0[,3]==”Dead”)))<20)

{

return()

} else {

 my.surv <- Surv(LUAD0$months ,LUAD0$Event==”Dead”)

 FML <- as.formula(paste0(“my.surv~”,colnames(LUAD0)[2]))

 m=coxph(FML,data = LUAD0)

 sm<-summary(m)

 HR <- round(sm$coefficients[,2],3)

 HRCILL <- round(sm$conf.int[,3],3)

 HRCIUL <- round(sm$conf.int[,4],3)

 pValue <- round(sm$coefficients[,5],3)

 tmp <- data.frame(“miRNAs” = colnames(LUAD0)[2],

“N”= nrow(LUAD0),

“pValue” = pValue,

“HR” = HR,

“HRCILL” = HRCILL,

“HRCIUL” = HRCIUL)

 return(tmp)

}

}

univar <- lapply(c(2:200), unicox)

univar <- ldply(univar, data.frame)

View(univar)

sigCOX <- univar[which(univar[,3]<0.05),]

sigCOX <- sigCOX[order(sigCOX$pValue,decreasing = F),]

#多因素Cox

attach(LUAD)

my.surv <- Surv(`months` ,Event==”Dead”)

multicox <- oxph(my.surv~hsa_miR_148a_3p+hsa_miR_6715b_3p+hsa_miR_133b+hsa_miR_148a_5p+hsa_miR_199b_5p+hsa_miR_145_3p+hsa_miR_133a_3p+hsa_let_7c_5p+hsa_miR_195_5p+hsa_miR_30a_5p,data = LUAD)

multisum <- summary(multicox)

MHR <- round(multisum$coefficients[,2],3)

MPV <- round(multisum$coefficients[,5],3)

MCIL <- round(multisum$conf.int[,3],3)

MCIU <- round(multisum$conf.int[,4],3)

multicox <- data.frame(“pValue” = MPV,

  “HR” = MHR,

  “MCIL” = MCIL,

  “MCIU” = MCIU)

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
请输入有效评论哦,肆意灌水或者乱打评论是不会通过的,会影响您评论后获得资源哦~~
提交
头像

昵称

取消
昵称表情

    暂无评论内容