Reputation: 1
I'm absolutely new to Stack Overflow, so I hope I am doing everything right. If not, please be kind :)
I'm having trouble with the tbl_survfit()
function from the gtsummary
package (fantastic package by the way). tbl_survfit()
works absolutely fine when I use only one factor in the survfit
-object, i.e.
(I'll take the dataset trial
from the gtsummary
package as an example)
library(gtsummary)
library(survival)
tbl_survfit(
survfit(Surv(ttdeath, death) ~ trt, trial),
times = c(12, 24))
or
tbl_survfit(
survfit(Surv(ttdeath, death) ~ stage, trial),
times = c(12, 24))
works fine. However, when I use a combination of factors, e.g.,
tbl_survfit(
survfit(Surv(ttdeath, death) ~ trt + stage, trial),
times = c(12, 24))
I get an error that I do not understand. The problem seems to be with tbl_survfit()
since the survfit
object itself
survfit(Surv(ttdeath, death) ~ trt + stage, trial)
is created without any problems. I am pretty sure that I have used tbl_survfit()
with a combination of factors before without any problems and I am lost why it is not working anymore. I have updated R
, survival
and gtsummary
to the newest versions and tried everything from here:
Common Sources of Error with tbl_survfit()
Any help is much appreciated, thank you in advance!
Edit: For further clarification, I want to use tbl_survfit()
to get a table with the 'survival probabilities' for all factor level combinations, i.e. (in the example above) all (eight) combinations of factor levels from trt
and stage
(trt = Drug A
and stage = T1
, trt = Drug A
and stage = T2
, etc.). Put another way, I want the 'survival probabilities' for the survfit
object
survfit(Surv(ttdeath, death) ~ trt + stage, trial)
which contains these combinations.
Call: survfit(formula = Surv(ttdeath, death) ~ trt + stage, data = trial)
n events median 0.95LCL 0.95UCL
trt=Drug A, stage=T1 28 12 NA 20.8 NA
trt=Drug A, stage=T2 25 11 NA 21.3 NA
trt=Drug A, stage=T3 22 13 21.2 17.6 NA
trt=Drug A, stage=T4 23 16 19.8 16.5 NA
trt=Drug B, stage=T1 25 12 NA 21.5 NA
trt=Drug B, stage=T2 29 16 20.4 16.7 NA
trt=Drug B, stage=T3 21 9 NA 18.0 NA
trt=Drug B, stage=T4 27 23 15.6 14.3 20.9
Upvotes: 0
Views: 121
Reputation: 11764
The tbl_survfit()
function supports a single stratifying variable only. There used to be a nice message about this when you passed 2 or more variables in the model:
The
tbl_survfit()
function supportssurvfit()
objects with a single stratifying variable, and it looks like you may have more. Errors or unexpected output may occur.
But I see this message was lost in the v2.0 release of the package. I'll add it back for the next release.
Upvotes: 1
Reputation: 206496
The answer was given in the "Common sources of errors in tbl_survfit" link you provided. You want to select the columns for your model, and then pass that into tbl_survfit
trial %>%
select(ttdeath, death, trt, stage) %>%
tbl_survfit(y = Surv(ttdeath, death), times = c(12, 24))
The difference here from what was on the page was the addition of "stage" in the select()
statement. You need to include whatever variables you want in the model there.
Upvotes: 0