How to obtain Risk score in R? Is the following approach correct?
library (survival)
coxph(Surv(time, status) ~ factor(ph.ecog)+factor(sex)+ factor(age>median(lung$age)), data=lung)
#Call:
#coxph(formula = Surv(time, status) ~ factor(ph.ecog) + factor(sex) +
# factor(age > median(lung$age)), data = lung)
# coef exp(coef) se(coef) z p
#factor(ph.ecog)1 0.40140 1.49391 0.20170 1.990 0.04658
#factor(ph.ecog)2 0.91911 2.50705 0.23044 3.988 6.65e-05
#factor(ph.ecog)3 1.98491 7.27840 1.03298 1.922 0.05466
#factor(sex)2 -0.54989 0.57701 0.16838 -3.266 0.00109
#factor(age > median(lung$age))TRUE 0.08952 1.09365 0.16138 0.555 0.57910
risk = with(lung[,c('ph.ecog','sex','age')],
0.57910* (age > median(lung$age))
- 0.54989* (sex==2)+ifelse (ph.ecog==1, 0.40140, ifelse(ph.ecog==2, 0.91911, 1.98491) )
)
lung$group= risk> median(risk, na.rm=T)
plot (survfit(Surv(lung$time, lung$status)~lung$group), col= c(1,2))
```