我想根据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)
答案 0 :(得分:1)
我的机器上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"))
这可能是原始贡献者可以解决的问题。在某个阶段,我可以对该函数的先前版本进行一些小的修改就可以生成类似的内容。但是,在我重新安装更新的软件包之后,它不再起作用。
编辑
另一种方法是灵活的。这需要两个步骤。首先,收集模型信息(我在这里使用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)