shah-in-boots / rmdl

A Causality-Informed Modeling Appraoch
https://shah-in-boots.github.io/rmdl/
Other
0 stars 0 forks source link

Forest tables #29

Closed shah-in-boots closed 9 months ago

shah-in-boots commented 1 year ago

Forest tables will help to document usually subgroup or comparison analyses. It seems like they can vary in the following ways:

Will need to come-up with a "methodology" for how to approach these on the spectrum. It should be somewhat flexible to modify as well because stylistic differences are crucial. Best option would be to let ggplot2 handle the plotting differences, and gt handle the font/color differences.

  1. Multiple Terms/Exposures x Single Subgroup
  2. Single Term/Exposure x Multiple Subgroup

Sub-issues that have arisen thus far:

shah-in-boots commented 1 year ago

Potential solution to level issues, which remains a problem in commit c1a42428, may be resolved by ignoring level labels altogether in the function. Instead, the levels may better be renamed at the dataset level? However this requires the naming and labeling to come from original dataset (instead of the mdl_tbl object).

shah-in-boots commented 10 months ago

Starting to review this again, as it had fallen off of development. Have created a new branch forest_by_group to work on this.

shah-in-boots commented 10 months ago

One consideration as we move towards forest plots is that there are multiple subtypes of forest plots. Strata-based, interaction term based, etc. Will need to consider the role of these complex plots and how they can be combined. E.g. should a survival plot be able to be combined with a forest plot?

If so, how can we do this safely? It would require a lot of checks/balances to ensure consistency of the data between two tables to merge them....

shah-in-boots commented 9 months ago

Interaction forest plots should work if given all the right arguments.

May need to push these into new issues

Example below

Local .Rprofile detected at /Users/asshah4/projects/vlndr/.Rprofile

library(vlndr)
#> Loading required package: vctrs
#> Loading required package: tibble
#> 
#> Attaching package: 'tibble'
#> The following object is masked from 'package:vctrs':
#> 
#>     data_frame
f <- vec_c(fmls(hp + mpg ~ .x(wt) + .i(am) + cyl),
           fmls(hp + mpg ~ .x(wt) + .i(vs) + cyl)) |>
  suppressMessages()
m <- fit(f, .fn = lm, data = mtcars, raw = FALSE)
object <- model_table(linear = m, data = mtcars)

# Variables of interest for filtering are function arguments

gtbl <-
  tbl_interaction_forest(
    object,
        outcomes = list(hp ~ "Horsepower"),
        exposures = list(wt ~ "Weight"),
        interactions = list(am ~ "Transmission", vs ~ "Engine"),
        level_labels = list(am ~ c("Automatic", "Manual"),
                           vs ~ c("V8", "V6")),
        columns = list(beta ~ "Estimate", conf ~ "95% CI", n ~ "No.", p ~ "Interaction p-value"),
        axis = list(scale ~ "continuous", title ~ "Forest"),
        width = list(),
        forest = list()
  )

Created on 2024-01-28 with reprex v2.1.0

shah-in-boots commented 9 months ago

Now technically functioning for interaction.