Problems when applying function comp()

survmisc

#1

Hi,

I have designed the following data set with survival times for two different groups:

Timesexample<- c(6,6,6,7,10,13,16,22,23,6,9,10,11,17,19,20,25,32,32,34,35, 1,1,2,2,3,4,4,5,5,8,8,8,8,11,11,12,12,15,17,22,23)
Eventsex<-c(1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
Group<-c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
object<-Surv(Timesexample, Eventsex)
Group <- factor(Group, labels = c("A", "B"))

Tablex<-data.frame(object, Group)

I am trying to compare both survival curves in order to get the p-values for Long-rank, wilcoxon, tarone, peto and flemington-harrington tests. I have seen that function comp() from package survMisc can perform such tests, however when I applied comp() to my data, I get the following error message:

library(survMisc)
fit = survfit(Surv(Timesexample, Eventsex) ~ Group, data = Tablex)
comp(fit)$tests$lrTests

no applicable method for 'comp' applied to an object of class "survfit"

Can anyone help me to solve this problem? I have already tried comp(ten()) as some post suggest, but it doesn't seem to work either.

Thank you


#2

Looking at the documentation, the comp() function is looking for a 'ten' (time, event, number at risk) object.

Try something like:

foo <- ten(fit)
comp(foo)$tests$lrTests

#3

Hi Pete,

Thanks for your reply, I already tried using 'ten' but the output I get looks as follows:

comp(ten(fit))$tests$lrTests
                   Q        Var      Z      pNorm    
1            10.25050    6.34099 4.0707 4.6877e-05 ***
n           271.00000 5462.61156 3.6666 0.00024575 ***
sqrtN        51.16275  173.75714 3.8813 0.00010388 ***
S1            6.36221    2.87942 3.7493 0.00017730 ***
S2            6.12261    2.69899 3.7268 0.00019393 ***
FH_p=1_q=1    1.66465    0.22122 3.5393 0.00040122 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
              maxAbsZ        Var      Q     pSupBr    
1            10.25050    6.34099 4.0707 9.3753e-05 ***
n           271.00000 5462.61156 3.6666 0.00049150 ***
sqrtN        51.16275  173.75714 3.8813 0.00020776 ***
S1            6.36221    2.87942 3.7493 0.00035460 ***
S2            6.12261    2.69899 3.7268 0.00038785 ***
FH_p=1_q=1    1.66465    0.22122 3.5393 0.00080244 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
NULL

Which looks rather different to the expected output for comp(). I took this example from the website:
[https://stats.stackexchange.com/questions/23323/how-to-perform-a-wilcoxon-signed-rank-test-for-survival-data-in-r]

They get the output I am looking for when applying comp()

> comp(fit)$tests$lrTests
                              ChiSq df      p
Log-rank                       3.40  1 0.0653
Gehan-Breslow (mod~ Wilcoxon)  2.72  1 0.0989
Tarone-Ware                    2.98  1 0.0842
Peto-Peto                      2.71  1 0.0998
Mod~ Peto-Peto (Andersen)      2.64  1 0.1042
Flem~-Harr~ with p=1, q=1      1.45  1 0.2281

Thanks again!


#4

There's a comment on that CV answer pointing out that different syntax is needed since the major rewrite of survMisc that occurred in version 0.5.0. It probably should have clarified that the output has also changed. Post-rewrite, the comp() function returns NULL (so comp(ten(fit))$tests$lrTests isn't any different from comp(ten(fit))). Instead, it prints to the console and adds attributes to the ten object, so life will be easier if you are explicitly storing your ten object as seen in the comp() examples.

I think your options here are:

  1. Carefully read the new documentation for comp() (run ?comp at the console after loading survMisc) to determine how the new output might map onto what you're looking for, and study the examples to learn the new usage pattern.

  2. Install an older version of survMisc from the CRAN archive to get the old behavior (but, definitely consult the NEWS and GitHub issue tracker first before choosing this path — it sounds like there were bugs in the older code relating to comp()).