赞
踩
#1、生存分析和ROC曲线
数据格式
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=rt
f
u
s
t
a
t
,
m
a
r
k
e
r
=
r
t
fustat, marker = rt
fustat,marker=rtriskScore,
predict.time =3, method=“KM”)
tiff(file=“survival_ROC.tiff”,width = 20,height = 10,units =“cm”,compression=“lzw”,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”, “low risk”), lty = 2:3, col=c(“red”,“blue”))
plot(roc
F
P
,
r
o
c
FP, roc
FP,rocTP, type=“l”, 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和生存时间
数据格式
#读取数据
dat <- read.table(“risk.txt”,header = TRUE,sep="\t")
library(ggplot2)
library(gridExtra)
#对第五列的low和high计数
low <- sum(dat[,5]== “low”)
high <- sum(dat[,5]== “high”)
total <- low+high
#标签
lowlable=paste(“Low :”,low)
highlable=paste(“High :”,high)
#对第二列的Alive和Dead计数
Alive <- sum(dat[,2] == “Alive”)
Dead <- sum(dat[,2] == “Dead”)
#标签
Alivelable=paste(“Alive :”,Alive)
Deadlable=paste(“Dead :”,Dead)
#绘图
tiff(file=“riskscore_sur_year.tiff”,width = 20,height = 10,units =“cm”,compression=“lzw”,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曲线的优化
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。