Skip to content

Add tbl_proportion() and proportion comparison verbs - #304

Open
Melkiades wants to merge 5 commits into
mainfrom
303_add_tbl_proportion
Open

Add tbl_proportion() and proportion comparison verbs#304
Melkiades wants to merge 5 commits into
mainfrom
303_add_tbl_proportion

Conversation

@Melkiades

Copy link
Copy Markdown
Contributor

Adds a reusable stats layer for binary/response summary tables (RSPT01), so templates hold only cosmetics.

Three verbs, statistics and tabulation separated from wording:

CI method and level match cardx::ard_categorical_ci(); the difference CI and p-value are verified against prop.test(), and the odds ratio against a manual 2x2.

Fixes #303

tbl_proportion() summarizes a binary or multinomial variable as
proportions with confidence intervals, with a selectable CI method and
conf.level. add_proportion_difference() appends the difference in rates,
its CI, and a p-value; add_proportion_odds_ratio() appends an odds ratio.
Both comparison verbs support stratified (Cochran-Mantel-Haenszel)
analysis via strata.

Fixes #303
@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Unit Tests Summary

  1 files  324 suites   1m 50s ⏱️
324 tests 324 ✅ 0 💤 0 ❌
938 runs  938 ✅ 0 💤 0 ❌

Results for commit 4324432.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
tbl_proportion 👶 $+0.00$ $+5$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
tbl_baseline_chg 💚 $12.68$ $-1.34$ tbl_baseline_chg_works
tbl_hierarchical_rate_and_count 💚 $9.87$ $-1.26$ tbl_hierarchical_rate_and_count_works
tbl_hierarchical_rate_by_grade 💚 $11.22$ $-1.78$ tbl_hierarchical_rate_by_grade_works
tbl_proportion 👶 $+0.00$ add_proportion_difference_adds_the_comparison_block
tbl_proportion 👶 $+0.00$ add_proportion_difference_supports_fisher_and_cmh
tbl_proportion 👶 $+0.00$ add_proportion_odds_ratio_adds_an_odds_ratio_row
tbl_proportion 👶 $+0.00$ informative_errors_are_raised
tbl_proportion 👶 $+0.00$ odds_ratio_matches_the_2x2_hand_calculation
tbl_proportion 👶 $+0.00$ stratified_odds_ratio_uses_the_CMH_common_odds_ratio
tbl_proportion 👶 $+3.06$ tbl_proportion_binary_summary_works
tbl_proportion 👶 $+0.00$ tbl_proportion_multinomial_summary_preserves_factor_level_order
tbl_proportion 👶 $+0.01$ tbl_proportion_supports_different_CI_methods_and_conf.level
tbl_proportion 👶 $+0.00$ tbl_proportion_works_without_a_by_variable
tbl_rmpt 💚 $6.70$ $-2.01$ tbl_rmpt_works_with_default_parameters_Example_1_
tbl_shift 💚 $3.86$ $-1.81$ tbl_shift_strata_location_
tbl_survfit_quantiles 💔 $0.18$ $+1.57$ tbl_survfit_quantiles_works
tbl_survfit_times 💚 $1.92$ $-1.69$ tbl_survfit_times_works
tbl_with_pools 💔 $5.75$ $+1.17$ tbl_with_pools_validates_inputs_correctly

Results for commit f61892d

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

badge

Code Coverage Summary

