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

Cleanup gtcrosstabs #31

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Cleanup gtcrosstabs #31

wants to merge 5 commits into from

Conversation

aspina7
Copy link
Member

@aspina7 aspina7 commented Mar 19, 2023

starting a new function for adding cross tabulations to a gtsummary tbl_uvregression

y = {{case}},
include = {{exposure}},
method.args = list(family = poisson,
offset = log({{obstime}})),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chucking an error with {{obstime}} - cant figure out how to just feed all of this in to method.args clean - this would allow to specify up top and only need one call to gtsummary::tbl_uvregression

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: create a temp var which is log ostime, then can just pass all as a char!

@aspina7
Copy link
Member Author

aspina7 commented Apr 17, 2023

hey @zkamvar - can I bug you for a sec?
I managed to pull apart your two_by_two_functions so that they now work in gtsummary and for categorical variables too!

They are all now in tbl_univariate_stratified_internal.R (realise now I should probably rename this for clarity)...

  • tbl_cmh_internal() pulls all the bits together for stratified table
  • add_crosstabs() returns the appropriate counts for a tbl_cmh or a gtsummary::tbl_uvregression.

None of the documentation is up to scratch just yet (sorry) - and the code is still very repeaty ineffecienty....
One thing that would make it all cleaner is if I could pass arguments to the gtsummary regression call (see comment above) but I cant get it to cooperate.
Any chance you could take a quick peak please? Copying a dataframe below that can use to mess ....
Thanks!
Oh the brightside is that I can probably re-use most of the tests! And it also means we can retire most of our old table functions

