0

I want to output the results of the wonderful gtsummary package for tbl_uvregression by groups.

library(gtsummary)
conflict_prefer("trial", "gtsummary")

trial %>%
  group_by(grade) %>%
  select(response, age) %>%
  tbl_uvregression(
    method = glm,
    y = response,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = ~style_pvalue(.x, digits = 2)
  ) %>%
  add_global_p() %>%  # add global p-value 
  add_nevent() %>%    # add number of events of the outcome
  add_q() %>%         # adjusts global p-values for multiple testing
  bold_p() %>%        # bold p-values under a given threshold (default 0.05)
  bold_p(t = 0.10, q = TRUE) %>% # now bold q-values under the threshold of 0.10
  bold_labels()

This produces an error: Adding missing grouping variables: grade

Can anyone help? Thank you very much

manro
  • 3,529
  • 2
  • 9
  • 22
gideon1321
  • 51
  • 1
  • 5
  • We cannot reproduce your code & error without sample data. Please review what you can & should do in order to provide a [good R reprex](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Maurits Evers Aug 28 '22 at 11:59
  • Thank you Maurits. trial is part of gtsummary. When you load (gtsummary) the trial dataset is available. – gideon1321 Aug 28 '22 at 12:20
  • 1
    @gideon1321 Including `grade` in `group_by` will result in `grade` being carried along even if omitted in `select`...can you clarify what your end result should look like? Did you want 3 tables of models next to each other (one for each grade)? If so, take a look at [this answer](https://stackoverflow.com/a/60959878/3460670) and see if it helps... – Ben Aug 28 '22 at 17:53
  • Dear Ben, thank you. That was almost what i am looking for – gideon1321 Sep 05 '22 at 21:13

0 Answers0