I like the syntax of GTsummary and tbl_summary, but I find it very slow on my Mac Book Air M2 with 8 GB of RAM.
Is this a normal render time for gtsummary?
library(dplyr)
library(gtsummary)
#make up dataset
set.seed(1)
data_set <- as_tibble(rnorm(1000,mean=100,sd=20))
data_set <- data_set %>% mutate(cohort=rbinom(1000,1,0.5),
value_2=rnorm(1000,mean=100,sd=20),
value_3=rnorm(1000,mean=100,sd=20),
value_4=rnorm(1000,mean=100,sd=20),
value_5=rnorm(1000,mean=100,sd=20),
value_6=rnorm(1000,mean=100,sd=20))
start_time <- Sys.time()
data_set %>% tbl_summary(by=cohort)
end_time <- Sys.time()
end_time-start_time
Time difference of 5.646836 secs
With your code, I have a similar time using an AMD Ryzen 7 2700x.
It is true gtsummary seems quite slow, and the issue gets worse with complex models with lots of data.
For the sake of comparison, below the time it takes gtsummary and sjPlot to create roughly the same plot. As you can see, gtsummary takes 4 times more.
Not sure if there may be a parameter to avoid some complex calculation behind the curtains... Any hints, @daniel-d-sjoberg ?
model = lm(total.fruits ~ nutrient + amd + status, lme4::Arabidopsis)
tictoc::tic(msg = "gtsummary")
TABLE1 = model |>
gtsummary::tbl_regression(intercept = TRUE, pvalue_fun = ~ gtsummary::style_pvalue(.x, digits = 3)) |>
gtsummary::bold_p(t = 0.05) |>
gtsummary::bold_labels() |>
gtsummary::italicize_levels() |>
gtsummary::add_glance_table(include = c("nobs", "r.squared", "adj.r.squared"))
# TABLE1
tictoc::toc()
#> gtsummary: 3.15 sec elapsed
tictoc::tic(msg = "sjPlot")
TABLE2 = sjPlot::tab_model(model)
# TABLE2
tictoc::toc()
#> sjPlot: 0.703 sec elapsed
Created on 2023-03-08 with reprex v2.0.2