linelist_cleaned <- tibble::tribble(
      ~DIED, ~fever_bin, ~age_group, ~obstime,
      FALSE,      FALSE,      "45+",       4L,
      TRUE,      FALSE,    "15-29",      12L,
      TRUE,      FALSE,    "15-29",      20L,
      TRUE,      FALSE,     "3-14",      16L,
      FALSE,       TRUE,      "45+",      23L,
      TRUE,      FALSE,    "30-44",      21L,
      TRUE,       TRUE,    "15-29",      30L,
      TRUE,       TRUE,      "45+",      30L,
      FALSE,      FALSE,     "3-14",      13L,
      FALSE,       TRUE,     "3-14",      27L,
      TRUE,      FALSE,    "15-29",       6L,
      FALSE,       TRUE,     "3-14",      19L,
      FALSE,      FALSE,    "30-44",      10L,
      FALSE,       TRUE,      "45+",       4L,
      FALSE,       TRUE,      "45+",      18L,
      FALSE,      FALSE,      "45+",      19L,
      FALSE,       TRUE,      "45+",      21L,
      FALSE,      FALSE,     "3-14",      27L,
      FALSE,      FALSE,      "45+",      29L,
      TRUE,      FALSE,    "30-44",      10L,
      TRUE,       TRUE,    "15-29",       6L,
      TRUE,      FALSE,    "30-44",      10L,
      TRUE,      FALSE,    "15-29",      17L,
      FALSE,      FALSE,    "15-29",      25L,
      FALSE,       TRUE,      "45+",      25L,
      TRUE,       TRUE,      "45+",      18L,
      FALSE,       TRUE,    "15-29",       1L,
      FALSE,       TRUE,    "15-29",      23L,
      FALSE,      FALSE,      "45+",       8L,
      FALSE,      FALSE,     "3-14",      28L,
      FALSE,       TRUE,      "45+",      21L,
      FALSE,      FALSE,    "15-29",      28L,
      FALSE,       TRUE,      "0-2",      19L,
      FALSE,       TRUE,      "45+",      11L,
      FALSE,      FALSE,     "3-14",      25L,
      FALSE,       TRUE,      "0-2",      26L,
      FALSE,       TRUE,     "3-14",      15L,
      FALSE,      FALSE,      "45+",      10L,
      FALSE,       TRUE,     "3-14",      15L,
      TRUE,      FALSE,    "15-29",       1L,
      FALSE,       TRUE,    "15-29",      20L,
      FALSE,       TRUE,    "15-29",      29L,
      FALSE,       TRUE,     "3-14",       6L,
      FALSE,       TRUE,    "30-44",       7L,
      TRUE,      FALSE,    "30-44",      20L,
      FALSE,      FALSE,      "45+",      21L,
      FALSE,       TRUE,      "45+",      26L,
      FALSE,       TRUE,    "30-44",      16L,
      TRUE,      FALSE,    "30-44",      16L,
      TRUE,       TRUE,     "3-14",      30L,
      FALSE,      FALSE,    "15-29",      22L,
      FALSE,      FALSE,    "15-29",      18L,
      TRUE,      FALSE,      "45+",      14L,
      TRUE,      FALSE,    "15-29",      25L,
      TRUE,      FALSE,     "3-14",       9L,
      FALSE,       TRUE,    "30-44",      15L,
      FALSE,       TRUE,    "30-44",       8L,
      FALSE,       TRUE,      "0-2",       1L,
      TRUE,       TRUE,    "15-29",      20L,
      FALSE,       TRUE,     "3-14",       8L,
      FALSE,      FALSE,      "45+",      20L,
      FALSE,       TRUE,    "15-29",      15L,
      FALSE,       TRUE,    "30-44",      25L,
      FALSE,      FALSE,    "15-29",       5L,
      FALSE,      FALSE,     "3-14",       2L,
      FALSE,      FALSE,      "0-2",      22L,
      TRUE,      FALSE,     "3-14",       1L,
      FALSE,      FALSE,      "45+",       3L,
      FALSE,       TRUE,      "45+",      29L,
      TRUE,       TRUE,      "45+",      12L,
      TRUE,      FALSE,      "45+",      23L,
      FALSE,      FALSE,    "15-29",      20L,
      FALSE,       TRUE,      "45+",       3L,
      FALSE,       TRUE,      "45+",      14L,
      FALSE,       TRUE,    "15-29",      10L,
      FALSE,      FALSE,      "45+",      16L,
      FALSE,       TRUE,    "15-29",       3L,
      TRUE,      FALSE,      "45+",       9L,
      FALSE,       TRUE,      "45+",       5L,
      FALSE,       TRUE,    "15-29",      10L,
      FALSE,       TRUE,      "45+",      20L,
      FALSE,      FALSE,    "15-29",       1L,
      FALSE,      FALSE,    "30-44",      10L,
      TRUE,       TRUE,    "15-29",      18L,
      FALSE,       TRUE,    "15-29",      20L,
      FALSE,      FALSE,      "0-2",      25L,
      FALSE,      FALSE,      "45+",      14L,
      FALSE,       TRUE,      "45+",      16L,
      FALSE,      FALSE,     "3-14",      27L,
      FALSE,      FALSE,      "45+",      15L,
      TRUE,      FALSE,     "3-14",      25L,
      TRUE,      FALSE,    "15-29",       1L,
      TRUE,       TRUE,      "0-2",       2L,
      FALSE,      FALSE,      "0-2",      19L,
      FALSE,       TRUE,    "15-29",      15L,
      FALSE,       TRUE,    "30-44",      18L,
      FALSE,       TRUE,      "45+",      18L,
      TRUE,       TRUE,      "45+",      16L,
      FALSE,      FALSE,    "15-29",      18L,
      FALSE,      FALSE,      "0-2",       6L,
      FALSE,       TRUE,    "30-44",      12L,
      FALSE,      FALSE,     "3-14",      29L,
      FALSE,      FALSE,    "15-29",       1L,
      FALSE,      FALSE,    "30-44",      16L,
      FALSE,      FALSE,      "0-2",      30L,
      TRUE,       TRUE,    "30-44",      23L,
      TRUE,       TRUE,    "15-29",      12L,
      TRUE,      FALSE,      "45+",      24L,
      FALSE,      FALSE,      "45+",       7L,
      FALSE,       TRUE,    "30-44",      28L,
      TRUE,      FALSE,    "30-44",       9L,
      FALSE,       TRUE,    "30-44",       8L,
      FALSE,       TRUE,      "45+",      14L,
      FALSE,      FALSE,      "45+",      25L,
      FALSE,       TRUE,    "30-44",       9L,
      TRUE,      FALSE,    "30-44",      26L,
      FALSE,      FALSE,      "45+",       8L,
      FALSE,      FALSE,    "15-29",       8L,
      TRUE,      FALSE,      "45+",      18L,
      TRUE,      FALSE,    "15-29",       8L,
      FALSE,      FALSE,     "3-14",      23L,
      TRUE,      FALSE,     "3-14",      19L,
      FALSE,       TRUE,    "15-29",       1L,
      FALSE,      FALSE,      "0-2",      17L,
      FALSE,       TRUE,     "3-14",       2L,
      FALSE,       TRUE,     "3-14",      18L,
      FALSE,      FALSE,     "3-14",       8L,
      FALSE,       TRUE,    "30-44",      19L,
      TRUE,       TRUE,      "0-2",       6L,
      FALSE,       TRUE,    "30-44",      13L,
      TRUE,       TRUE,    "15-29",      16L,
      FALSE,      FALSE,      "0-2",      25L,
      FALSE,       TRUE,     "3-14",      28L,
      TRUE,      FALSE,    "15-29",      12L,
      FALSE,      FALSE,      "45+",      24L,
      FALSE,      FALSE,     "3-14",       3L,
      TRUE,      FALSE,      "45+",       5L,
      FALSE,      FALSE,      "45+",      15L,
      FALSE,      FALSE,      "45+",       3L,
      FALSE,      FALSE,    "15-29",      20L,
      FALSE,      FALSE,    "15-29",      23L,
      FALSE,       TRUE,    "30-44",       1L,
      TRUE,      FALSE,      "45+",      12L,
      TRUE,       TRUE,    "15-29",      13L,
      TRUE,       TRUE,     "3-14",      21L,
      FALSE,      FALSE,      "45+",      22L,
      TRUE,      FALSE,      "0-2",      23L,
      TRUE,       TRUE,      "45+",      12L,
      FALSE,       TRUE,    "15-29",      16L,
      FALSE,       TRUE,     "3-14",      24L,
      TRUE,      FALSE,    "30-44",      15L,
      FALSE,       TRUE,    "15-29",       4L,
      TRUE,       TRUE,      "45+",      11L,
      FALSE,       TRUE,    "15-29",      16L,
      FALSE,       TRUE,      "45+",       6L,
      FALSE,       TRUE,    "15-29",      17L,
      FALSE,       TRUE,      "45+",      10L,
      FALSE,      FALSE,      "45+",      11L,
      FALSE,      FALSE,    "30-44",       6L,
      TRUE,       TRUE,    "30-44",       7L,
      TRUE,      FALSE,      "45+",       8L,
      TRUE,      FALSE,    "30-44",      29L,
      FALSE,      FALSE,      "45+",      29L,
      TRUE,       TRUE,      "45+",      22L,
      TRUE,      FALSE,      "0-2",      18L,
      TRUE,       TRUE,      "45+",       2L,
      FALSE,       TRUE,    "30-44",      12L,
      FALSE,      FALSE,      "45+",      17L,
      FALSE,       TRUE,      "45+",      25L,
      FALSE,      FALSE,    "15-29",       5L,
      FALSE,       TRUE,     "3-14",      25L,
      FALSE,       TRUE,    "30-44",      29L,
      FALSE,       TRUE,    "30-44",      27L,
      FALSE,       TRUE,     "3-14",      27L,
      FALSE,      FALSE,      "45+",      12L,
      TRUE,       TRUE,      "45+",       1L,
      TRUE,       TRUE,     "3-14",      30L,
      FALSE,       TRUE,    "15-29",      25L,
      FALSE,      FALSE,     "3-14",      11L,
      TRUE,      FALSE,    "15-29",      13L,
      FALSE,       TRUE,      "45+",      24L,
      FALSE,      FALSE,    "15-29",       5L,
      FALSE,       TRUE,     "3-14",      24L,
      FALSE,      FALSE,    "30-44",       8L,
      FALSE,      FALSE,     "3-14",      11L,
      FALSE,       TRUE,    "15-29",      17L,
      FALSE,      FALSE,    "15-29",      17L,
      TRUE,       TRUE,    "30-44",      11L,
      FALSE,      FALSE,      "45+",      20L,
      FALSE,       TRUE,      "0-2",      11L,
      TRUE,       TRUE,     "3-14",       9L,
      FALSE,       TRUE,      "0-2",       7L,
      TRUE,       TRUE,      "45+",       7L,
      TRUE,      FALSE,      "45+",      19L,
      TRUE,      FALSE,    "30-44",      25L,
      FALSE,      FALSE,    "15-29",       3L,
      FALSE,      FALSE,     "3-14",      24L,
      FALSE,       TRUE,      "45+",      29L,
      FALSE,      FALSE,    "15-29",      29L,
      TRUE,      FALSE,    "30-44",      13L,
      FALSE,      FALSE,     "3-14",      15L,
      FALSE,      FALSE,    "15-29",       7L,
      TRUE,       TRUE,      "45+",      23L,
      TRUE,       TRUE,     "3-14",       1L,
      FALSE,      FALSE,      "0-2",      27L,
      TRUE,      FALSE,      "0-2",      20L,
      FALSE,       TRUE,    "15-29",      22L,
      TRUE,       TRUE,      "45+",       7L,
      FALSE,       TRUE,    "30-44",      15L,
      FALSE,      FALSE,      "0-2",      15L,
      FALSE,      FALSE,    "15-29",      29L,
      TRUE,      FALSE,      "45+",      21L,
      FALSE,       TRUE,     "3-14",       1L
    )
    
    el_tablo <- tbl_cmh_internal(linelist_cleaned, 
                     DIED, 
                     fever_bin, 
                     age_group, 
                     measure = "OR")
    
    add_crosstabs(el_tablo)

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

Successfully merging this pull request may close these issues.

1 participant