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

Feature request: Show only N and Event N columns once for multivariable regression models #2171

Open
dchiu911 opened this issue Feb 25, 2025 · 2 comments

Comments

@dchiu911
Copy link

Is your feature request related to a problem? Please describe.
It would be nice if there was a way to only show the N and Event N counts once for an entire multivariable model in tbl_regression(), since they would be the same for every variable.

Describe the solution you'd like
Would it possible to have the values merged with the headers, e.g. N=183, Event N=58 and not have the counts repeated in each label's row?

library(gtsummary)
glm(response ~ age + grade, trial, family = binomial) |>
  tbl_regression(exponentiate = TRUE) |>
  add_nevent() |> 
  add_n()
Characteristic N Event N OR1 95% CI1 p-value
Age 183 58 1.02 1.00, 1.04 0.10
Grade 183 58


    I


    II

0.85 0.39, 1.85 0.7
    III

1.01 0.47, 2.16 >0.9
1 OR = Odds Ratio, CI = Confidence Interval

Created on 2025-02-25 with reprex v2.1.1

Describe alternatives you've considered
I can modify the headers but cannot figure out how to remove the values for each label using modify_table_body():

library(gtsummary)
glm(response ~ age + grade, trial, family = binomial) |>
  tbl_regression(exponentiate = TRUE) |>
  add_nevent() |>
  add_n() |>
  modify_header(stat_n = "**N={N}**", stat_nevent = "**Event N={N_event}**")
Characteristic N=183 Event N=58 OR1 95% CI1 p-value
Age 183 58 1.02 1.00, 1.04 0.10
Grade 183 58


    I


    II

0.85 0.39, 1.85 0.7
    III

1.01 0.47, 2.16 >0.9
1 OR = Odds Ratio, CI = Confidence Interval

Created on 2025-02-25 with reprex v2.1.1
Additional context
Add any other context or screenshots about the feature request here.

@dchiu911
Copy link
Author

I suppose this works but I was wondering if there would be value to allowing the header space to show this information

glm(response ~ age + grade, trial, family = binomial) |>
  tbl_regression(exponentiate = TRUE) |>
  modify_spanning_header(c(estimate, p.value) ~ "**N={N}, Event N={N_event}**")

@ddsjoberg
Copy link
Owner

ddsjoberg commented Feb 25, 2025

Hi @dchiu911 , thanks for the post!

I don't think I am 100% sure what you're looking for. From what I gather, I think this would work, right? If not, where do you see the header with Ns appearing?

library(gtsummary)

glm(response ~ age + grade, trial, family = binomial) |>
  tbl_regression(exponentiate = TRUE) |>
  modify_header(label = "**N={N}**, **Event N={N_event}**") |> 
  as_kable()
N=183, Event N=58 OR 95% CI p-value
Age 1.02 1.00, 1.04 0.10
Grade
I
II 0.85 0.39, 1.85 0.7
III 1.01 0.47, 2.16 >0.9

Created on 2025-02-25 with reprex v2.1.1

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

No branches or pull requests

2 participants