Exit Cox regression to xxtable - select rows / columns and add confidence interval

I do not want to export the result from cox regression to a table, which I can then insert into my article. I think the best way to do this is with xxtable:

library(survival) data(pbc) fit.pbc <- coxph(Surv(time, status==2) ~ age + edema + log(bili) + log(protime) + log(albumin), data=pbc) summary(fit.pbc) library(xtable) xtable(fit.pbc) 

Now I want to do the following for output:

  • Add Confidence Interval (CI) 95%
  • Select specific lines, e.g. age and log (protime)
  • Radius exp (B) and CI up to three decimal places
  • Remove column with z and regular coef

Thanks in advance!

+6
source share
2 answers

I would approach this by first looking at how the survival package creates a table that it prints by default.

To find the function that performs this printing, examine the fit object class and then find the print method for this 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" 

Looking at print.coxph , here is 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) 
+9
source
 xtable(round(summary(fit.pbc)$conf.int[c(1,3),],3)) #-----------------------------# % latex table generated in R 2.13.1 by xtable 1.5-6 package % Sat Oct 15 18:36:04 2011 \begin{table}[ht] \begin{center} \begin{tabular}{rrrrr} \hline & exp(coef) & exp(-coef) & lower .95 & upper .95 \\ \hline age & 1.04 & 0.96 & 1.02 & 1.06 \\ log(bili) & 2.37 & 0.42 & 2.02 & 2.79 \\ \hline \end{tabular} \end{center} \end{table} 

This shows what you see with str in the summary object

 str(summary(fit.pbc)) # snipped $ conf.int : num [1:5, 1:4] 1.0404 2.4505 2.3716 10.8791 0.0815 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:5] "age" "edema" "log(bili)" "log(protime)" ... .. ..$ : chr [1:4] "exp(coef)" "exp(-coef)" "lower .95" "upper .95" 
+3
source

Source: https://habr.com/ru/post/899380/


All Articles