ddsjoberg / gtsummary

Presentation-Ready Data Summary and Analytic Result Tables
http://www.danieldsjoberg.com/gtsummary
Other
1.04k stars 116 forks source link

v2.0 `tbl_uvregression()` #1641

Closed ddsjoberg closed 4 months ago

ddsjoberg commented 5 months ago

Add function to package

larmarange commented 5 months ago

Just a quick comment about plot.tbl_uvregression(). Technically, it cannot natively be handled by ggtstats::gcoef_model(), even if we could consider moving this function to ggstats.

But we could also maybe consider refactoring tbl_uvregression() and split it in smaller pieces:

  1. developing an uvregression() function in charge of computing the different univariate models and returning a list of models with a .uvregressions class.
  2. providing a tidy() and a glance() method for .uvregression objects. The tidy() method will apply tidy() to each sub-model and bind rows.
  3. updating broom.helpers to support .uvregression objects, so tidy_plus_plus() could be applied on such objects.

At that stage, .uvregression objects could be handled directly and natively by tbl_regression(), and as well by ggtstats::ggcoef_*() family (either allowing to compare univariate and multivariate models with ggcoef_compare().

Would it be an idea to explore? Should uvregression() be part of gtsummary() or be proposed in a dedicated package?

ddsjoberg commented 5 months ago

Hmmmm, good points. Maybe it's easier to simply keep supporting the functions as they are? The functions are pretty simple and probably won't be a burden to maintain.

#' @rdname plot
#' @export
plot.tbl_regression <- function(x,
                                remove_header_rows = TRUE,
                                remove_reference_rows = FALSE, ...) {
  check_dots_empty(error = function(e) inform(c(e$message, e$body)))
  assert_package("ggstats", fn = "plot.tbl_regression()")

  df_coefs <- x$table_body
  if (isTRUE(remove_header_rows)) {
    df_coefs <- df_coefs %>% filter(!.data$header_row %in% TRUE)
  }
  if (isTRUE(remove_reference_rows)) {
    df_coefs <- df_coefs %>% filter(!.data$reference_row %in% TRUE)
  }

  df_coefs %>%
    ggstats::ggcoef_plot(exponentiate = x$inputs$exponentiate, ...)
}

#' @rdname plot
#' @export
plot.tbl_uvregression <- plot.tbl_regression
larmarange commented 5 months ago

I agree with that these plot functions are easy to maintain.

Regarding a more general implementation of uvregressions(), I do think that it is something to keep in mind, but out of the scope of the v2.

ABohynDOE commented 4 months ago

Do you think that in v2.0 it would be possible to consider the implementation of tbl_uvregression() for multiple imputations from the mice package ? The details have already been mentioned in this issue

EDIT: I'm ready to help with the implementation but I don't really know where to start...

ddsjoberg commented 4 months ago

Hi again @ABohynDOE ,

The way we're constructing the models in uvregression will be based off of this function. https://insightsengineering.github.io/cardx/main/reference/construction_helpers.html

If you'd like to take a go at adding an S3 method for imputed data frames, while keeping the same API, please feel free. Note, however, that that function has some planned maintenance in the next month, so it could be a good idea to hold off until then?

ABohynDOE commented 4 months ago

Hi again ! Thanks for the answer, I'll wait for the maintenance and then I'll try to implement a method for imputed dfs.