I'm trying to run a survival analysis in R using the survival
package. I have right-censored data only (time to event, then event "1" or censor "0"). I created a survival object using the Surv
function. However, survdiff
and coxph
give errors, suggesting that they do not recognize it as right-censored data. Any advice?
> surv.dfs <- Surv(DaysFromTx,Event)
> surv.dfs
[1] 99:1 334:1 1024+ 1341+ 210+ 1069+ 890+ 1242+ 255+ 228+ 349+ 300+ 717+ 2+ 657+ 995+ 491+ 1544+ 265:1 440+ 362:1 845+
[23] 669+ 1176+ 718+ 768+ 1171+ 2276+ 1152+ 207+ 1138+ 1002+ 942+ 644+ 1110+ 179:1 1535+ 841+ 923+ 904+ 367:1 959+ 746+ 1256+
[45] 83:1 439:1 69+ 449+ 591+ 983+ 787+ 704+ 825+ 747+ 28+ 41+ 907+ 181:1 371+ 388+ 166:1 702+ 647+ 944+ 903+ 797+
[67] 1095+ 770:1 1118+ 63:1 1762+ 1662+ 127:1 634+ 312+ 483+
> survdiff(surv.dfs ~ group)
Error in survdiff(surv.dfs ~ group) : Right censored data only
> coxph(surv.dfs ~ group)
Error in coxph(surv.dfs ~ group) : Cox model doesn't support "mright" survival data
Censoring. Censoring is a form of missing data problem in which time to event is not observed for reasons such as termination of study before all recruited subjects have shown the event of interest or the subject has left the study prior to experiencing an event. Censoring is common in survival analysis.
Right censored data is data for items that have not yet failed. They are considered “still alive” as their failure time has not yet occurred, though it is expected to occur at some point in the future. For example, consider a fatigue test with 10 components under test.
In general, an observation is said to be right censored if the person was alive at study termination or was lost to follow-up at any time during the study. By right censoring, it is meant that the survival time is only known to exceed a certain value.
is your Event of a factor class? it should be numeric or boolean. so if your Event classes are 0
or 1
, try:
df$Event <- as.numeric(df$Event)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With