As discussed in Section 11.4, we can perform a log-rank test to compare
the survival of males to females, using the survdiff()
function.
> logrank.test <- survdiff(Surv(time, status) ~ sex)
> logrank.test
Call:
survdiff(formula = Surv(time, status) ~ sex)
N Observed Expected (O-E)^2/E (O-E)^2/V
sex=Female 45 15 18.5 0.676 1.44
sex=Male 43 20 16.5 0.761 1.44
Chisq= 1.4 on 1 degrees of freedom, p= 0.23
The resulting p-value is 0.23, indicating no evidence of a difference in survival between the two sexes.
survdiff()
function in logrank.pub
)
Assume that:
ISLR2
and survival
libraries has been loadedPublication
dataset has been loaded and attached