atorus-research / Tplyr

Home Page:https://atorus-research.github.io/Tplyr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Denominator grouping issue

cyangrw opened this issue · comments

commented

The example in the Tplyr articles (https://atorus-research.github.io/Tplyr/articles/denom.html) set_denoms_by seems to work

tplyr_table(adsl, TRT01P) %>% 
  add_layer(
    group_count(DCSREAS, by=SEX) %>% 
      set_denoms_by(SEX, TRT01P)
  ) %>% 
  build() %>% 
  kable()

However if add set_distinct_by then the numbers will be not right, looks like it overrides the setting of set_denoms_by no matter what grouping it is specifying.

tplyr_table(adsl, TRT01P) %>% 
  set_pop_data(adsl) %>%
  set_pop_treat_var(TRT01P) %>%
  set_pop_where(SAFFL == "Y") %>%
  set_distinct_by(USUBJID) %>%
  add_layer(
    group_count(DCSREAS, by=SEX) %>% 
      set_denoms_by(SEX, TRT01P)
  ) %>% 
  build()

A very typical case is when dealing with labs data, where the users want the denominator to be by treatment group and AVISIT, and it needs to be distinct SUBJID, is there a solution to make it work?

tplyr_meta <- data %>% tplyr_table(TRT01A) %>%
    set_pop_data(adsl) %>%
    set_pop_treat_var(TRT01A) %>%
    set_pop_where(SAFFL == "Y") %>%
    set_distinct_by(SUBJID) %>%
    set_count_layer_formats(n_counts = f_str("xx/x (xx.x)", distinct_n, distinct_total, distinct_pct)) %>%
    add_layer(group_count("Any Out of Range", by = AVISIT) %>%
                set_denoms_by(AVISIT, TRT01A)) %>%
    add_layer(group_count(RANGEFL, by = vars(AVISIT, PARAM)) %>%
                set_denoms_by(AVISIT, PARAM, TRT01A))

@cyangrw can you please pull the development branch down and see if this resolves your issue? We just made a bug fix for #136 through #139 that I believe should correct this issue.

It seems to work correctly now, thanks.

close this issue