@@ -616,19 +616,19 @@ test_that("pairwise_comparisons_bin testing two groups", {
616616 group_by(group ) | >
617617 mutate(num_pos = sum(x ), n = n()) | >
618618 group_by(group ,num_pos , n ) | >
619- group_modify( ~ wilson_ci(. $ x , .95 )) | > ungroup() | >
619+ group_modify( ~ wilson_ci(. $ x , .95 ),
620+ sum(. $ x )) | > ungroup() | >
620621 mutate(rr = paste0(num_pos , ' /' , n , ' = ' ,
621622 stat_paste(mean * 100 , lower * 100 , upper * 100 , digits = 1 , suffix = ' %' )))
622623
623624 testing_stats <- bind_cols(
624- testing_stats_pre | > filter(group == ' a' ) | > select(Group1 = group , Group1_rr = rr ),
625- testing_stats_pre | > filter(group == ' b' ) | > select(Group2 = group , Group2_rr = rr ))
626-
625+ testing_stats_pre | > filter(group == ' a' ) | > select(Group1 = group , Group1_n = n , Group1_rr = rr ),
626+ testing_stats_pre | > filter(group == ' b' ) | > select(Group2 = group , Group2_n = n , Group2_rr = rr ))
627627
628628 # testing multiple methods
629629 test_pasting <- paste_tbl_grp(data = testing_stats )
630630
631- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
631+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
632632
633633 lapply(c(" barnard" , " fisher" , " chi.sq" ),
634634 function (method_in ){
@@ -648,18 +648,20 @@ test_that("pairwise_comparisons_bin testing two groups", {
648648 group_by(group ) | >
649649 mutate(num_pos = sum(x ), n = n()) | >
650650 group_by(group ,num_pos , n ) | >
651- group_modify( ~ wilson_ci(. $ x , .95 )) | > ungroup() | >
651+ group_modify( ~ wilson_ci(. $ x , .95 ),
652+ sum(. $ x )) | >
653+ ungroup() | >
652654 mutate(rr = paste0(num_pos , ' /' , n , ' = ' ,
653655 stat_paste(mean * 100 , lower * 100 , upper * 100 , digits = 3 , suffix = ' %' )))
654656
655657 testing_stats_3digits <- bind_cols(
656658 testing_stats_pre_3digits | >
657659 filter(group == ' a' ) | >
658- select(Group1 = group , Group1_rr = rr ), testing_stats_pre_3digits | >
659- filter(group == ' b' ) | > select(Group2 = group , Group2_rr = rr ))
660+ select(Group1 = group , Group1_n = n , Group1_rr = rr ), testing_stats_pre_3digits | >
661+ filter(group == ' b' ) | > select(Group2 = group , Group2_n = n , Group2_rr = rr ))
660662
661663 test_pasting <- paste_tbl_grp(data = testing_stats_3digits )
662- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
664+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
663665 testing_results <- data.frame (test_pasting ,
664666 ResponseTest = two_samp_bin_test(x = x , y = group ),
665667 PerfectSeparation = ifelse(diff(testing_stats_pre_3digits $ mean ) == 1 ,
@@ -671,7 +673,7 @@ test_that("pairwise_comparisons_bin testing two groups", {
671673 # One-sided test comparison
672674 test_pasting <- paste_tbl_grp(data = testing_stats , alternative = ' less' )
673675
674- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
676+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
675677
676678 testing_results <- data.frame (test_pasting ,
677679 # Need reverse testing direction
@@ -686,7 +688,7 @@ test_that("pairwise_comparisons_bin testing two groups", {
686688 # sorted group greater than comparison
687689 test_pasting <- paste_tbl_grp(data = testing_stats , alternative = ' greater' ,
688690 first_name = ' Group2' , second_name = ' Group1' )
689- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
691+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
690692 testing_results <- data.frame (
691693 test_pasting ,
692694 # Need reverse testing direction
@@ -701,7 +703,7 @@ test_that("pairwise_comparisons_bin testing two groups", {
701703
702704 # High number needed for testing
703705 test_pasting <- paste_tbl_grp(data = testing_stats )
704- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
706+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
705707 testing_results <- data.frame (
706708 test_pasting ,
707709 ResponseTest = NA_integer_ ,
@@ -720,7 +722,8 @@ test_that("pairwise_comparisons_bin testing two groups", {
720722 group_by(group ) | >
721723 mutate(num_pos = sum(x ), n = n()) | >
722724 group_by(group ,num_pos , n ) | >
723- group_modify( ~ wilson_ci(. $ x , .95 )) | > ungroup() | >
725+ group_modify( ~ wilson_ci(. $ x , .95 ),
726+ sum(. $ x )) | > ungroup() | >
724727 mutate(rr = paste0(num_pos , ' /' , n , ' = ' , stat_paste(mean * 100 ,
725728 lower * 100 ,
726729 upper * 100 ,
@@ -729,9 +732,10 @@ test_that("pairwise_comparisons_bin testing two groups", {
729732
730733 paired_stats <- bind_cols(paired_stats_pre | >
731734 filter(group == ' a' ) | >
732- select(Group1 = group , Group1_rr = rr ), paired_stats_pre | >
735+ select(Group1 = group , Group1_n = n , Group1_rr = rr ),
736+ paired_stats_pre | >
733737 filter(group == ' b' ) | >
734- select(Group2 = group , Group2_rr = rr ))
738+ select(Group2 = group , Group2_n = n , Group2_rr = rr ))
735739
736740
737741 test_pasting <- paste_tbl_grp(data = paired_stats )
@@ -741,8 +745,8 @@ test_that("pairwise_comparisons_bin testing two groups", {
741745 second_name = " Group1" )
742746 expect_false(identical(test_pasting , test_pasting_rev ))
743747
744- names(test_pasting ) <- c(' Comparison' , ' ResponseStats' )
745- names(test_pasting_rev ) <- c(' Comparison' , ' ResponseStats' )
748+ names(test_pasting ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
749+ names(test_pasting_rev ) <- c(' Comparison' , ' SampleSizes ' , ' ResponseStats' )
746750
747751 testing_results <- data.frame (test_pasting ,
748752 ResponseTest = two_samp_bin_test(x = x , y = group , method = ' mcnemar' ),
@@ -778,11 +782,12 @@ test_that("pairwise_test_bin testing 3+ groups", {
778782 ci = wilson_ci(response ),
779783 r1 = sum(response ),
780784 r0 = abs(sum(response - 1 )),
785+ n = n(),
781786 .groups = " keep" ) | >
782787 pivot_wider(id_cols = c(antigen , visitno ),
783788 names_from = group ,
784789 names_prefix = " grp" ,
785- values_from = c(rfraction , ci , r0 , r1 )) | >
790+ values_from = c(rfraction , ci , r0 , r1 , n )) | >
786791 mutate(pval = ifelse(((r0_grp1 == 0 & r0_grp2 == 0 ) | (r1_grp1 == 0 & r1_grp2 == 0 )),
787792 1 ,
788793 as.double(Exact :: exact.test(matrix (c(r1_grp1 ,
@@ -795,6 +800,7 @@ test_that("pairwise_test_bin testing 3+ groups", {
795800 alternative = " two.sided" )$ p.value )),
796801 PerfectSeparation = FALSE ,
797802 Comparison = " 1 vs. 2" ,
803+ SampleSizes = paste0(n_grp1 , " vs. " , n_grp2 ),
798804 ResponseStats = paste0(rfraction_grp1 ,
799805 " = " ,
800806 round_away_0(ci_grp1 $ mean * 100 , 1 , trailing_zeros = TRUE ),
@@ -811,7 +817,7 @@ test_that("pairwise_test_bin testing 3+ groups", {
811817 " %, " ,
812818 round_away_0(ci_grp2 $ upper * 100 , 1 , trailing_zeros = TRUE ),
813819 " %)" )) | >
814- select(antigen , visitno , Comparison , ResponseStats , ResponseTest = pval , PerfectSeparation )
820+ select(antigen , visitno , Comparison , SampleSizes , ResponseStats , ResponseTest = pval , PerfectSeparation )
815821
816822 function_obj <- exampleData_BAMA | >
817823 group_by(antigen , visitno ) | >
0 commit comments