ddsjoberg / gtsummary

Presentation-Ready Data Summary and Analytic Result Tables
http://www.danieldsjoberg.com/gtsummary
Other
1.05k stars 122 forks source link

tbl_svysummary "unweighted" summary statistics not working #874

Closed gjones1219 closed 3 years ago

gjones1219 commented 3 years ago

Hello! I am writing to report that when I try to use tbl_summary to calculate unweighted statistics (i.e. {n_unweighted}) it does not work and it only returns the weighted values. Can you please address? Thank you.

Grant

ddsjoberg commented 3 years ago

Thanks Grant. Can you please give a reproducible example?

ddsjoberg commented 3 years ago

Please feel free to re-open when you've prepared a reproducible example

library(gtsummary)
#> #BlackLivesMatter

survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) %>%
  tbl_svysummary(
    by = Survived, 
    include = c(Class, Survived),
    statistic = all_categorical() ~ "{n_unweighted} /  {N_unweighted}"
  ) %>%
  as_kable() # converting to kable to display on GH
Characteristic No, N = 1,490 Yes, N = 711
Class
1st 4 / 16 4 / 16
2nd 4 / 16 4 / 16
3rd 4 / 16 4 / 16
Crew 4 / 16 4 / 16

Created on 2021-04-30 by the reprex package (v2.0.0)