多因素生存分析图绘制
#1、生存分析和ROC曲線
數(shù)據(jù)格式
library(survival)
rt=read.table(“risk.txt”,header=T,sep="\t")
diff=survdiff(Surv(futime, fustat) ~risk,data = rt)
pValue=1-pchisq(diffKaTeX parse error: Expected 'EOF', got '#' at position 107: …ummary(fit) #?查看五年生存率 library…futime, status=rtfustat,marker=rtfustat, marker = rtfustat,marker=rtriskScore,
predict.time =3, method=“KM”)
tiff(file=“survival_ROC.tiff”,width = 20,height = 10,units =“cm”,compression=“l(fā)zw”,bg=“white”,res=500)
par(mfrow=c(1,2),cex.main=1.3, cex.lab=1.2, cex.axis=1.2, font=1.2, lwd = 2 )
plot(fit, lty = 2:3,col=c(“red”,“blue”),xlab=“time (year)”,ylab=“survival rate”,
main=paste(“survival curve (p=”, pValue ,")",sep=""),mark.time=T)
legend(“topright”, c(“high risk”, “l(fā)ow risk”), lty = 2:3, col=c(“red”,“blue”))
plot(rocFP,rocFP, rocFP,rocTP, type=“l(fā)”, xlim=c(0,1), ylim=c(0,1),col=‘red’,
xlab=“False positive rate”, ylab=“True positive rate”,
main=paste(“ROC curve (”, “AUC = “,round(roc$AUC,3),”)”))
abline(0,1)
dev.off()
#riskscore和生存時(shí)間
數(shù)據(jù)格式
#讀取數(shù)據(jù)
dat <- read.table(“risk.txt”,header = TRUE,sep="\t")
library(ggplot2)
library(gridExtra)
#對(duì)第五列的low和high計(jì)數(shù)
low <- sum(dat[,5]== “l(fā)ow”)
high <- sum(dat[,5]== “high”)
total <- low+high
#標(biāo)簽
lowlable=paste(“Low :”,low)
highlable=paste(“High :”,high)
#對(duì)第二列的Alive和Dead計(jì)數(shù)
Alive <- sum(dat[,2] == “Alive”)
Dead <- sum(dat[,2] == “Dead”)
#標(biāo)簽
Alivelable=paste(“Alive :”,Alive)
Deadlable=paste(“Dead :”,Dead)
#繪圖
tiff(file=“riskscore_sur_year.tiff”,width = 20,height = 10,units =“cm”,compression=“l(fā)zw”,bg=“white”,res=500)
p1 <- ggplot(dat,aes(x=x,y=riskScore)) + geom_point(shape=19,aes(colour = risk)) +xlab("") + ylab(“riskScore”) +
scale_color_manual(paste(“Risk”),values=c(“blue”,“red”))+
geom_vline(xintercept = 250,linetype =3,color=“blue”)+theme(panel.background = element_rect(fill = “transparent”, color = “gray”),legend.position=‘none’)
p2 <- ggplot(dat,aes(x=x,y=futime)) + geom_point(aes(colour = risk,shape=fustat)) +xlab("") + ylab(“Survival Year”) +
geom_vline(xintercept = 250,linetype =3,color=“red”)+theme(panel.background =
element_rect(fill = “transparent”, color = “gray”)) +scale_color_manual(paste(“Risk”), values=c(“blue”,“red”),labels=c(lowlable,highlable))+scale_shape_manual(paste(“Fustat”),
values=c(1,6),labels=c(Alivelable,Deadlable))
grid.arrange(p1,p2 ,widths=c(1.5,2),nrow=1)
dev.off()
多因素COX分析,生存圖和ROC曲線的優(yōu)化
總結(jié)
以上是生活随笔為你收集整理的多因素生存分析图绘制的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python 多因素方差分析
- 下一篇: 爬虫实战操作(2)—— 新浪新闻内容细节