Filename                                 Stmts    Miss  Cover    Missing
-------------------------------------  -------  ------  -------  ------------------------------------------------------------------------------------------------
R/add_blank_rows.R                          63       0  100.00%
R/add_difference_row.R                     101       0  100.00%
R/add_forest_utils.R                        97      10  89.69%   76-79, 94-100
R/add_forest.R                             139       0  100.00%
R/add_hierarchical_count_row.R              33       0  100.00%
R/add_label_column.R                        26       0  100.00%
R/add_proportion_difference.R              150       1  99.33%   245
R/add_proportion_odds_ratio.R               57       0  100.00%
R/adjust_stat_columns_wrap.R                29       1  96.55%   59
R/annotate_gg_km.R                         141       0  100.00%
R/annotate_gg_pkc.R                        100       0  100.00%
R/annotate_gg.R                             94       0  100.00%
R/ard_tabulate_abnormal_by_baseline.R       65       0  100.00%
R/crane-package.R                            2       2  0.00%    26-27
R/deprecated.R                              21      21  0.00%    18-54
R/df_add_poolings.R                         41       0  100.00%
R/get_cox_pairwise_df.R                    163       0  100.00%
R/gg_km_utils.R                             39      14  64.10%   20-37
R/gg_km.R                                  143      37  74.13%   55-58, 75, 102, 176-181, 184-187, 197-199, 204-205, 239-241, 248-251, 255, 266-270, 283, 285-287
R/gg_lineplot.R                            121       0  100.00%
R/gg_mmrm_lineplot.R                       102       1  99.02%   106
R/gg_pkc_lineplot.R                         98       0  100.00%
R/gg_utils.R                               222       0  100.00%
R/label_roche.R                             72       0  100.00%
R/modify_header_rm_md.R                     18       2  88.89%   35-36
R/modify_split_caption.R                    26       0  100.00%
R/modify_zero_recode.R                      20       1  95.00%   64
R/pk_helper.R                              499       0  100.00%
R/reverse_difference_ci.R                   33       0  100.00%
R/tbl_baseline_chg.R                       188       0  100.00%
R/tbl_coxph.R                               90       1  98.89%   229
R/tbl_hierarchical_incidence_rate.R        291       4  98.63%   430-433
R/tbl_hierarchical_rate_and_count.R        339      13  96.17%   343, 425, 446-456
R/tbl_hierarchical_rate_by_grade.R         317       3  99.05%   169-171
R/tbl_listing.R                             36       0  100.00%
R/tbl_mmrm.R                               344       6  98.26%   452-456, 548
R/tbl_null_report.R                         10       0  100.00%
R/tbl_proportion.R                         141      13  90.78%   100-103, 107-111, 114-117
R/tbl_rmpt.R                               157      12  92.36%   299-304, 316-321
R/tbl_roche_subgroups.R                    157       0  100.00%
R/tbl_roche_summary.R                       64       0  100.00%
R/tbl_shift.R                              111       0  100.00%
R/tbl_survfit_quantiles.R                  154       0  100.00%
R/tbl_survfit_times.R                       92       0  100.00%
R/tbl_with_pools.R                          79       1  98.73%   317
R/theme_gtsummary_roche.R                   87       1  98.85%   61
R/utils.R                                   42       0  100.00%
TOTAL                                     5414     144  97.34%

Diff against main

Filename                         Stmts    Miss  Cover
-----------------------------  -------  ------  --------
R/add_proportion_difference.R     +150      +1  +99.33%
R/add_proportion_odds_ratio.R      +57       0  +100.00%
R/tbl_proportion.R                +141     +13  +90.78%
TOTAL                             +348     +14  -0.09%

Results for commit: 4324432

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Melkiades and others added 2 commits August 18, 2026 15:18
The difference confidence interval keeps its continuity correction, but
the chi-squared p-value now has its own test_correct flag (default FALSE)
so it matches the NEST 1.0 catalog (RSPT01), where the interval uses the
correction and the test does not.
@wzfrank wzfrank assigned wzfrank and unassigned wzfrank Sep 3, 2026
@wzfrank
wzfrank self-requested a review September 3, 2026 18:55

@wzfrank wzfrank left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add an argument to customize Wald, with continuity correction.

Melkiades and others added 2 commits September 4, 2026 16:42
The 'cc' methods (waldcc, wilsoncc, strat_wilsoncc) apply a continuity
correction, so the default CI row label now reads 'with continuity
correction' instead of the abbreviated 'with correction'. The label
remains overridable via ci_label. Addresses PR review feedback.
@Melkiades

Copy link
Copy Markdown
Contributor Author

Addressed in 4324432c. The default CI row label for the continuity-corrected methods (waldcc, wilsoncc, strat_wilsoncc) now reads "Wald, with continuity correction" (previously "Wald, with correction"), matching the statistical meaning of the cc suffix. The label was already overridable via the ci_label argument on both tbl_proportion() and add_proportion_difference(); this change corrects the default wording. Docs, snapshot, and NEWS updated.

@wzfrank wzfrank left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I think this looks good now!

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 this pull request may close these issues.

Add tbl_proportion() and proportion comparison verbs

2 participants