Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0 tbl_uvregression() #1641

Closed
5 tasks done
ddsjoberg opened this issue May 13, 2024 · 6 comments
Closed
5 tasks done

v2.0 tbl_uvregression() #1641

ddsjoberg opened this issue May 13, 2024 · 6 comments
Labels

Comments

@ddsjoberg
Copy link
Owner

ddsjoberg commented May 13, 2024

Add function to package

  • tbl_uvregression()
  • add_n.tbl_uvregression()
  • add_global_p.tbl_uvregression()
  • add_nevent.tbl_uvregression()
  • plot.tbl_uvregressions()
@ddsjoberg ddsjoberg added the v2.0 label May 13, 2024
@larmarange
Copy link
Collaborator

larmarange commented May 14, 2024

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
Copy link
Owner Author

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
Copy link
Collaborator

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
Copy link

ABohynDOE commented May 24, 2024

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
Copy link
Owner Author

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants