rtables
rtables copied to clipboard
How to change placement of column counts (N) for nested columns?
For nested column splits, Is it possible to add the column counts N
to the highest-level column? For example:
basic_table() %>%
add_colcounts() %>%
split_cols_by("ARM") %>%
split_cols_by_multivar(c("AGE", "BMRKR1")) %>%
analyze_colvars(afun = mean, format = "xx.x") %>%
build_table(DM)
Looks like:
A: Drug X B: Placebo C: Combination
AGE BMRKR1 AGE BMRKR1 AGE BMRKR1
(N=121) (N=121) (N=106) (N=106) (N=129) (N=129)
----------------------------------------------------------------
mean 34.9 5.8 33 6.1 34.6 5.7
I would like the (N=xx) row to be under the "ARM" column headings like so:
A: Drug X B: Placebo C: Combination
(N=121) (N=106) (N=129)
AGE BMRKR1 AGE BMRKR1 AGE BMRKR1
----------------------------------------------------------------
mean 34.9 5.8 33 6.1 34.6 5.7
Session info:
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rtables_0.3.2.17.9045 magrittr_1.5
loaded via a namespace (and not attached):
[1] compiler_3.6.3 htmltools_0.4.0 tools_3.6.3 Rcpp_1.0.4.6 digest_0.6.25 packrat_0.5.0 rlang_0.4.6 purrr_0.3.4
There have been some discussions of implementing this between @waddella and myself but currently I do not believe this is not possible, no.
In particular, how this would interact with overridden counts is quite unclear if we were to do it.
On Tue, Nov 24, 2020, 4:18 PM anajens [email protected] wrote:
For nested column splits, Is it possible to add the column counts N to the highest-level column? For example:
basic_table() %>% add_colcounts() %>% split_cols_by("ARM") %>% split_cols_by_multivar(c("AGE", "BMRKR1")) %>% analyze_colvars(afun = mean, format = "xx.x") %>% build_table(DM)
Looks like:
A: Drug X B: Placebo C: Combination AGE BMRKR1 AGE BMRKR1 AGE BMRKR1 (N=121) (N=121) (N=106) (N=106) (N=129) (N=129)
mean 34.9 5.8 33 6.1 34.6 5.7
I would like the (N=xx) row to be under the "ARM" column headings like so:
A: Drug X B: Placebo C: Combination (N=121) (N=106) (N=129) AGE BMRKR1 AGE BMRKR1 AGE BMRKR1
mean 34.9 5.8 33 6.1 34.6 5.7
Session info:
R version 3.6.3 (2020-02-29) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Linux 9 (stretch)
Matrix products: default BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so
locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C [7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] rtables_0.3.2.17.9045 magrittr_1.5
loaded via a namespace (and not attached): [1] compiler_3.6.3 htmltools_0.4.0 tools_3.6.3 Rcpp_1.0.4.6 digest_0.6.25 packrat_0.5.0 rlang_0.4.6 purrr_0.3.4
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Roche/rtables/issues/135, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG53MMTGC4ZBFK4DQYWUB3SRRENVANCNFSM4UBSUZHQ .
Thanks @anajens and @gmbecker . Yeah we discussed this a while ago already. I had some more concrete ideas on the user interface for layout and build:
-
In the layout creation pipeline, the
add_colcounts()
function should attach column counts to the immediate previous column split only. This could change the type of column split to a "labeled column split". (Note that I have a prototypeadd_rowcounts()
internally which works in the same way, i.e. just to previous row split.) -
Then when calling
build_table
, we could have a new argumentcol_counts
that is now taking a data frame that has (at least) the same columns as were used in the layout for labeled column splits (see above). The same splits are performed on this data frame then internally, and the resulting N numbers are used for labeling the columns in the resulting table. This would be nice since it is general and actually simplifying things for the user even in the situation of a single col counts - the user can just pass the ADSL table e.g., instead of manually doing the tabulation on the col split variable and passing that.
build_table now accepts the alt_counts_df
argument which does what is suggested in @danielinteractive's comment above, though support for multi-level reporting of column counts is still not in currently. Rather, it was implemented as a fix/workaround for #154
Thanks @gmbecker ! Being aware of the date today etc, still wondering: do you think this still comes in time for the release? (I guess not) Background is that we have a couple of tables where this would be much cleaner and much less hacky than what we are currently doing as workaround. (Note that also with alt_counts_df
we need to work around here)
@gmbecker just wanted to add another example for this use case:
anl <- ex_advs %>%
filter(AVISIT %in% c("BASELINE", "WEEK 3 DAY 22")) %>%
droplevels()
df_N <- anl %>%
select(USUBJID, ARM) %>%
unique()
# This is what should be shown in the header.
df_N %>% count(ARM)
basic_table() %>%
split_cols_by("ARM") %>%
split_cols_by("AVISIT") %>%
add_colcounts() %>%
split_rows_by("PARAM") %>%
analyze("AVAL") %>%
build_table(anl, alt_counts_df = df_N)
Right now the above gives an error because the reference dataset does not include AVISIT. The idea result should look like this:
A: Drug X B: Placebo C: Combination
(N = 134) (N = 134) (N = 132)
BASELINE WEEK 3 DAY 22 BASELINE WEEK 3 DAY 22 BASELINE WEEK 3 DAY 22
---------------------------------------------------------------------------------------------------------
Diastolic Blood Pressure
Mean 48.6 50.71 50.44 49.09 51.11 49.94
Pulse Rate
Mean 51.86 50.45 50.27 49.92 50.25 49.8
Respiratory Rate
Mean 49.41 50.61 51.12 50.16 50.75 49.15
Systolic Blood Pressure
Mean 49.41 49.68 50.25 49.03 48.49 50.54
Temperature
Mean 49.75 50.08 50.87 49.88 49.12 49.67
Weight
Mean 50.73 48.96 49.88 49.57 49.38 50.45
@gmbecker can we address this in the near future?
@Melkiades ping
@BFalquet this feature is in the overall backlog but is not currently slated to be worked on (and there isn't room to add it in the current increment), so this is a "it will go in eventually but it probably won't be super soon" kind of situation.
@BFalquet this feature is in the overall backlog but is not currently slated to be worked on (and there isn't room to add it in the current increment), so this is a "it will go in eventually but it probably won't be super soon" kind of situation.
ok, thanks for the update, that is what we understood from the PI planning, I am just cross-referencing the issue so that it doesn't disappear into oblivion.