@@ -597,19 +597,20 @@ test_that("pairwise_comparisons_bin testing two groups", {
597597 group_by(group ) %> %
598598 mutate(num_pos = sum(x ), n = n()) %> %
599599 group_by(group ,num_pos , n ) %> %
600- group_modify( ~ wilson_ci(. $ x , .95 )) %> % ungroup() %> %
600+ group_modify( ~ wilson_ci(. $ x , .95 ),
601+ sum(. $ x )) %> % ungroup() %> %
601602 mutate(rr = paste0(num_pos , ' /' , n , ' = ' ,
602603 stat_paste(mean * 100 , lower * 100 , upper * 100 , digits = 1 , suffix = ' %' )))
603604
604605 testing_stats <- bind_cols(
605- testing_stats_pre %> % filter(group == ' a' ) %> % select(Group1 = group , Group1_rr = rr ),
606- testing_stats_pre %> % filter(group == ' b' ) %> % select(Group2 = group , Group2_rr = rr ))
606+ testing_stats_pre %> % filter(group == ' a' ) %> % select(Group1 = group , Group1_n = n , Group1_rr = rr ),
607+ testing_stats_pre %> % filter(group == ' b' ) %> % select(Group2 = group , Group2_n = n , Group2_rr = rr ))
607608
608609
609610 # testing multiple methods
610611 test_pasting <- paste_tbl_grp(data = testing_stats )
611612
612- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
613+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
613614
614615 lapply(c(" barnard" , " fisher" , " chi.sq" ),
615616 function (method_in ){
@@ -629,18 +630,20 @@ test_that("pairwise_comparisons_bin testing two groups", {
629630 group_by(group ) %> %
630631 mutate(num_pos = sum(x ), n = n()) %> %
631632 group_by(group ,num_pos , n ) %> %
632- group_modify( ~ wilson_ci(. $ x , .95 )) %> % ungroup() %> %
633+ group_modify( ~ wilson_ci(. $ x , .95 ),
634+ sum(. $ x )) %> %
635+ ungroup() %> %
633636 mutate(rr = paste0(num_pos , ' /' , n , ' = ' ,
634637 stat_paste(mean * 100 , lower * 100 , upper * 100 , digits = 3 , suffix = ' %' )))
635638
636639 testing_stats_3digits <- bind_cols(
637640 testing_stats_pre_3digits %> %
638641 filter(group == ' a' ) %> %
639- select(Group1 = group , Group1_rr = rr ), testing_stats_pre_3digits %> %
640- filter(group == ' b' ) %> % select(Group2 = group , Group2_rr = rr ))
642+ select(Group1 = group , Group1_n = n , Group1_rr = rr ), testing_stats_pre_3digits %> %
643+ filter(group == ' b' ) %> % select(Group2 = group , Group2_n = n , Group2_rr = rr ))
641644
642645 test_pasting <- paste_tbl_grp(data = testing_stats_3digits )
643- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
646+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
644647 testing_results <- data.frame (test_pasting ,
645648 ResponseTest = two_samp_bin_test(x = x , y = group ),
646649 PerfectSeparation = ifelse(diff(testing_stats_pre_3digits $ mean ) == 1 ,
@@ -652,7 +655,7 @@ test_that("pairwise_comparisons_bin testing two groups", {
652655 # One-sided test comparison
653656 test_pasting <- paste_tbl_grp(data = testing_stats , alternative = ' less' )
654657
655- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
658+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
656659
657660 testing_results <- data.frame (test_pasting ,
658661 # Need reverse testing direction
@@ -667,7 +670,7 @@ test_that("pairwise_comparisons_bin testing two groups", {
667670 # sorted group greater than comparison
668671 test_pasting <- paste_tbl_grp(data = testing_stats , alternative = ' greater' ,
669672 first_name = ' Group2' , second_name = ' Group1' )
670- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
673+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
671674 testing_results <- data.frame (
672675 test_pasting ,
673676 # Need reverse testing direction
@@ -682,7 +685,7 @@ test_that("pairwise_comparisons_bin testing two groups", {
682685
683686 # High number needed for testing
684687 test_pasting <- paste_tbl_grp(data = testing_stats )
685- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
688+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
686689 testing_results <- data.frame (
687690 test_pasting ,
688691 ResponseTest = NA_integer_ ,
@@ -701,7 +704,8 @@ test_that("pairwise_comparisons_bin testing two groups", {
701704 group_by(group ) %> %
702705 mutate(num_pos = sum(x ), n = n()) %> %
703706 group_by(group ,num_pos , n ) %> %
704- group_modify( ~ wilson_ci(. $ x , .95 )) %> % ungroup() %> %
707+ group_modify( ~ wilson_ci(. $ x , .95 ),
708+ sum(. $ x )) %> % ungroup() %> %
705709 mutate(rr = paste0(num_pos , ' /' , n , ' = ' , stat_paste(mean * 100 ,
706710 lower * 100 ,
707711 upper * 100 ,
@@ -710,9 +714,10 @@ test_that("pairwise_comparisons_bin testing two groups", {
710714
711715 paired_stats <- bind_cols(paired_stats_pre %> %
712716 filter(group == ' a' ) %> %
713- select(Group1 = group , Group1_rr = rr ), paired_stats_pre %> %
717+ select(Group1 = group , Group1_n = n , Group1_rr = rr ),
718+ paired_stats_pre %> %
714719 filter(group == ' b' ) %> %
715- select(Group2 = group , Group2_rr = rr ))
720+ select(Group2 = group , Group2_n = n , Group2_rr = rr ))
716721
717722
718723 test_pasting <- paste_tbl_grp(data = paired_stats )
@@ -722,8 +727,8 @@ test_that("pairwise_comparisons_bin testing two groups", {
722727 second_name = " Group1" )
723728 expect_false(identical(test_pasting , test_pasting_rev ))
724729
725- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
726- names(test_pasting_rev ) <- c(' Comparison' , ' ResponseStats' )
730+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
731+ names(test_pasting_rev ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
727732
728733 testing_results <- data.frame (test_pasting ,
729734 ResponseTest = two_samp_bin_test(x = x , y = group , method = ' mcnemar' ),
@@ -759,11 +764,12 @@ test_that("pairwise_test_bin testing 3+ groups", {
759764 ci = wilson_ci(response ),
760765 r1 = sum(response ),
761766 r0 = abs(sum(response - 1 )),
767+ n = n(),
762768 .groups = " keep" ) %> %
763769 pivot_wider(id_cols = c(antigen , visitno ),
764770 names_from = group ,
765771 names_prefix = " grp" ,
766- values_from = c(rfraction , ci , r0 , r1 )) %> %
772+ values_from = c(rfraction , ci , r0 , r1 , n )) %> %
767773 mutate(pval = ifelse(((r0_grp1 == 0 & r0_grp2 == 0 ) | (r1_grp1 == 0 & r1_grp2 == 0 )),
768774 1 ,
769775 as.double(Exact :: exact.test(matrix (c(r1_grp1 ,
@@ -776,6 +782,7 @@ test_that("pairwise_test_bin testing 3+ groups", {
776782 alternative = " two.sided" )$ p.value )),
777783 PerfectSeparation = FALSE ,
778784 Comparison = " 1 vs. 2" ,
785+ SampleSizes = paste0(n_grp1 , " vs. " , n_grp2 ),
779786 ResponseStats = paste0(rfraction_grp1 ,
780787 " = " ,
781788 round_away_0(ci_grp1 $ mean * 100 , 1 , trailing_zeros = TRUE ),
@@ -792,7 +799,7 @@ test_that("pairwise_test_bin testing 3+ groups", {
792799 " %, " ,
793800 round_away_0(ci_grp2 $ upper * 100 , 1 , trailing_zeros = TRUE ),
794801 " %)" )) %> %
795- select(antigen , visitno , Comparison , ResponseStats , ResponseTest = pval , PerfectSeparation )
802+ select(antigen , visitno , Comparison , SampleSizes , ResponseStats , ResponseTest = pval , PerfectSeparation )
796803
797804 function_obj <- exampleData_BAMA %> %
798805 group_by(antigen , visitno ) %> %
0 commit comments