Closed ddsjoberg closed 4 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:
uvregression()
function in charge of computing the different univariate models and returning a list of models with a .uvregressions
class.tidy()
and a glance()
method for .uvregression
objects. The tidy()
method will apply tidy()
to each sub-model and bind rows.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?
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
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.
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...
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?
Hi again ! Thanks for the answer, I'll wait for the maintenance and then I'll try to implement a method for imputed dfs.
Add function to package
tbl_uvregression()
add_n.tbl_uvregression()
add_global_p.tbl_uvregression()
add_nevent.tbl_uvregression()
plot.tbl_uvregressions()