insightsengineering / cards

CDISC Analysis Results Data
https://insightsengineering.github.io/cards/
30 stars 2 forks source link

Best way to tabulate any AE? #212

Closed ddsjoberg closed 6 months ago

ddsjoberg commented 6 months ago

When we want to tabulate the number of AEs and the rate, we need to do an awkward full join. Is there a way we could make this happen with just specifying ard_categorical(denominator)?

card_any_ae <-
  adae |> 
  slice(1L, .by = USUBJID) |> 
  mutate(any_ae = TRUE) |> 
  full_join(
    adsl, 
    by = c("USUBJID", "TRTA")
  ) |> 
  mutate(any_ae = coalesce(any_ae, FALSE)) |> 
  cards::ard_dichotomous(by = TRTA, variable = any_ae)
card_any_ae
ddsjoberg commented 6 months ago

can just do this with this code

ADAE |> 
  dplyr::slice(1L, .by = USUBJID) |> 
  dplyr::mutate(any_ae = TRUE) |> 
  cards::ard_dichotomous(by = TRTA, variable = any_ae, denominator = ADSL |> dplyr::rename(TRTA = ARM))