[R] coxph question

Mayeul KAUFFMANN mayeul.kauffmann at tiscali.fr
Fri Aug 13 17:06:24 CEST 2004

I understood the following: you want to try every single covariate in a
cox model with only one covariate, then take the best ones according to

Assume your columns  look like:
stop status event x1 x2 x3 etc
You want to add column 3 (x1), then 4, etc.

I suggest a for() loop:

z<-NULL;for(i in 3:ncol(data))
{coxtmp <- coxph(Surv(stop,status)~ data[,i]) #you can modify the formula
                                                       #adding covariates
in any case, for instance
z<- rbind(z,c(i,beta,se,pvalue=signif(1 - pchisq((beta/ se)^2, 1), 4)))
print (i)}

#then select the covariates according to the p values:

Hope it helps.

Univ. Pierre Mendes France
Grenoble - France

----- Original Message ----- 
Thanks Mayeul,

I actually would like to test each variable individually and use those
have low p-value to build a classifier (not in cox model). Therefore, I
need to write a function to subset those low p-value variables, instead of
putting them as covariates. Any ideas?


-----Original Message-----

> I have many variables to test using cox model (coxph), and I am only
interested in those variables with p value less than 0.01. Is there a
quick way to do this automatically instead of looking at the output of
each variable?
> Chris

More information about the R-help mailing list