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

Create or adapt an analysis function for injection rate #1302

Open
edelarua opened this issue Sep 5, 2024 · 3 comments
Open

Create or adapt an analysis function for injection rate #1302

edelarua opened this issue Sep 5, 2024 · 3 comments
Assignees

Comments

@edelarua
Copy link
Contributor

edelarua commented Sep 5, 2024

Create a new analysis function or adapt estimate_incidence_rate() if possible to calculate rate per injection, with rows as follows:

  • "Total number of injections" - default format "xx"
  • "Total number of adverse events (Rate per injection)" - default format "xx (xx.x)"
@edelarua
Copy link
Contributor Author

edelarua commented Sep 5, 2024

Hi @barnett11,

This issue relates to AET10ALL_INJ. Are you able to provide some details on how injection data appears in a dataset (or, ideally, dummy data)? Is this data usually part of ADAETTE?

Thanks!!

@barnett11
Copy link

Hi @barnett11,

This issue relates to AET10ALL_INJ. Are you able to provide some details on how injection data appears in a dataset (or, ideally, dummy data)? Is this data usually part of ADAETTE?

Thanks!!

Hi @edelarua - it would come from ADEX where PARAMCD="TNDOSE"

@edelarua
Copy link
Contributor Author

edelarua commented Sep 9, 2024

Tentative solution:

library(tern) 

adsl <- random.cdisc.data::cadsl
adex <- random.cdisc.data::cadex
adae <- random.cdisc.data::cadae

# filter injection data so PARAMCD == "TNDOSE"
anl <- dplyr::left_join(
  adae,
  adex %>% 
    dplyr::filter(PARAMCD == "TNDOSE") %>%
    dplyr::select(USUBJID, AVAL),
  by = "USUBJID"
)

a_ae_dose_rate <- function(df,
                           .var,
                           aval_var = "AVAL",
                           id_var = "USUBJID",
                           per_n_dose = NULL,
                           tot_inj_row = TRUE,
                           tot_ae_row = TRUE,
                           .df_row,
                           .N_col,
                           .labels = list(
                             tot_inj = "Total number of injections",
                             tot_ae = "Total number of adverse events (rate per injection)"
                           ),
                           .formats = list(tot_inj = "xx", tot_ae = "xx (xx.xx)", ae_rows = "xx (xx.xx)"),
                           .indent_mods = list(tot_inj = 0L, tot_ae = 0L, ae_rows = 1L),
                           na_str = default_na_str()) {
  # process data
  df_dose <- df %>% dplyr::distinct(.data[[id_var]], .keep_all = TRUE)
  if (is.null(per_n_dose)) per_n_dose <- 1
  
  # calculate statistics
  tot_dose <- sum(df_dose[[aval_var]])
  ae_cts <- s_count_occurrences(df = df, .var = .var, .N_col = .N_col, .df_row = .df_row)$count
  ae_cts_rates <- lapply(ae_cts, function(x, per_n) c(x, x / tot_dose * per_n), per_n = per_n_dose)

  # apply formatting
  .formats <- c(
    if (tot_inj_row) .formats$tot_inj, 
    if (tot_ae_row) .formats$tot_ae, 
    rep(.formats$ae_rows, length(ae_cts))
  )
  .indent_mods <- c(
    if (tot_inj_row) .indent_mods$tot_inj, 
    if (tot_ae_row) .indent_mods$tot_ae, 
    rep(.indent_mods$ae_rows, length(ae_cts))
  )
  
  # add total AEs row
  if (tot_ae_row) {
    overall_aes <- sum(unlist(ae_cts))
    overall <- list(c(overall_aes, overall_aes / tot_dose * per_n_dose))
    names(overall) <- .labels$tot_ae
    ae_cts_rates <- c(overall, ae_cts_rates)
  }

  # add total injections row
  if (tot_inj_row) {
    overall <- list(tot_dose)
    names(overall) <- .labels$tot_inj
    ae_cts_rates <- c(overall, ae_cts_rates)
  }
  
  in_rows(
    .list = ae_cts_rates,
    .formats = .formats,
    .indent_mods = .indent_mods,
    .format_na_strs = na_str
  )
}

basic_table(show_colcounts = TRUE) %>%
  split_cols_by("ARM") %>%
  analyze(
    vars = "AETERM",
    afun = a_ae_dose_rate,
    extra_args = list(
      tot_inj_row = TRUE, tot_ae_row = TRUE, 
      per_n_dose = 100,
      .labels = list(
        tot_inj = "Total number of injections",
        tot_ae = "Total number of adverse events (rate per 100 injections)"
      )
    )
  ) %>%
  append_topleft("MedDRA Preferred Term") %>%
  build_table(anl, alt_counts_df = adsl)
#>                                                             A: Drug X    B: Placebo    C: Combination
#> MedDRA Preferred Term                                        (N=134)       (N=134)        (N=132)    
#> —————————————————————————————————————————————————————————————————————————————————————————————————————
#> Total number of injections                                     854           861            840      
#> Total number of adverse events (rate per 100 injections)   465 (54.45)   476 (55.28)    515 (61.31)  
#>   trm A.1.1.1.1                                             50 (5.85)     45 (5.23)      63 (7.50)   
#>   trm A.1.1.1.2                                             48 (5.62)     48 (5.57)      50 (5.95)   
#>   trm B.1.1.1.1                                             47 (5.50)     49 (5.69)      43 (5.12)   
#>   trm B.2.1.2.1                                             49 (5.74)     44 (5.11)      52 (6.19)   
#>   trm B.2.2.3.1                                             48 (5.62)     54 (6.27)      51 (6.07)   
#>   trm C.1.1.1.3                                             43 (5.04)     46 (5.34)      43 (5.12)   
#>   trm C.2.1.2.1                                             35 (4.10)     48 (5.57)      55 (6.55)   
#>   trm D.1.1.1.1                                             50 (5.85)     42 (4.88)      51 (6.07)   
#>   trm D.1.1.4.2                                             48 (5.62)     42 (4.88)      50 (5.95)   
#>   trm D.2.1.5.3                                             47 (5.50)     58 (6.74)      57 (6.79)

Created on 2024-09-09 with reprex v2.1.1

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

No branches or pull requests

2 participants