xtable中的Cox回归输出-选择行/列并添加置信区间 [英] Cox regression output in xtable - choosing rows/columns and adding a confidence interval

查看:138
本文介绍了xtable中的Cox回归输出-选择行/列并添加置信区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望将cox回归的输出导出到表格中,然后可以将其放入文章中。我想最好的方法是使用xtable:

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(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 to the output:


  • 添加置信区间(CI)为95 %

  • 选择某些行,例如age和log(protime)

  • 将exp(B)& CI到小数点后三位

  • 用z&删除列常规系数

  • Add confidence interval (CI) of 95 %
  • Select certain rows, say age and log(protime)
  • Round the exp(B) & CI to three decimals
  • Remove the column with z & regular coef

谢谢!

推荐答案

我将通过首先查看 survival 包如何构造其默认打印的表的方式来实现此目的。

I'd approach this by first taking a look at how the survival package constructs the table it prints by default.

要找到执行该打印的功能,请检查fit对象的类,然后寻找该类的打印方法:

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"

看看 print.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)

这篇关于xtable中的Cox回归输出-选择行/列并添加置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