# [R] log rank test p value

Marc Schwartz marc_schwartz at comcast.net
Wed May 16 04:17:08 CEST 2007

```On Wed, 2007-05-16 at 11:54 +1000, Murray Pung wrote:
> How can I get the Log - Rank p value to be output?
>
> The chi square value can be output, so I was thinking if I can also have the
> degrees of freedom output I could generate the p value, but can't see how to
> find df either.
>
> > (survtest <- survdiff(Surv(time, cens) ~ group, data = surv,rho=0))
> Call:
> survdiff(formula = Surv(time, cens) ~ group, data = surv, rho = 0)
>
>          N Observed Expected (O-E)^2/E (O-E)^2/V
> group=1 20       16     11.0      2.23      4.64
> group=2 20       12     17.0      1.45      4.64
>
>  Chisq= 4.6  on 1 degrees of freedom, p= 0.0312
>
> > survtest\$chisq
> [1] 4.641028
>
> > survtest\$df
> NULL

That part of the output is created in print.survdiff(), which you can
review by using:

survival:::print.survdiff

The degrees of freedom and the p value are calculated in that function.

Using the example in ?survdiff:

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

> survtest
Call:
survdiff(formula = Surv(futime, fustat) ~ rx, data = ovarian)

N Observed Expected (O-E)^2/E (O-E)^2/V
rx=1 13        7     5.23     0.596      1.06
rx=2 13        5     6.77     0.461      1.06

Chisq= 1.1  on 1 degrees of freedom, p= 0.303

> str(survtest)
List of 6
\$ n    : 'table' int [, 1:2] 13 13
..- attr(*, "dimnames")=List of 1
.. ..\$ groups: chr [1:2] "rx=1" "rx=2"
\$ obs  : num [1:2] 7 5
\$ exp  : num [1:2] 5.23 6.77
\$ var  : num [1:2, 1:2]  2.94 -2.94 -2.94  2.94
\$ chisq: num 1.06
\$ call : language survdiff(formula = Surv(futime, fustat) ~ rx, data = ovarian)
- attr(*, "class")= chr "survdiff"

We can then do the following to secure the p value:

> 1 - pchisq(survtest\$chisq, 1)
[1] 0.3025911