We will here use the dessin_forest_models
function in
the Data &
Functions page.
Download Forest_autom.R
library(survival)
# Data used
data(pbc)
# Different models to plot
mod1 <- coxph(Surv(time,status>0) ~ trt, data=pbc)
mod2 <- coxph(Surv(time,status>0) ~ trt+age, data=pbc)
mod3 <- coxph(Surv(time,status>0) ~ trt+age+sex, data=pbc)
dessin_forest_models
functionArguments
dessin_forest_models(
vect_models,
vector
of model names to be displayed (example: c(‘mod1’, ‘mod2’))
- if it is a multivariate model, only the estimate of the first
variable will be displayed
- accepted models: coxph,
svycoxph, glm, svyglm
vecnoms = NULL,
vector of the
names you want to give to the different models.
name_col_var = "Variable",
desired column name with
variables.
name_col_mean = "HR (95%CI)",
desired
column name with estimates.
zero = 1,
where we want to
put the zero of the forest plot.
pos_graphique = 3,
can be equal to 1, 2, 3 or 4, localisation of the graph
IC = TRUE,
TRUE: displays the CI in the column with the
estimate.
digit = 2,
to round off the estimate and its
confidence interval.
lwd.ci = 1,
confidence interval
thickness.
clip,
allows to choose the upper and lower
limits of the x-axis.
- by default: from minimum HR/OR to
maximum HR/OR
- we specify the limits: vector of size 2
with the lower bound and the upper bound
- “clip_tot”: we
display the whole graph
by = 0.5,
allows to choose the
distance between the different ticks of the x-axis.
print_pval = FALSE
TRUE : print the pvalue in the last
column
)
dessin_forest_models(c("mod1", "mod2", "mod3"),
vecnoms=c("Naive", "Ajusted on age", "Ajusted on age and sex"), clip = "clip_tot", print_pval=TRUE)
This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Developed and updated by Noémie Bigot and Anouk Walter-Petrich
noemie.bigot@aphp.fr; anouk.walter-petrich@u-paris.fr
Based on The R Graph Gallery by Yan Holtz.