我想并排显示两个回归分析的结果,比如说逻辑回归和 COX 回归。变量以行形式呈现,p、OR/HR 和置信区间的相应数据以列形式呈现。因此,列名称不匹配:OR 位于左侧,HR 位于右侧。
我尝试了 cbind,但遇到了以下问题:
(1) 如果由于变量选择而导致一个变量(行)仅出现在一张表中怎么办?在这种情况下,在将两者组合时,另一个表中必须有一个空白行。
(2) 两个表合并后,如何添加跨越每个表的四列的标题,以便将它们标记为逻辑或 COX?
我正在寻找的输出将通过 xtable 显示为乳胶表:
| Logistic regression | COX regression
| p | OR | 2.5% | 97.5% | p | HR | 2.5% | 97.5%
v1 | 0.849 | 0.936 | ... | ... | | | |
v2 | 0.249 | 0.595 | ... | ... | 0.026 | 1.916 | ... | ...
v3 | | | | | 0.023 | 0.140 | ... | ...
这是一些示例代码:
library(xtable);library(survival)
# Creating a sample data frame
set.seed(1234)
event <- as.numeric(round(rnorm(10,5,5))>1);tte<-abs(round(rnorm(10,5,5)))
v1 <- round(rnorm(10,5,5));v2 <- round(rnorm(10,2,5));v3 <- round(rnorm(10,1,5))
df<-data.frame(event, tte, v1, v2, v3)
# Some logistic regression ...
LogReg <- glm(event~v1+v2,family=binomial,data=df)
LogRegTable<-round(cbind(summary(LogReg)$coef[, "Pr(>|z|)"], exp(coef(LogReg)), exp(confint(LogReg))),3)
colnames(LogRegTable)<-c("p","OR","2.5%","97.5%")
LogRegTable<-LogRegTable[!rownames(LogRegTable)=="(Intercept)",]
# ... and some COX regression
CoxReg <- coxph(Surv(df$tte, df$event)~v2+v3,data=df)
CoxRegTable<-round(cbind(summary(CoxReg)$coef[, "Pr(>|z|)"], exp(coef(CoxReg)), exp(confint(CoxReg))),3)
colnames(CoxRegTable)<-c("p","HR","2.5%","97.5%")
# There we go
LogRegTable
CoxRegTable
# Now, how to get them in one table?
xtable(
cbind(LogRegTable, CoxRegTable)
)
# ... messes up the correct row names