[R] categorical varibles in coxph
Thomas Lumley
tlumley at u.washington.edu
Fri Oct 15 22:27:15 CEST 2004
On Fri, 15 Oct 2004, Lisa Wang wrote:
> Hello,
>
> I wonder when I do coxph in R:
>
> coxph( Surv(start, stop, event) ~ x, data=test)
>
> If x is a categorical varible (1,2,3,4,5), should I creat four dummy
> varibles for it? if yes, how can I get the overall p value on x other
> than for each dummy variable?
>
No. Use
coxph( Surv(start, stop, event) ~ factor(x), data=test)
or define x as a factor.
For an overal test use anova(): eg
> data(pbc)
> model<-coxph(Surv(time,status)~factor(edtrt)+bili, data=pbc)
> model
Call:
coxph(formula = Surv(time, status) ~ factor(edtrt) + bili, data = pbc)
coef exp(coef) se(coef) z p
factor(edtrt)0.5 0.629 1.88 0.2297 2.74 6.2e-03
factor(edtrt)1 1.664 5.28 0.2762 6.02 1.7e-09
bili 0.119 1.13 0.0129 9.29 0.0e+00
Likelihood ratio test=127 on 3 df, p=0 n= 418
> anova(model)
Analysis of Deviance Table
Cox model: response is Surv(time, status)
Terms added sequentially (first to last)
Df Deviance Resid. Df Resid. Dev
NULL 418 1746.94
factor(edtrt) 2 62.13 416 1684.82
bili 1 65.11 415 1619.71
> summary(model)
Call:
coxph(formula = Surv(time, status) ~ factor(edtrt) + bili, data = pbc)
n= 418
coef exp(coef) se(coef) z p
factor(edtrt)0.5 0.629 1.88 0.2297 2.74 6.2e-03
factor(edtrt)1 1.664 5.28 0.2762 6.02 1.7e-09
bili 0.119 1.13 0.0129 9.29 0.0e+00
exp(coef) exp(-coef) lower .95 upper .95
factor(edtrt)0.5 1.88 0.533 1.20 2.94
factor(edtrt)1 5.28 0.189 3.07 9.07
bili 1.13 0.887 1.10 1.16
Rsquare= 0.262 (max possible= 0.985 )
Likelihood ratio test= 127 on 3 df, p=0
Wald test = 193 on 3 df, p=0
Score (logrank) test = 281 on 3 df, p=0
More information about the R-help
mailing list