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

Populate "overall" categories for ard_stack(..., .overall = TRUE, .shuffle = TRUE) #234

Closed
bzkrouse opened this issue Apr 25, 2024 · 3 comments
Assignees
Milestone

Comments

@bzkrouse
Copy link
Collaborator

We have some code in shuffle_ard() to populate levels with "Overall < varname >" if a grouping variable is present but its level is NA (like with for overall stat tests). It would be nice for this to happen for overall calculations from ard_stack() as well, to effectively create a separate "overall" category for displays. This requires adding just a bit of code in ard_stack() prior to the shuffle.

example:

ard_stack(
  data = adsl_,
  by = TRT01A,
  ard_continuous(variables = AGE),
  ard_categorical(variables = AGEGR1),
  .shuffle = TRUE,
  .overall = TRUE
)  

Current rows corresponding to the overall calculations:

# A tibble: 17 × 6
   TRT01A variable label           context     stat_name    stat
   <chr>  <chr>    <chr>           <chr>       <chr>       <dbl>
 1 NA     AGE      N               continuous  N         254    
 2 NA     AGE      Mean            continuous  mean       75.1  
 3 NA     AGE      SD              continuous  sd          8.25 
 4 NA     AGE      Median          continuous  median     77    
 5 NA     AGE      25th Percentile continuous  p25        70    
 6 NA     AGE      75th Percentile continuous  p75        81    
 7 NA     AGE      Min             continuous  min        51    
 8 NA     AGE      Max             continuous  max        89    
 9 NA     AGEGR1   <65             categorical n          33    
10 NA     AGEGR1   <65             categorical N         254    

Desired result:

# A tibble: 26 × 6
   TRT01A         variable label           context     stat_name   stat
   <chr>          <chr>    <chr>           <chr>       <chr>      <dbl>
 1 Overall TRT01A AGE      N               continuous  N         254   
 2 Overall TRT01A AGE      Mean            continuous  mean       75.1 
 3 Overall TRT01A AGE      SD              continuous  sd          8.25
 4 Overall TRT01A AGE      Median          continuous  median     77   
 5 Overall TRT01A AGE      25th Percentile continuous  p25        70   
 6 Overall TRT01A AGE      75th Percentile continuous  p75        81   
 7 Overall TRT01A AGE      Min             continuous  min        51   
 8 Overall TRT01A AGE      Max             continuous  max        89   
 9 Overall TRT01A AGEGR1   <65             categorical n          33   
10 Overall TRT01A AGEGR1   <65             categorical N         254   

@ddsjoberg I will put in a PR to get your thoughts!

@ddsjoberg
Copy link
Collaborator

From our meeting on May 20, 2024: Something like this could work for populating an Overall grouping level from within ard_shuffle()

library(cards)

tt <- bind_ard(
  ard_categorical(ADSL, by = ARM, variables = AGEGR1),
  ard_categorical(ADSL, variables = AGEGR1),
  ard_categorical(ADSL, variables = ARM)
)

tt_missing_by <-
  tt |> 
  dplyr::filter(is.na(group1)) |> 
  dplyr::rows_update(
    tt |> 
      dplyr::filter(!is.na(group1)) |> 
      dplyr::select(all_ard_variables(), "stat_name", "stat_label") |> 
      dplyr::distinct() |> 
      dplyr::mutate(group1 = "ARM", group1_level = list("Overall"), .before = 1L),
    by = c("variable", "variable_level", "stat_name", "stat_label"),
    unmatched = "ignore"
  )
tt_missing_by
tt[is.na(tt$group1), names(tt_missing_by)] <- tt_missing_by
tt

@ddsjoberg ddsjoberg added this to the v0.3.0 milestone Aug 26, 2024
@ddsjoberg
Copy link
Collaborator

@bzkrouse to investigate and close if it's already done

@ddsjoberg
Copy link
Collaborator

Added in PR #306

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

Successfully merging a pull request may close this issue.

2 participants