# [R] Trend test for survival data

Terry Therneau therneau at mayo.edu
Tue Apr 22 14:52:16 CEST 2008

```> Hello,
> is there a R package that provides a log rank trend test
> for survival data in >=3 treatment groups?
> Or are there any comparable trend tests for survival data in R?

The log-rank test is equivalent to a Cox model with a factor variable as the
predictor.  To do a trend test, simply fit the Cox model with the variable
scored as 1,2,3,...  Or fit it as a factor and do a post-hoc trend test:

>  fit1 <- coxph(Surv(time, status) ~ ph.ecog, data=lung)
> fit1
Call:
coxph(formula = Surv(time, status) ~ ph.ecog, data = lung)

coef exp(coef) se(coef)   z       p
ph.ecog 0.476      1.61    0.113 4.2 2.7e-05

Likelihood ratio test=17.6  on 1 df, p=2.77e-05  n=227 (1 observation deleted
due to missingness)

>  fit2 <- coxph(Surv(time, status) ~ factor(ph.ecog), data=lung)
> fit2

coef exp(coef) se(coef)    z       p
factor(ph.ecog)1 0.369      1.45    0.199 1.86 6.3e-02
factor(ph.ecog)2 0.916      2.50    0.225 4.08 4.5e-05
factor(ph.ecog)3 2.208      9.10    1.026 2.15 3.1e-02

Likelihood ratio test=18.4  on 3 df, p=0.000356  n=227 (1 observation deleted
due to missingness)

> zz <- c(1,2,3)
> test.num <- zz %*% coef(fit2)
> test.var <- zz %*% fit2\$var %*% zz
> test.num/sqrt(test.var)
[,1]
[1,] 2.74323

Note that ecog performace score=0 is implicitly part of the contrast.  The
full coefficient vector is (0, .369, .916, 2.208) and my linear contrast zz is
0,1,2,3.

Terry Therneau

```