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

make_table_10_gt #171

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Conversation

YoshitoKoujin
Copy link
Collaborator

-update argument for AESOC specification

Pull Request

Closes #nnn

-update argument for AESOC specification
@YoshitoKoujin YoshitoKoujin linked an issue Nov 17, 2023 that may be closed by this pull request
@YoshitoKoujin YoshitoKoujin changed the title -update gt make_table_10_gt Nov 17, 2023
@YoshitoKoujin YoshitoKoujin marked this pull request as ready for review November 30, 2023 04:41
Copy link
Contributor

github-actions bot commented Nov 30, 2023

badge

Code Coverage Summary

Filename            Stmts    Miss  Cover    Missing
----------------  -------  ------  -------  ---------
R/fda-fig_01.R         75       0  100.00%
R/fda-fig_02.R         75       0  100.00%
R/fda-fig_14.R        115       0  100.00%
R/fda-table_02.R      166       0  100.00%
R/fda-table_03.R       35       0  100.00%
R/fda-table_04.R       63       0  100.00%
R/fda-table_05.R       61       0  100.00%
R/fda-table_06.R       76       0  100.00%
R/fda-table_07.R       35       0  100.00%
R/fda-table_08.R       46       0  100.00%
R/fda-table_09.R      333       4  98.80%   254-258
R/fda-table_10.R       98       1  98.98%   194
R/fda-table_11.R       42       0  100.00%
R/fda-table_12.R       40       0  100.00%
R/fda-table_13.R       20       0  100.00%
R/fda-table_14.R       27       0  100.00%
R/fda-table_15.R       32       0  100.00%
R/fda-table_16.R       32       0  100.00%
R/fda-table_17.R       32       0  100.00%
R/fda-table_18.R       32       0  100.00%
R/fda-table_20.R       71       0  100.00%
R/fda-table_21.R       78       0  100.00%
R/fda-table_22.R       77       0  100.00%
R/fda-table_32.R       94       0  100.00%
R/fda-table_33.R       95       0  100.00%
R/fda-table_34.R       30       0  100.00%
R/fda-table_35.R       23       1  95.65%   58
R/fda-table_36.R       30       1  96.67%   70
R/fda-table_38.R       39       0  100.00%
R/utils.R              28       0  100.00%
TOTAL                2000       7  99.65%

Diff against main

Filename            Stmts    Miss  Cover
----------------  -------  ------  -------
R/fda-table_10.R      +72      +1  -1.02%
TOTAL                 +72      +1  -0.04%

Results for commit: 09e4b51

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Nov 30, 2023

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
fda-table_10 💔 $1.20$ $+19.52$ $+8$ $+2$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
fda-table_10 👶 $+13.25$ Table_10_gt_generation_works
fda-table_10 👶 $+6.26$ Table_10_gt_generation_works_with_custom_values

Results for commit 15b5d97

♻️ This comment has been updated with latest results.

@ayogasekaram
Copy link
Collaborator

ayogasekaram commented Dec 5, 2023

Thank you so much for working on this @YoshitoKoujin! I have a couple of suggestions:

  1. I'm looking at the FDA spec file and it looks like there are some rows in the gt table that aren't in the spec -
image

Is there a way to remove the numbers from these rows?

  1. is there a way to compute this table using gt_sum functions? with the gt table, I believe it's not only producing a gt end product but also using their functions to calculate the values. maybe you can consult @ddsjoberg on a direction for this table.

@ddsjoberg
Copy link
Collaborator

ddsjoberg commented Dec 5, 2023

There is a gtsummary extension that makes these types of tables (kind of, with a little manipulation). In the next release of gtsummary, these calculations will be 1. More straight-forward, 2. Much, much faster.

adsl <- scda::synthetic_cdisc_dataset("rcd_2022_10_13", "adsl")
adae <- scda::synthetic_cdisc_dataset("rcd_2022_10_13", "adae")

# Pre-Processing - Ensure required variables fmqsc_var and fmqnam_var exist in adae
set.seed(1)
adae <- adae |> 
  dplyr::rename(FMQ01SC = SMQ01SC) |> 
  dplyr::mutate(
    AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE),
    FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE)
  )
adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW"

