ggforest(survminer)仅选择协变量

问题描述 投票:0回答:1

我想在Cox生存模型之后创建一个森林图。但是,我只想在图中显示一些协变量?有人知道这是否可能吗?也许使用ggforest2?谢谢

library(survival)
library(survminer)

model <- coxph(Surv(time, status) ~ sex + rx + adhere,
               data = colon )
ggforest(model)

colon <- within(colon, {
  sex <- factor(sex, labels = c("female", "male"))
  differ <- factor(differ, labels = c("well", "moderate", "poor"))
  extent <- factor(extent, labels = c("submuc.", "muscle", "serosa", "contig."))
})
bigmodel <-
  coxph(Surv(time, status) ~ sex + rx + adhere + differ + extent + node4,
        data = colon )
ggforest(bigmodel)
r ggplot2 survival-analysis forestplot
1个回答
0
投票

我的计算机上ggforest的当前版本不允许我选择要在图中显示的变量。但是,另一个包forestmodel::forest_model具有covariates =,应该允许用户选择变量。但是,如下面的图形所示,当前版本的forestmodel可能无法正确执行此操作:

colon <- within(colon, {
  sex <- factor(sex, labels = c("female", "male"))
  differ <- factor(differ, labels = c("well", "moderate", "poor"))
  extent <- factor(extent, labels = c("submuc.", "muscle", "serosa", "contig."))
})
bigmodel <-
  coxph(Surv(time, status) ~ sex + rx + adhere + differ + extent + node4,
        data = colon )
forest_model(bigmodel, covariates = c("sex", "rx"))

enter image description here

这可能是原始贡献者可以解决的问题。在某个阶段,我可以对该函数的先前版本进行一些小的修改就可以生成类似的内容。但是,在我重新安装更新的软件包之后,它不再起作用。

enter image description here

编辑

另一种方法是灵活的。这需要两个步骤。首先,收集模型信息(我在这里使用broom::tidy,但是您可以使用其他方法。第二,使用forestplot::forest_plot生成图形。同样,您也可以使用其他Meta分析软件包)。让我们继续上面的bigmodel

library(forestplot)
library(tidyverse)
# Save model information
df <- broom::tidy(bigmodel,  exponentiate = TRUE)
# pick up the first 4 values 
df1 <- df[1:4, ] %>% 
  transmute( 
    HR = round(estimate, 2), 
    low = conf.low, 
    high = conf.high)

row_names <- cbind(c("Name", "Sex", "Lev", "Lev + 5FU", "adhere"),
                   c("HR", df1$HR))
df1 <- rbind(rep(NA, 4), df1)
forestplot(labeltext = row_names,
           df1[,c("HR", "low", "high")],
           is.summary=c(FALSE, FALSE, FALSE),
           zero      = 1,
           xlog      = TRUE)

这将产生以下图形。可能需要更多的学习才能生成令人满意的图形,但是相对来说您可以控制。enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.