R: exporting summary of coxph object

1

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

• 5.7k views

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


Login
before adding your answer.

Traffic: 1046 users visited in the last hour



Source link