example_table <- 
  # build primary table
  gtsummary::tbl_strata2(
    data = adae,
    strata = "AEBODSYS",
    ~gtreg::tbl_ae(
      data = .x |> dplyr::mutate(.x, AEBODSYS = .y),
      strata = "ARM",
      id = "USUBJID",
      soc = "AEBODSYS",
      ae = "FMQ01NAM",
      statistic = "{n} ({p}%)",
      id_df = adsl
    ),
    .combine_with = "tbl_stack",
    .combine_args = list(group_header = NULL)
  ) |> 
  # remove stats from SOC row
  gtsummary::modify_table_body(
    ~.x |> 
      dplyr::mutate(
        dplyr::across(
          gtsummary::all_stat_cols(),
          function(x) ifelse(.data$variable %in% "soc", "", x)
        )
      )
  ) |> 
  # update column headers
  gtsummary::modify_header(
    gtreg::all_ae_cols() ~ "**{strata}**  \nN = {n}",
    label = "**Body System or Organ Class**  \nFMQ (Narrow)"
  ) |> 
  gtsummary::modify_spanning_header(gtreg::all_ae_cols() ~ NA) |> 
  # bold SOC rows
  gtsummary::modify_table_styling(
    columns = "label",
    rows = variable %in% "soc",
    text_format = "bold"
  ) 
image

@YoshitoKoujin
Copy link
Collaborator Author

There is a gtsummary extension that makes these types of tables (kind of, with a little manipulation). In the next release of gtsummary, these calculations will be 1. More straight-forward, 2. Much, much faster.

adsl <- scda::synthetic_cdisc_dataset("rcd_2022_10_13", "adsl")
adae <- scda::synthetic_cdisc_dataset("rcd_2022_10_13", "adae")

# Pre-Processing - Ensure required variables fmqsc_var and fmqnam_var exist in adae
set.seed(1)
adae <- adae |> 
  dplyr::rename(FMQ01SC = SMQ01SC) |> 
  dplyr::mutate(
    AESER = sample(c("Y", "N"), size = nrow(adae), replace = TRUE),
    FMQ01NAM = sample(c("FMQ1", "FMQ2", "FMQ3"), size = nrow(adae), replace = TRUE)
  )
adae$FMQ01SC[is.na(adae$FMQ01SC)] <- "NARROW"

example_table <- 
  # build primary table
  gtsummary::tbl_strata2(
    data = adae,
    strata = "AEBODSYS",
    ~gtreg::tbl_ae(
      data = .x |> dplyr::mutate(.x, AEBODSYS = .y),
      strata = "ARM",
      id = "USUBJID",
      soc = "AEBODSYS",
      ae = "FMQ01NAM",
      statistic = "{n} ({p}%)",
      id_df = adsl
    ),
    .combine_with = "tbl_stack",
    .combine_args = list(group_header = NULL)
  ) |> 
  # remove stats from SOC row
  gtsummary::modify_table_body(
    ~.x |> 
      dplyr::mutate(
        dplyr::across(
          gtsummary::all_stat_cols(),
          function(x) ifelse(.data$variable %in% "soc", "", x)
        )
      )
  ) |> 
  # update column headers
  gtsummary::modify_header(
    gtreg::all_ae_cols() ~ "**{strata}**  \nN = {n}",
    label = "**Body System or Organ Class**  \nFMQ (Narrow)"
  ) |> 
  gtsummary::modify_spanning_header(gtreg::all_ae_cols() ~ NA) |> 
  # bold SOC rows
  gtsummary::modify_table_styling(
    columns = "label",
    rows = variable %in% "soc",
    text_format = "bold"
  ) 
image

Thank you for the info. I'm looking forward to the next release!

@YoshitoKoujin
Copy link
Collaborator Author

Thank you for your review @ayogasekaram! I've made some adjustments and removed a few rows based on your comments. Could you please take a look at the updated program? This version utilizes 'gt', but does not incorporate 'gtsummary'. However, we will need to update it once the new 'gtsummary' is released. Therefore, please consider this program as a provisional version.

Copy link
Contributor

Unit Tests Summary

  1 files   29 suites   1m 31s ⏱️
130 tests 130 ✅   0 💤 0 ❌
473 runs  351 ✅ 122 💤 0 ❌

Results for commit 09e4b51.

@ayogasekaram
Copy link
Collaborator

This PR will be revisited when the gtsummary package updates are complete and released.

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

Successfully merging this pull request may close these issues.

Create make_table_10_gt
4 participants