Search code examples
rsurveygtsummary

Using {gtsummary} to display confidence intervals for survey.design object?


{gtsummary} has the tbl_svysummary() function for producing summary statistics tables from survey.design objects created by the {survey} package. The {gtsummary} website provides an example of how to add confidence intervals for tbl_summary(), by defining custom functions for calculating CIs which are then passed to the statistics = argument in tbl_summary().

However, the documentation for tbl_svysummary() noted that "Unlike tbl_summary(), it is not possible to pass a custom function." I'm using a survey.design object since I'm applying weighting to my data, but I really like the output of {gtsummary}, so it would be great if I could find a way to add confidence intervals as I need to show these for reporting.

Any suggestions on how to achieve this, or is it not possible?


Solution

  • I am sorry to report that it is currently not possible. The way one would go about it using the add_stat() function (example here How to generate effect size [90%CI] in the summary table using R package “gtsummary”?). But that function has not yet been generalized to work with tbl_svysummary() objects.

    I had never considered generalizing it until now, so thank you very much for your question. I opened a GitHub Issue to track implementation progress. You can subscribe to the issue to be notified when it is complete. https://github.com/ddsjoberg/gtsummary/issues/688

    Happy Programming!