各位大神,为什么循环运行不了,但是单独的赋值就可以运行。
for (i in 3:23){
gene <- colnames(rt1)[i]
sur.cut <- surv_cutpoint(rt1,time = 'futime',event = 'fustat',variables =as.vector(gene))
risk=as.vector(ifelse(rt1[,i]>sur.cut$cutpoint$cutpoint,"high","low"))
diff=survdiff(Surv(futime, fustat) ~risk,data = rt1)
pValue=1-pchisq(diff$chisq,df=1)
if(pValue<0.001){
pValue="p<0.001"
}else{
pValue=paste0("p=",sprintf("%.03f",pValue))}
name1 <- list('high','low')
n1 <- sum(risk=='high')
n2 <- sum(risk=='low')
n <- c(n1,n2)
labels=paste0(name1,"(n=",n,")")
fit <- survfit(Surv(futime, fustat) ~ risk, data = rt1)
filen <- paste0(gene,' survival.pdf')
pdf(file=filen,onefile = FALSE,
width = 5.5, #图片的宽度
height =5) #图片的高度
ggsurvplot(fit,
data=rt1,
pval=pValue,
pval.size=6,
legend.labs=labels,
legend.title="Risk",
xlab="Time(years)",
break.time.by = 1,
palette=c("red", "blue") )
dev.off()}