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

Tableby: labels not showing when non-default test is specified #220

Closed
scheidec opened this issue Jun 11, 2019 · 3 comments
Closed

Tableby: labels not showing when non-default test is specified #220

scheidec opened this issue Jun 11, 2019 · 3 comments

Comments

@scheidec
Copy link

scheidec commented Jun 11, 2019

If labels are specified in summary(labelTranslations = ...), but a non-default test is used, the label should properly render in the output:

library(tidyverse)
library(arsenal)

data(mockstudy)

mockstudy <- mockstudy %>% 
  as_tibble() %>% 
  mutate(race = ifelse(race == "Caucasian", "White", "Other"))

controls <- tableby.control(
  cat.stats        = c("countpct"),
  numeric.stats    = c("meansd"),
  total            = FALSE,
  cat.simplify     = TRUE,
  numeric.simplify = TRUE,
  digits           = 1
)

labels <- list(
  ast      = "AST",
  alk.phos = "Alkaline Phosphate",
  fu.time  = "Follow-up Time",
  sex      = "Sex (Female)",
  race     = "Race (White)"
)
  
mockstudy %>% 
  tableby(arm ~ age + ast + alk.phos + kwt(fu.time, "medianq1q3") + sex + fe(race),
          data    = .,
          control = controls) %>%
  summary(labelTranslations = labels,
          term.name         = "Variable",
          text              = TRUE) %>% 
  as_tibble()
#> # A tibble: 6 x 5
#>   Variable   `A: IFL (N=428)`  `F: FOLFOX (N=69… `G: IROX (N=380… `p value`
#>   <chr>      <chr>             <chr>             <chr>            <chr>    
#> 1 Age in Ye… 59.7 (11.4)       60.3 (11.6)       59.8 (11.5)      0.614    
#> 2 AST        37.3 (28.0)       35.2 (26.7)       35.7 (25.8)      0.507    
#> 3 Alkaline … 175.6 (128.6)     162.0 (122.0)     173.5 (138.6)    0.226    
#> 4 fu.time    446.5 (255.5, 72… 601.0 (345.0, 10… 515.5 (306.5, 8… < 0.001  
#> 5 Sex (Fema… 151 (35.3%)       280 (40.5%)       152 (40.0%)      0.190    
#> 6 race       371 (86.7%)       586 (85.5%)       331 (87.3%)      0.708

mockstudy %>% 
  tableby(arm ~ age + ast + alk.phos + kwt(fu.time, "medianq1q3") + sex + fe(race),
          data    = .,
          control = controls) %>% 
  as_tibble() %>% 
  select(variable, term, label)
#> # A tibble: 6 x 3
#>   variable term                           label       
#>   <chr>    <chr>                          <chr>       
#> 1 age      age                            Age in Years
#> 2 ast      ast                            ast         
#> 3 alk.phos alk.phos                       alk.phos    
#> 4 fu.time  "kwt(fu.time, \"medianq1q3\")" fu.time     
#> 5 sex      sex                            sex         
#> 6 race     fe(race)                       race

Created on 2019-06-11 by the reprex package (v0.3.0)

In this example, the labels for fu.time and race are not showing correctly. Under the hood, it looks like this is caused by the term being modified, as compared to the original variable name, so the label is not mapping as expected.

@scheidec scheidec changed the title Tableby: override labels when non-default test is specified Tableby: labels not showing when non-default test is specified Jun 11, 2019
@eheinzen
Copy link
Collaborator

For reasons that I'm having difficulty vocalizing, I'm not sure that I should fix this. It's not a hard fix (only 5 lines or so), but I'm not sure it's in tableby's best interest. I'm still thinking about this.

In the meantime, can you do something like this?

mockstudy %>% 
    set_labels(labels) %>% 
    tableby(arm ~ age + ast + alk.phos + kwt(fu.time, "medianq1q3") + sex + fe(race),
            data = .,
            control = controls) %>%
    summary(term.name = "Variable",
            text = TRUE) %>% 
    as_tibble()
#> # A tibble: 6 x 5
#>   Variable           `A: IFL (N=428)`     `F: FOLFOX (N=691)`   `G: IROX (N=380)`    `p value`
#>   <chr>              <chr>                <chr>                 <chr>                <chr>    
#> 1 Age in Years       59.7 (11.4)          60.3 (11.6)           59.8 (11.5)          0.614    
#> 2 AST                37.3 (28.0)          35.2 (26.7)           35.7 (25.8)          0.507    
#> 3 Alkaline Phosphate 175.6 (128.6)        162.0 (122.0)         173.5 (138.6)        0.226    
#> 4 Follow-up Time     446.5 (255.5, 724.2) 601.0 (345.0, 1046.0) 515.5 (306.5, 807.0) < 0.001  
#> 5 Sex (Female)       151 (35.3%)          280 (40.5%)           152 (40.0%)          0.190    
#> 6 Race (White)       371 (86.7%)          586 (85.5%)           331 (87.3%)          0.708    

@scheidec
Copy link
Author

Yes that works. Is there any situation where one would require using the labelTranslations argument over the arsenal::set_labels function?

@eheinzen
Copy link
Collaborator

Good question. There might be. You could always do something like this:

labels[["fe(race)"]] <- "Race (White)"
mockstudy %>% 
     tableby(arm ~ age + ast + alk.phos + kwt(fu.time, "medianq1q3") + sex + fe(race),
            data    = .,
            control = controls) %>%
    summary(labelTranslations = labels,
            term.name         = "Variable",
            text              = TRUE) %>% 
    as_tibble()
#> # A tibble: 6 x 5
#>   Variable           `A: IFL (N=428)`     `F: FOLFOX (N=691)`   `G: IROX (N=380)`    `p value`
#>   <chr>              <chr>                <chr>                 <chr>                <chr>    
#> 1 Age in Years       59.7 (11.4)          60.3 (11.6)           59.8 (11.5)          0.614    
#> 2 AST                37.3 (28.0)          35.2 (26.7)           35.7 (25.8)          0.507    
#> 3 Alkaline Phosphate 175.6 (128.6)        162.0 (122.0)         173.5 (138.6)        0.226    
#> 4 fu.time            446.5 (255.5, 724.2) 601.0 (345.0, 1046.0) 515.5 (306.5, 807.0) < 0.001  
#> 5 Sex (Female)       151 (35.3%)          280 (40.5%)           152 (40.0%)          0.190    
#> 6 Race (White)       371 (86.7%)          586 (85.5%)           331 (87.3%)          0.708    

but it's kind of annoying, especially when you also specify custom digits, statistics, etc.

I thought about this some more last night, and convinced myself that it'd be a good idea to fix. Thanks for the issue!

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

No branches or pull requests

2 participants