I would like to plot results of multiple cox proportional univariate analysis into one forest plot. Thanksfully this is possible by using the forest_model package in R.
I was wondering if it is possible to use the 'panel' argument of the function forest_model() while also using the 'model_list' argument.
When only using one analysis with forest_model() everything works fine:
panels <- list(
list(width = 0.03),
list(width = 0.1, display = ~variable, fontface = "bold", heading = "Xariable"),
list(width = 0.1, display = ~level),
list(width = 0.05, display = ~n, hjust = 1, heading = "N"),
list(width = 0.03, item = "vline", hjust = 0.5),
list(
width = 0.55,
item = "forest",
hjust = 0.5,
heading = "Hazard ratio",
linetype = "dashed",
line_x = 0
),
list(width = 0.03, item = "vline", hjust = 0.5),
list(
width = 0.12,
display = ~ ifelse(reference, "Reference", sprintf("%0.2f (%0.2f - %0.2f)",trans(estimate), trans(conf.low), trans(conf.high))),
display_na = NA,
heading="95% CI (Range)"
),
list(
width = 0.05,
display = ~ ifelse(reference, "", format.pval(p.value, digits = 1, eps = 0.001)),
display_na = NA, hjust = 1, heading = "p"
),
list(width = 0.03)
)
forest_model(coxph(Surv(Duration, AliveDead) ~ Gender, pretty_Datensatz_3), panels, exponentiate=TRUE)
Plot with customization with the panel arguemnt
When using the model_list argument the customization done with the panels argument seems to be ignored.
coxVar1 <- coxph(Surv(Duration, AliveDead) ~ Gender, pretty_Datensatz_3)
# coxVar2 till coxVar8 in the same way
model_list <- list(Age = coxVar2, Gender = coxVar1, RRT = coxVar4, Catecholamine = coxVar5, InvVent = coxVar6, SAPS = coxVar3, TISS = coxVar7, DoV=coxVar8)
forest_model(model_list = model_list,merge_models =TRUE, panels)
I have already tried to use fewer list elements within model_list
but this did not change anything.
I have searched through Google and ChatGPT but this problem wasn't addressed there. I also read through the documentation but either I missed something or there was no info about this.
Anyone any suggestions?
I tested it out and I have something for you to try.
Let's try a reproducible example.
library(survival)
library(dplyr)
library(tidyverse)
pretty_lung <- lung %>%
transmute(time,
status,
Age = age,
Sex = factor(sex, labels = c("Male", "Female")),
ECOG = factor(lung$ph.ecog),
`Meal Cal` = meal.cal
)
coxVar1 <- coxph(Surv(time, status) ~ ECOG, pretty_lung)
coxVar2 <- coxph(Surv(time, status) ~ Sex, pretty_lung)
model_list <- list(ECOG = coxVar1, Sex = coxVar2)
And then I read in your panels
list. Note that I saw that there was a typo in "Xariables", which may have been intentional.
This did not work for me, and gave the same result as you specified.
forest_model(model_list = model_list,merge_models =TRUE, panels) #does not work
If I used panels = panels
, this had the expected result.
forest_model(model_list = model_list,merge_models =TRUE, panels=panels) #specify panels=
The reason seems that there is a if(missing(panels))
statement that displays the default_forest_panels
assignment unless you explicitly assign your panels
.