Coder Social home page Coder Social logo

Comments (2)

anajens avatar anajens commented on June 14, 2024

The current approach for using count_patients_with_flags relies on a step with insert_rrow to add a title row in a layout. The function should be refactored to include it's own title row. Rationale:
(1) Use of insert_rrow creates a problem with the indentation - e.g. "Serious AE" row has extra indentation (this is not a bug in rtables. More background here: insightsengineering/rtables#202)
(2) insert_rrow may be deprecated (insightsengineering/rtables#214)

Sample code:

library(tern)
library(dplyr)
library(scda)

adsl <- synthetic_cdisc_data("latest")$adsl
adae <- synthetic_cdisc_data("latest")$adae

# Create custom flags:
adae <- adae %>%
  mutate(
    SER = AESER == "Y",
    REL = AEREL == "Y",
    CTC35 = AETOXGR %in% c("3", "4", "5"),
    CTC45 = AETOXGR %in% c("4", "5")
  ) %>%
  var_relabel(
    SER = "Serious AE",
    REL = "Related AE",
    CTC35 = "Grade 3-5 AE",
    CTC45 = "Grade 4/5 AE"
  )

aesi_vars <- c("SER", "REL", "CTC35", "CTC45")

# Create layout
lyt <- basic_table() %>%
  split_cols_by("ACTARM") %>%
  add_colcounts() %>%
  count_patients_with_event(
    vars = "USUBJID",
    filters = c("STUDYID" = as.character(unique(adae$STUDYID))),
    denom = "N_col",
    .labels = c(count_fraction = "Total number of patients with at least one adverse event")
  ) %>%
  count_patients_with_flags(
    "USUBJID",
    flag_variables = var_labels(adae[, aesi_vars]),
    .indent_mods = 1L
  )

result <- build_table(lyt, df = adae, alt_counts_df = adsl)

result <- insert_rrow(result, rrow("Total number of patients with at least one"), at = 2)
result
                                                            A: Drug X    B: Placebo    C: Combination
                                                             (N=134)       (N=134)        (N=132)    
-----------------------------------------------------------------------------------------------------
Total number of patients with at least one adverse event    122 (91%)    123 (91.8%)    120 (90.9%)  
Total number of patients with at least one                                                           
    Serious AE                                             104 (77.6%)   101 (75.4%)      99 (75%)   
  Related AE                                               105 (78.4%)   108 (80.6%)    109 (82.6%)  
  Grade 3-5 AE                                             109 (81.3%)   104 (77.6%)    109 (82.6%)  
  Grade 4/5 AE                                             91 (67.9%)    90 (67.2%)      93 (70.5%)  

from tern.

anajens avatar anajens commented on June 14, 2024

I'm moving this to SME sprint 28 board.

from tern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.