I have a cox.obj named obj, obj <- coxph( Surv(time, status) ~ group, surv.data) now I want to retrieve the p-value from obj, so that I can run this hundreds of times and plot out the distribution of the p-value. could anyone tell me how to get p-value from obj? thanks, -- View this message in context: http://www.nabble.com/retrieve-p-value-from-a-cox.obj-tf4348520.html#a12389652 Sent from the R help mailing list archive at Nabble.com.
str() is your friend. It tells you about the structure of any R object, from which you can usually glean what you need to know to get what you want. It is often useful to use it on summary(object) rather than on the object, as the summary method for an (S3) classed object often contains what you're looking for. Less generally, names() and as.list() can sometimes get you what you want also. Alternatively, check the summary.coxph() code (survival:::summary.coxph, as it's hidden in the namespace). It is clear there how to get what you want, either direct from the fitted object or from the summary.coxph object. Bert Gunter Genentech Nonclinical Statistics -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of clearsky Sent: Wednesday, August 29, 2007 8:41 AM To: r-help at stat.math.ethz.ch Subject: [R] retrieve p-value from a cox.obj I have a cox.obj named obj, obj <- coxph( Surv(time, status) ~ group, surv.data) now I want to retrieve the p-value from obj, so that I can run this hundreds of times and plot out the distribution of the p-value. could anyone tell me how to get p-value from obj? thanks, -- View this message in context: http://www.nabble.com/retrieve-p-value-from-a-cox.obj-tf4348520.html#a123896 52 Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
I tried obj$p, obj$pvalue, but they both returned null~~ clearsky wrote:> > I have a cox.obj named obj, > obj <- coxph( Surv(time, status) ~ group, surv.data) > now I want to retrieve the p-value from obj, so that I can run this > hundreds of times and plot out the distribution of the p-value. could > anyone tell me how to get p-value from obj? > > thanks, > >-- View this message in context: http://www.nabble.com/retrieve-p-value-from-a-cox.obj-tf4348520.html#a12390960 Sent from the R help mailing list archive at Nabble.com.
Several responders have given input on how to find and read the code for summary.coxph and print.coxph, or using str() to examine the output of a coxph object. An even better starting place would be the documentation (yes there is some). help(coxph) gives a page that contains: "Value: an object of class coxph. See 'coxph.object' for details." and help(coxph.object) gives a description of all the components. Terry Therneau
On Wed, 2007-08-29 at 08:40 -0700, clearsky wrote:> I have a cox.obj named obj, > obj <- coxph( Surv(time, status) ~ group, surv.data) > now I want to retrieve the p-value from obj, so that I can run this hundreds > of times and plot out the distribution of the p-value. could anyone tell me > how to get p-value from obj? > > thanks,Hi Clearsky try: summary(obj)$waldtest[3] -- Bernardo Rangel Tura, M.D,Ph.D National Institute of Cardiology Brazil