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

Using add_overall() before add_n() in tbl_summary() doubles n #1126

Closed
brachem-christian opened this issue Jan 27, 2022 · 1 comment · Fixed by #1128
Closed

Using add_overall() before add_n() in tbl_summary() doubles n #1126

brachem-christian opened this issue Jan 27, 2022 · 1 comment · Fixed by #1128

Comments

@brachem-christian
Copy link

Hello,

thanks for the awesome package!

When adding both add_overall() and add_n() to a tbl_summary() the results change depending on the order. When add_overall() is used first, the N are doubled.

Reprex:

Doubled N:

library(gtsummary)

tbl_summary(iris, by = Species) |> 
  add_overall() |> 
  add_n()
Characteristic N Overall, N = 1501 setosa, N = 501 versicolor, N = 501 virginica, N = 501
Sepal.Length 300 5.80 (5.10, 6.40) 5.00 (4.80, 5.20) 5.90 (5.60, 6.30) 6.50 (6.23, 6.90)
Sepal.Width 300 3.00 (2.80, 3.30) 3.40 (3.20, 3.68) 2.80 (2.52, 3.00) 3.00 (2.80, 3.18)
Petal.Length 300 4.35 (1.60, 5.10) 1.50 (1.40, 1.58) 4.35 (4.00, 4.60) 5.55 (5.10, 5.88)
Petal.Width 300 1.30 (0.30, 1.80) 0.20 (0.20, 0.30) 1.30 (1.20, 1.50) 2.00 (1.80, 2.30)

1

      Median (IQR)
      <br />
    </p>
  </td>
</tr>

Correct N:

tbl_summary(iris, by = Species) |> 
  add_n() |> 
  add_overall() 
Characteristic N Overall, N = 1501 setosa, N = 501 versicolor, N = 501 virginica, N = 501
Sepal.Length 150 5.80 (5.10, 6.40) 5.00 (4.80, 5.20) 5.90 (5.60, 6.30) 6.50 (6.23, 6.90)
Sepal.Width 150 3.00 (2.80, 3.30) 3.40 (3.20, 3.68) 2.80 (2.52, 3.00) 3.00 (2.80, 3.18)
Petal.Length 150 4.35 (1.60, 5.10) 1.50 (1.40, 1.58) 4.35 (4.00, 4.60) 5.55 (5.10, 5.88)
Petal.Width 150 1.30 (0.30, 1.80) 0.20 (0.20, 0.30) 1.30 (1.20, 1.50) 2.00 (1.80, 2.30)

1

      Median (IQR)
      <br />
    </p>
  </td>
</tr>

Created on 2022-01-27 by the reprex package (v2.0.1)

I deleted the style portion the reprex package created because it seems irrelevant for this example.

@ddsjoberg
Copy link
Owner

@brachem-christian thank you so much for the bug report and the reprex! I know exactly the update I made that results in this bug and will patch ASAP. Much appreciated!

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 a pull request may close this issue.

2 participants