Hello,

I have two questions regarding a survival analysis I have been working on. Below is the code to date.
The variables:

1) recidivism$intDaysUntilFVPO are the number of days before an violent offence was committed - if no offence was committed than the days between court hearing and end of data collection was recorded. 2) recidivism$intDaysUntilFNVPO are the number of days before a nonviolent offence was committed - if no offence was committed than the days between court hearing and end of data collection was recorded. 3) recidivism$Event_v coded TRUE or FALSE as to whether a violent offence was committed 4) recidivism$Event_nv coded TRUE or FALSE as to whether a non-violent offence was committed
5) recidivism$group - there were 3 groups recorded as 1, 2 or 3

I encountered two problems:

a) when I tried to run the following: > surv_test(Surv(recidivism$intDaysUntilFVPO, recidivism$Event_v) ~ recidivism$group, data = recidivism, distribution = "exact")

I received the following error message. I am unsure whether the problem lies with the group variable, how I have set up the time variables or there is something missing.

Error in check(itp) :
  'object' does not represent a K sample problem with censored data

(b) I ran some simple plots of the curves. While I have a fair idea of which group is which, I wanted to add a legend identifying the groups ? What code is required for this?

Any assistance is much appreciated,

Bob


> library(survival)
>
> survdiff(Surv(recidivism$intDaysUntilFVPO, recidivism$Event_v) ~ group, data = recidivism)
Call:
survdiff(formula = Surv(recidivism$intDaysUntilFVPO, recidivism$Event_v) ~
    group, data = recidivism)

           N Observed Expected (O-E)^2/E (O-E)^2/V
group=1 1136      135   154.18      2.39      7.75
group=2  446       87    61.29     10.78     14.90
group=3   65        1     7.52      5.66      5.86

 Chisq= 18.9  on 2 degrees of freedom, p= 8.06e-05
> survdiff(Surv(recidivism$intDaysUntilFNVPO, recidivism$Event_nv) ~ group, data = recidivism)
Call:
survdiff(formula = Surv(recidivism$intDaysUntilFNVPO, recidivism$Event_nv) ~
    group, data = recidivism)

           N Observed Expected (O-E)^2/E (O-E)^2/V
group=1 1136      323    366.3      5.11     17.80
group=2  446      184    127.7     24.84     33.12
group=3   65        7     20.1      8.51      8.86

 Chisq= 38.5  on 2 degrees of freedom, p= 4.3e-09
> layout(matrix(1:2, ncol = 2))
> plot(survfit(Surv(recidivism$intDaysUntilFNVPO, recidivism$Event_v) ~ recidivism$group, data = recidivism), main = "time to violent reoffense by group", lty = c(1,2,3), ylab = "probability", xlab = "survival time in days") > plot(survfit(Surv(recidivism$intDaysUntilFVPO, recidivism$Event_nv) ~ recidivism$group, data = recidivism), main = "time to nonviolent reoffense by group", lty = c(1,2,3), ylab = "probability", xlab = "survival time in days")
>
> library(coin)
> surv_test(Surv(recidivism$intDaysUntilFVPO, recidivism$Event_v) ~ recidivism$group, data = recidivism, distribution = "exact")
Error in check(itp) :
  'object' does not represent a K sample problem with censored data

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to