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

Age groups are not mutually exclusive and our results do not match Table 2 Spec #162

Open
ddsjoberg opened this issue Nov 8, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@ddsjoberg
Copy link
Collaborator

ddsjoberg commented Nov 8, 2023

Table 2 is the first table most visitors to the site will take a look at. In the data prep section we have this code:

# Pre-Processing - Add any variables needed in your table to df
adsl <- adsl %>%
  dplyr::mutate(AGEGR1 = as.factor(dplyr::case_when(
    AGE >= 17 & AGE < 65 ~ ">=17 to <65",
    AGE >= 65 ~ ">=65",
    AGE >= 65 & AGE < 75 ~ ">=65 to <75",
    AGE >= 75 ~ ">=75"
  )))

This variable we're creating is a bit confusing because these categories are not mutually exclusive. For example, one patient who is 70 years old would fall into ">=65" and ">=65 to <75". But this can't be summarized from a single variable, but the code make it look like we're trying to do so.

I see from the spec, that these non-exclusive groups appear. But to match the spec, we'd need to update our summary code:
image

I would expect we'd need something more like this:

library(gtsummary)

adsl <- 
  scda::synthetic_cdisc_dataset("rcd_2022_10_13", "adsl") %>%
  mutate(
    AGEGR1 = dplyr::case_when(
      AGE >= 17 & AGE < 65 ~ ">=17 to <65",
      AGE >= 65 ~ ">=65"
    ) %>%
      formatters::with_label("Age Group, years"),
    AGEGR1_v2 = (AGE >= 65 & AGE < 75) %>% 
      formatters::with_label(">=65 to <75"),
    AGEGRP_v3 = (AGE >= 75) %>% 
      formatters::with_label(">=75")
  )

tbl <-
  tbl_summary(
  adsl, 
  include = c(AGEGR1, AGEGR1_v2, AGEGRP_v3),
  by = ARM
) |> 
  modify_table_styling(
    columns = label, 
    rows = variable %in% c("AGEGR1_v2", "AGEGRP_v3"),
    text_format = "indent"
  )
image

Created on 2023-11-08 with reprex v2.0.2

@ddsjoberg ddsjoberg changed the title How do you want unobserved factor levels? Age groups are not mutually exclusive and our results do not match Table 2 Spec Nov 8, 2023
@edelarua edelarua added the bug Something isn't working label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants