簡體   English   中英

ggforest(survminer)僅選擇協變量

[英]ggforest (survminer) only selected covariates

我想在 Cox 生存模型之后創建一個森林 plot。 但是,我只想在圖中顯示一些協變量? 有人知道這是否可能嗎? 也許使用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)

我機器上當前版本的ggforest不允許我將 select 變量顯示在 plot 中。 但是,另一個 package forestmodel::forest_model具有covariates =應該允許用戶使用 select 變量。 但是,當前版本的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"))

在此處輸入圖像描述

這可能是原始貢獻者可以解決的問題。 在某個階段,我能夠通過對以前版本的 function 進行一些小的修改來生成類似的東西。 但是,在我重新安裝更新后的 package 后,它不再起作用。

在此處輸入圖像描述

編輯

另一種方法是靈活的。 它需要兩個步驟。 首先,收集 model 信息(我在這里使用broom::tidy ,但您可以使用其他方法。其次,使用forestplot::forest_plot生成圖形。同樣,您也可以使用其他 Meta 分析 package 來實現此目的。
讓我們繼續上面的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)

這將產生以下圖表。 生成令人滿意的圖表可能需要更多的學習,但相對而言,您可以控制。
在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM