log-rank test in R

I need to use the survdiff function to statistically compare (using log-rank test) the following survival functions:
(1) Male (Sex=1) and Female (Sex=2)
(2) Patients <= 65 years-old and Patients > 65 years-old

I used the following command

Male <- survdiff(Surv(time,Status)~sex==1,data=myeloma)
Female <- survdiff(Surv(time,Status)~sex==2,data=myeloma)


is that correct ?

• When you mention a function it's best to state which package it's from. Do you mean the survdiff function from survival? Commented Sep 4, 2014 at 10:33
• library(survival)
– SAMA
Commented Sep 4, 2014 at 22:37
• yes I meant the survdiff function from survival package
– SAMA
Commented Sep 4, 2014 at 22:39

The examples provided in ?survdiff are pretty clear. Using some example data included in survival, this

survdiff(Surv(futime, fustat) ~ rx,data=ovarian)


Is testing for a difference in survival between individuals with rx = 1 and rx = 2. For your data, this will compare survival for males versus females

survdiff(Surv(time, Status) ~ sex, data=myeloma)


And this will compare survival for <= 65 versus >65.

survdiff(Surv(time, Status) ~ age, data=myeloma)


It doesn't look right. If you want to limit the analysis to just males or females, the sex==1 or sex==2 is a separate input, the subset clause. The new commands would be

Males<-survdiff(surv(time,Status)~Patients, data = myeloma, sex==1)

Females<-survdiff(surv(time,Status)~Patients, data = myeloma, sex==2)


You need to specify something as the dependent variable in the equation, and the only remaing variable is Patients.

If you actually want to measure the effects of both sex and age together on survival, you need to be doing a stratified log rank test. I've used the function SurvTest(in documentation)/surv_test from the coin package.

As far as I could tell, it only takes one stratifying variable, but I came up with a workaround by appending several variables into a new variable and using that as the stratifying variable.

There are a couple of other packages that can do the same thing, but I can't think of them right now.

• As the logrank test is a special case of the Cox proportional hazards model, it is unclear why you are using it. And thinking of age > 65 as a point of discontinuity in a (highly likely to be smooth) age effect does not make sense. There is huge heterogeneity of age within the age > 65 group, and likewise for age <= 65. Commented Sep 4, 2014 at 11:43
• To clarify that , my aim is to compare between both two gender in one comparison , and between age<=65 and age>65 separately. I need tow studies one between two gender and the other between two different groups of age
– SAMA
Commented Sep 4, 2014 at 22:44
• my data has these variable {time ,Status,age,sex}
– SAMA
Commented Sep 4, 2014 at 22:49
• SAMA, can you clarify your aim in your original post? The explanation you provided here is perfectly clear, and that is what you are missing in the original post. Commented May 16, 2016 at 16:47