Hi, in coxph, coxph(Surv(time, status)~x,data=alm). How to encode x? For example, if x has two groups, the treatment group and control group. if I encode them as 1 and 2. Is the HR results treatment/control? What if I encode them as 0 and 1. I am confused with how survival package works for HR. What should I do to get a treatment/control HR? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/need-help-with-understanding-coxph-encoding-tp4367514p4367514.html Sent from the R help mailing list archive at Nabble.com.
On Feb 7, 2012, at 9:11 PM, summer wrote:> Hi, in coxph, > coxph(Surv(time, status)~x,data=alm). > How to encode x? For example, if x has two groups, the treatment > group and > control group. if I encode them as 1 and 2. Is the HR results > treatment/control? What if I encode them as 0 and 1. I am confused > with how > survival package works for HR. What should I do to get a treatment/ > control > HR?The proper way would be to construct "x" is as a factor. Then you will not be implicitly telling the function that it is dealing with a numeric value. (In this simple case it probably doesn't really matter. The coefficient for the effect would be the same. -- David Winsemius, MD West Hartford, CT
Coxph is a regression model, so the coefficient for "x" is the change in prediction value for each 1 unit change in x. Just like regression, it won't matter if you code it as 0/1 or 1/2 or 105 vs 106. If you code it as 0 vs 10 the coefficient will be divided by 10 though. The relative hazard in a coxph model is exp(x beta), so the hazard ratio for a 0 vs 1 variable is exp(beta); this is shown in the long for printout given by summary(fit). If you want to use factors, e.g. xfac = factor(x, levels=1:2, labels=c("control", "treatment")) then the labels will carry forward to the printout, but that is their only advantage. Terry T. --- begin included message ----------------- Hi, in coxph, coxph(Surv(time, status)~x,data=alm). How to encode x? For example, if x has two groups, the treatment group and control group. if I encode them as 1 and 2. Is the HR results treatment/control? What if I encode them as 0 and 1. I am confused with how survival package works for HR. What should I do to get a treatment/control HR? Thank you.