insightsengineering / tern

Table, Listings, and Graphs (TLG) library for common outputs used in clinical trials
https://insightsengineering.github.io/tern/
Other
77 stars 22 forks source link

Update summarize_ancova emmeans contrast #645

Closed ayogasekaram closed 2 years ago

ayogasekaram commented 2 years ago

Bug in s_ancova results in error when changing the reference group to "ARM B" or "ARM C".

library(scda)
library(rtables)
library(dplyr)

adsl <- synthetic_cdisc_data("latest")$adsl
adqs <- synthetic_cdisc_data("latest")$adqs
adqs_single <- adqs %>%
 filter(
     AVISIT == "WEEK 1 DAY 8", # single time point
     PARAMCD == "FKSI-FWB" # single end point
   ) %>%
   mutate(CHG = ifelse(BMEASIFL == "Y", CHG, NA)) # only analyze evaluable population
 adqs_multi <- adqs %>%
   filter(AVISIT == "WEEK 1 DAY 8")

 basic_table() %>%
   split_cols_by("ARMCD", ref_group = "ARM B") %>%
   add_colcounts() %>%
   summarize_ancova(
     vars = "CHG",
     variables = list(arm = "ARMCD", covariates = NULL),
     table_names = "unadj",
     conf_level = 0.95, var_labels = "Unadjusted comparison",
     .labels = c(lsmean = "Mean", lsmean_diff = "Difference in Means")
   ) %>%
   summarize_ancova(
    vars = "CHG",
     variables = list(arm = "ARMCD", covariates = c("BASE", "STRATA1")),
     table_names = "adj",
     conf_level = 0.95, var_labels = "Adjusted comparison (covariates BASE and STRATA1)"
   ) %>%
   build_table(adqs_single, alt_counts_df = adsl)

Results in:

result_summarize_ancova
JiaLiu0001 commented 2 years ago

Thank you @ayogasekaram , the bug is fixed. The updates pull request is here https://github.com/insightsengineering/tern/pull/651