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
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)