I wan\'t to export the output from a cox regression to a table that I then can put into my article. I guess the best way to go about it is with xtable:
library(s
I'd approach this by first taking a look at how the survival
package constructs the table it prints by default.
To find the function that does that printing, examine the class of your fit object, and then look for a print method for that class:
class(fit.pbc)
# [1] "coxph"
grep("coxph", methods("print"), value=TRUE)
# [1] "print.coxph" "print.coxph.null"
# [3] "print.coxph.penal" "print.summary.coxph"
After taking a look at print.coxph
, here's what I came up with:
cox <- fit.pbc
# Prepare the columns
beta <- coef(cox)
se <- sqrt(diag(cox$var))
p <- 1 - pchisq((beta/se)^2, 1)
CI <- round(confint(cox), 3)
# Bind columns together, and select desired rows
res <- cbind(beta, se = exp(beta), CI, p)
res <- res[c("age", "log(protime)"),]
# Print results in a LaTeX-ready form
xtable(res)