R: exporting summary of coxph object
1
0
Entering edit mode
8.3 years ago
orzech_mag ▴ 230

Dear colleges,

I performed Cox regression for proportional hazard using R package "survival". I obtained the results in form of "coxph" object, which seems to be a list. My problem is that I (and it seems like Internet too) do not know how to export it as .txt file for example. Please, give some feedback, I'll appreciate it.

Best regards!

R Cox regression data export • 9.4k views
ADD COMMENT
0
Entering edit mode

a simple summary is:

c <- coxph(Surv(x~y)) 
summary(c)

then if you want to extract p.value and hazard ratio:

pvc <- coef(summary(c))[,5]
hr <- round(coef(summary(c))[,2],3)
ADD REPLY
0
Entering edit mode

Thank you for your answer, however I am familiar with those commands. I do not know how to export it to text or csv file.

ADD REPLY
0
Entering edit mode
3.6 years ago
dwinsemius • 0

Just use capture.output. This shows the code and offers only the first 8 lines of 20 lines of text:

fit <- coxph(Surv(time, status) ~ age + sex, lung) txt.out <- capture.output(summary(fit)) txt.out [1] "Call:"
[2] "coxph(formula = Surv(time, status) ~ age + sex, data = lung)"
[3] ""
[4] " n= 228, number of events= 165 "
[5] ""
[6] " coef exp(coef) se(coef) z Pr(>|z|) "
[7] "age 0.017045 1.017191 0.009223 1.848 0.06459 . "
[8] "sex -0.513219 0.598566 0.167458 -3.065 0.00218 **"

-- David

ADD COMMENT

Login before adding your answer.

Traffic: 2669 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6