Denominator grouping issue
cyangrw opened this issue · comments
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))
It seems to work correctly now, thanks.
close this issue