We will use the cadtte data set from the random.cdisc.data package to create the survival forest graph. We start by filtering the adtte data set for the overall survival observations, converting time of overall survival to months, creating a new variable for event information, binarizing the ARM variable and creating a binned age variable by using the function cut_quantile_bins(). Note that we do not include the boundaries 0 and 1 in the corresponding cutoffs vector AGE_probs, but only the true cutoff probabilities to use (here 0.5, i.e. the median). We restrict the analysis of the biomarker variables BMRKR1 and BMRKR2 to the BEP by setting them as missing for the non-BEP.
We also relabel the biomarker evaluable population flag variable BEP01FL and the categorical biomarker variable BMRKR2 to update the display label of these variables in the graph.
We use the extract_survival_subgroups() function to calculate the survival forest results for the subgroups defined by the levels of the factor variables given in subgroups. We then tabulate the estimated statistics with the function tabulate_survival_subgroups() to be able to use them as an input for forest plot. Note that for the argument vars we could select different statistics, but the statistics n_tot, hr and ci are required.
We can remove the last line showing the <Missing> category from the result table to display the survival forest plot only with non-missing categories for BMRKR2.
Code
result <- result[-9, , keep_topleft =TRUE]
We can now produce the forest plot using the g_forest() function from tern based on this trimmed result table.
---title: SFG1subtitle: Survival Forest Graphs for Overall Population and by Categorical Biomarkercategories: [SFG]---------------------------------------------------------------------------::: panel-tabset{{< include setup.qmd >}}## PlotWe use the `extract_survival_subgroups()` function to calculate the survival forest results for the subgroups defined by the levels of the factor variables given in `subgroups`.We then tabulate the estimated statistics with the function `tabulate_survival_subgroups()` to be able to use them as an input for forest plot.Note that for the argument `vars` we could select different statistics, but the statistics `n_tot`, `hr` and `ci` are required.```{r}tbl <-extract_survival_subgroups(variables =list(tte ="AVAL",is_event ="is_event",arm ="ARM_BIN",subgroups =c("BEP01FL", "BMRKR2") ),label_all ="ITT",data = adtte)result <-basic_table() %>%tabulate_survival_subgroups(df = tbl,vars =c("n_tot_events", "n", "n_events", "median", "hr", "ci"),time_unit = adtte$AVALU[1] )```We can remove the last line showing the `<Missing>` category from the `result` table to display the survival forest plot only with non-missing categories for `BMRKR2`.```{r}result <- result[-9, , keep_topleft =TRUE]```We can now produce the forest plot using the `g_forest()` function from `tern` based on this trimmed `result` table.```{r, fig.width = 15}g_forest(result)```{{< include ../../misc/session_info.qmd >}}:::