I have a question regarding this C: Survival analysis of TCGA patients integrating gene expression (RNASeq) data
run survival analysis
s <- survfit(Surv(as.numeric(as.character(all_clin$new_death))[ind_clin],all_clin$death_event[ind_clin])~event_rna[ind_gene,ind_tum])
This can be calculated without any problem. However, I am wondering why one needs to create the event_rna
s1 <- tryCatch(survdiff(Surv(as.numeric(as.character(all_clin$new_death))[ind_clin],all_clin$death_event[ind_clin])~event_rna[ind_gene,ind_tum]), error = function(e) return(NA))
This gives me an empty list. What does it mean? why should it be empty?
# extraect the p.value
pv <- ifelse ( is.na(s1),next,(round(1 - pchisq(s1$chisq, length(s1$n) - 1),3)))[[1]]
I get this error for this command which is because I don't have the s1. So would it not be OK ?
Error in ifelseis.na(s1), next, (round(1 - pchisq(s1$chisq, length(s1$n) - :
no loop for break/next, jumping to top level
.
# plot the data
plot(survfit(Surv(as.numeric(as.character(all_clin$new_death))[ind_clin],all_clin$death_event[ind_clin])~event_rna[ind_gene,ind_tum]),
col=c(1:3), frame=F, lwd=2,main=paste('KIRK',rownames(z_rna)[ind_gene],sep='\n'))
This gives me three graph. Red, Green and Black. I guess normally it should give black and red, right?
# add lines for the median survival
x1 <- ifelse ( is.na(as.numeric(summary(s)$table[,'median'][1])),'NA',as.numeric(summary(s)$table[,'median'][1]))
x2 <- as.numeric(summary(s)$table[,'median'][2])
if(x1 != 'NA' & x2 != 'NA'){
lines(c(0,x1),c(0.5,0.5),col='blue')
lines(c(x1,x1),c(0,0.5),col='black')
lines(c(x2,x2),c(0,0.5),col='red')
}
I get this error
Error in summary(s)$table[, "median"] : incorrect number of dimensions
Please use below for an example
how i do survival analysis I am trying to give the data in R so that one can explain how to use it
df<- structure(list(sample = structure(c(3L, 3L, 1L, 2L, 3L, 3L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("Down",
"Up", "UP"), class = "factor"), new_time = c(42L, 52L, 99L, 41L,
20L, 6L, 4L, 11L, 47L, 29L, 4L, 8L, 10L, 28L, 16L, 18L, 32L,
26L), new_death = c(71L, 2L, 35L, 58L, 5L, 6L, 44L, 11L, 18L,
33L, 42L, 40L, 53L, 28L, 24L, 18L, 45L, 26L), death_event = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L,
0L)), .Names = c("sample", "new_time", "new_death", "death_event"
), class = "data.frame", row.names = c(NA, -18L))