tests/testthat/_snaps/count_occurrences.md

s_count_occurrences functions as expected with valid input and default arguments

Code
  res
Output
  $count
  $count$MH1
  [1] 3

  $count$MH2
  [1] 1

  $count$MH3
  [1] 1


  $count_fraction
  $count_fraction$MH1
  [1] 3.00 0.75

  $count_fraction$MH2
  [1] 1.00 0.25

  $count_fraction$MH3
  [1] 1.00 0.25


  $fraction
  $fraction$MH1
    num denom 
      3     4

  $fraction$MH2
    num denom 
      1     4

  $fraction$MH3
    num denom 
      1     4

s_count_occurrences functions as expected when requesting different denominator

Code
  res
Output
  $count
  $count$MH1
  [1] 3

  $count$MH2
  [1] 1

  $count$MH3
  [1] 1


  $count_fraction
  $count_fraction$MH1
  [1] 3 1

  $count_fraction$MH2
  [1] 1.0000000 0.3333333

  $count_fraction$MH3
  [1] 1.0000000 0.3333333


  $fraction
  $fraction$MH1
    num denom 
      3     3

  $fraction$MH2
    num denom 
      1     3

  $fraction$MH3
    num denom 
      1     3

a_count_occurrences works with custom input.

Code
  res
Output
  RowsVerticalSection (in_rows) object print method:
  ----------------------------
      row_name formatted_cell indent_mod  row_label
  1   Level: a              3          1   Level: a
  2      LVL B              1          2      LVL B
  3 Count of c              1          0 Count of c
  4  Missing D              0          3  Missing D
  5   Level: a        3 (60%)          1   Level: a
  6      LVL B        1 (20%)          2      LVL B
  7          c        1 (20%)          0          c
  8  Missing D         0 (0%)          0  Missing D

count_occurrences functions as expected with valid input and default arguments

Code
  res
Output
            A           B    
          (N=5)       (N=4)  
  ———————————————————————————
  MH1   3 (60.0%)   1 (25.0%)
  MH2   1 (20.0%)   2 (50.0%)
  MH3   1 (20.0%)   1 (25.0%)
  MH4       0       1 (25.0%)

count_occurrences functions as expected with label row specified

Code
  res
Output
             all obs 
  ———————————————————
  MH Term            
    MH1     4 (44.4%)
    MH2     3 (33.3%)

count_occurrences works as expected with risk difference column

Code
  res
Output
                  A: Drug X    B: Placebo   C: Combination   Risk Difference (%) (95% CI)
                   (N=202)      (N=177)        (N=162)                 (N=379)           
  ———————————————————————————————————————————————————————————————————————————————————————
  dcd A.1.1.1.1   17 (8.4%)    17 (9.6%)      14 (8.6%)           -1.2 (-7.0 - 4.6)      
  dcd A.1.1.1.2   17 (8.4%)    14 (7.9%)      17 (10.5%)           0.5 (-5.0 - 6.0)      
  dcd B.1.1.1.1   15 (7.4%)    19 (10.7%)     15 (9.3%)           -3.3 (-9.1 - 2.5)      
  dcd B.2.1.2.1   17 (8.4%)    16 (9.0%)      13 (8.0%)           -0.6 (-6.3 - 5.1)      
  dcd B.2.2.3.1   17 (8.4%)    15 (8.5%)      16 (9.9%)           -0.1 (-5.7 - 5.6)      
  dcd C.1.1.1.3   15 (7.4%)    13 (7.3%)      18 (11.1%)           0.1 (-5.2 - 5.4)      
  dcd C.2.1.2.1   20 (9.9%)    14 (7.9%)      10 (6.2%)            2.0 (-3.7 - 7.7)      
  dcd D.1.1.1.1   17 (8.4%)    18 (10.2%)      7 (4.3%)           -1.8 (-7.6 - 4.1)      
  dcd D.1.1.4.2   16 (7.9%)    13 (7.3%)      16 (9.9%)            0.6 (-4.8 - 5.9)      
  dcd D.2.1.5.3   21 (10.4%)   20 (11.3%)     12 (7.4%)           -0.9 (-7.2 - 5.4)
Code
  res
Output
                    A: Drug X      B: Placebo     C: Combination   Risk Difference (%) (95% CI)
                     (N=202)         (N=177)         (N=162)                 (N=379)           
  —————————————————————————————————————————————————————————————————————————————————————————————
  dcd A.1.1.1.1         8              11               11              -2.3 (-6.7 - 2.2)      
  dcd A.1.1.1.2        11              10               13              -0.2 (-4.8 - 4.4)      
  dcd B.1.1.1.1        12              14               11              -2.0 (-7.1 - 3.2)      
  dcd B.2.1.2.1        11              12               9               -1.3 (-6.2 - 3.5)      
  dcd B.2.2.3.1         7               9               15              -1.6 (-5.7 - 2.5)      
  dcd C.1.1.1.3        10              10               16              -0.7 (-5.2 - 3.8)      
  dcd C.2.1.2.1        13              12               7               -0.3 (-5.4 - 4.7)      
  dcd D.1.1.1.1        12              13               6               -1.4 (-6.4 - 3.6)      
  dcd D.1.1.4.2        12               8               15               1.4 (-3.1 - 5.9)      
  dcd D.2.1.5.3        14              16               10              -2.1 (-7.6 - 3.4)      
  dcd A.1.1.1.1     8 (4.0%)        11 (6.2%)       11 (6.8%)           -2.3 (-6.7 - 2.2)      
  dcd A.1.1.1.2     11 (5.4%)       10 (5.6%)       13 (8.0%)           -0.2 (-4.8 - 4.4)      
  dcd B.1.1.1.1     12 (5.9%)       14 (7.9%)       11 (6.8%)           -2.0 (-7.1 - 3.2)      
  dcd B.2.1.2.1     11 (5.4%)       12 (6.8%)        9 (5.6%)           -1.3 (-6.2 - 3.5)      
  dcd B.2.2.3.1     7 (3.5%)        9 (5.1%)        15 (9.3%)           -1.6 (-5.7 - 2.5)      
  dcd C.1.1.1.3     10 (5.0%)       10 (5.6%)       16 (9.9%)           -0.7 (-5.2 - 3.8)      
  dcd C.2.1.2.1     13 (6.4%)       12 (6.8%)        7 (4.3%)           -0.3 (-5.4 - 4.7)      
  dcd D.1.1.1.1     12 (5.9%)       13 (7.3%)        6 (3.7%)           -1.4 (-6.4 - 3.6)      
  dcd D.1.1.4.2     12 (5.9%)       8 (4.5%)        15 (9.3%)            1.4 (-3.1 - 5.9)      
  dcd D.2.1.5.3     14 (6.9%)       16 (9.0%)       10 (6.2%)           -2.1 (-7.6 - 3.4)      
  dcd A.1.1.1.1   8/202 (4.0%)    11/177 (6.2%)   11/162 (6.8%)         -2.3 (-6.7 - 2.2)      
  dcd A.1.1.1.2   11/202 (5.4%)   10/177 (5.6%)   13/162 (8.0%)         -0.2 (-4.8 - 4.4)      
  dcd B.1.1.1.1   12/202 (5.9%)   14/177 (7.9%)   11/162 (6.8%)         -2.0 (-7.1 - 3.2)      
  dcd B.2.1.2.1   11/202 (5.4%)   12/177 (6.8%)    9/162 (5.6%)         -1.3 (-6.2 - 3.5)      
  dcd B.2.2.3.1   7/202 (3.5%)    9/177 (5.1%)    15/162 (9.3%)         -1.6 (-5.7 - 2.5)      
  dcd C.1.1.1.3   10/202 (5.0%)   10/177 (5.6%)   16/162 (9.9%)         -0.7 (-5.2 - 3.8)      
  dcd C.2.1.2.1   13/202 (6.4%)   12/177 (6.8%)    7/162 (4.3%)         -0.3 (-5.4 - 4.7)      
  dcd D.1.1.1.1   12/202 (5.9%)   13/177 (7.3%)    6/162 (3.7%)         -1.4 (-6.4 - 3.6)      
  dcd D.1.1.4.2   12/202 (5.9%)   8/177 (4.5%)    15/162 (9.3%)          1.4 (-3.1 - 5.9)      
  dcd D.2.1.5.3   14/202 (6.9%)   16/177 (9.0%)   10/162 (6.2%)         -2.1 (-7.6 - 3.4)
Code
  res
Output
                                                     F                                                                         M                                   
                  A: Drug X    B: Placebo   C: Combination   Risk Difference (%) (95% CI)   A: Drug X    B: Placebo   C: Combination   Risk Difference (%) (95% CI)
                   (N=122)       (N=97)         (N=98)                 (N=219)                (N=80)       (N=80)         (N=64)                 (N=160)           
  —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  dcd A.1.1.1.1    9 (7.4%)    10 (10.3%)      8 (8.2%)           -2.9 (-10.6 - 4.7)        8 (10.0%)     7 (8.8%)       6 (9.4%)           1.3 (-7.8 - 10.3)      
  dcd A.1.1.1.2    6 (4.9%)     9 (9.3%)      12 (12.2%)          -4.4 (-11.3 - 2.6)        11 (13.8%)    5 (6.2%)       5 (7.8%)           7.5 (-1.7 - 16.7)      
  dcd B.1.1.1.1   11 (9.0%)    10 (10.3%)      7 (7.1%)           -1.3 (-9.2 - 6.6)          4 (5.0%)    9 (11.2%)      8 (12.5%)           -6.2 (-14.7 - 2.2)     
  dcd B.2.1.2.1   10 (8.2%)     7 (7.2%)      10 (10.2%)           1.0 (-6.1 - 8.1)          7 (8.8%)    9 (11.2%)       3 (4.7%)           -2.5 (-11.8 - 6.8)     
  dcd B.2.2.3.1   10 (8.2%)    11 (11.3%)     10 (10.2%)          -3.1 (-11.1 - 4.8)         7 (8.8%)     4 (5.0%)       6 (9.4%)           3.7 (-4.1 - 11.6)      
  dcd C.1.1.1.3   10 (8.2%)     8 (8.2%)      12 (12.2%)          -0.1 (-7.4 - 7.3)          5 (6.2%)     5 (6.2%)       6 (9.4%)            0.0 (-7.5 - 7.5)      
  dcd C.2.1.2.1   13 (10.7%)    6 (6.2%)       6 (6.1%)           4.5 (-2.8 - 11.7)          7 (8.8%)    8 (10.0%)       4 (6.2%)           -1.3 (-10.3 - 7.8)     
  dcd D.1.1.1.1   10 (8.2%)    12 (12.4%)      4 (4.1%)           -4.2 (-12.3 - 4.0)         7 (8.8%)     6 (7.5%)       3 (4.7%)            1.2 (-7.2 - 9.7)      
  dcd D.1.1.4.2   10 (8.2%)     5 (5.2%)       7 (7.1%)            3.0 (-3.5 - 9.6)          6 (7.5%)    8 (10.0%)      9 (14.1%)           -2.5 (-11.2 - 6.2)     
  dcd D.2.1.5.3   12 (9.8%)    10 (10.3%)      9 (9.2%)           -0.5 (-8.5 - 7.6)         9 (11.2%)    10 (12.5%)      3 (4.7%)           -1.2 (-11.3 - 8.8)

summarize_occurrences functions as expected with valid input and default arguments

Code
  res
Output
              A           B    
            (N=5)       (N=4)  
  —————————————————————————————
  F                            
    MH1   1 (20.0%)       0    
    MH2   1 (20.0%)   1 (25.0%)
    MH3       0       1 (25.0%)
    MH4       0       1 (25.0%)
  M                            
    MH1   2 (40.0%)   1 (25.0%)
    MH2       0       1 (25.0%)
    MH3   1 (20.0%)       0

summarize_occurrences works as expected with risk difference column

Code
  res
Output
             A: Drug X   B: Placebo   C: Combination   Risk Difference (%) (95% CI)
              (N=202)     (N=177)        (N=162)                 (N=379)           
  —————————————————————————————————————————————————————————————————————————————————
  F                                                                                
    LOW      12 (5.9%)   11 (6.2%)      10 (6.2%)           -0.3 (-5.1 - 4.6)      
    MEDIUM   11 (5.4%)   13 (7.3%)      10 (6.2%)           -1.9 (-6.9 - 3.1)      
    HIGH     10 (5.0%)    7 (4.0%)       7 (4.3%)            1.0 (-3.2 - 5.1)      
  M                                                                                
    LOW      12 (5.9%)    5 (2.8%)       6 (3.7%)            3.1 (-1.0 - 7.2)      
    MEDIUM   10 (5.0%)    9 (5.1%)       4 (2.5%)           -0.1 (-4.5 - 4.3)      
    HIGH     4 (2.0%)    12 (6.8%)      11 (6.8%)           -4.8 (-9.0 - -0.6)
Code
  res
Output
               A: Drug X      B: Placebo     C: Combination   Risk Difference (%) (95% CI)
                (N=202)         (N=177)         (N=162)                 (N=379)           
  ————————————————————————————————————————————————————————————————————————————————————————
  F                                                                                       
    LOW           10               6               8                1.6 (-2.4 - 5.6)      
    MEDIUM         9              11               9               -1.8 (-6.3 - 2.8)      
    HIGH           6               6               7               -0.4 (-4.0 - 3.1)      
    LOW        10 (5.0%)       6 (3.4%)         8 (4.9%)            1.6 (-2.4 - 5.6)      
    MEDIUM     9 (4.5%)        11 (6.2%)        9 (5.6%)           -1.8 (-6.3 - 2.8)      
    HIGH       6 (3.0%)        6 (3.4%)         7 (4.3%)           -0.4 (-4.0 - 3.1)      
    LOW      10/202 (5.0%)   6/177 (3.4%)     8/162 (4.9%)          1.6 (-2.4 - 5.6)      
    MEDIUM   9/202 (4.5%)    11/177 (6.2%)    9/162 (5.6%)         -1.8 (-6.3 - 2.8)      
    HIGH     6/202 (3.0%)    6/177 (3.4%)     7/162 (4.3%)         -0.4 (-4.0 - 3.1)      
  M                                                                                       
    LOW            7               5               6                0.6 (-2.9 - 4.2)      
    MEDIUM         9               7               4                0.5 (-3.5 - 4.5)      
    HIGH           4              11               8               -4.2 (-8.3 - -0.2)     
    LOW        7 (3.5%)        5 (2.8%)         6 (3.7%)            0.6 (-2.9 - 4.2)      
    MEDIUM     9 (4.5%)        7 (4.0%)         4 (2.5%)            0.5 (-3.5 - 4.5)      
    HIGH       4 (2.0%)        11 (6.2%)        8 (4.9%)           -4.2 (-8.3 - -0.2)     
    LOW      7/202 (3.5%)    5/177 (2.8%)     6/162 (3.7%)          0.6 (-2.9 - 4.2)      
    MEDIUM   9/202 (4.5%)    7/177 (4.0%)     4/162 (2.5%)          0.5 (-3.5 - 4.5)      
    HIGH     4/202 (2.0%)    11/177 (6.2%)    8/162 (4.9%)         -4.2 (-8.3 - -0.2)
Code
  res
Output
                                               A                                                                        B                                                                        C                                   
             A: Drug X   B: Placebo   C: Combination   Risk Difference (%) (95% CI)   A: Drug X   B: Placebo   C: Combination   Risk Difference (%) (95% CI)   A: Drug X   B: Placebo   C: Combination   Risk Difference (%) (95% CI)
              (N=64)       (N=67)         (N=62)                 (N=131)               (N=78)       (N=64)         (N=45)                 (N=142)               (N=60)       (N=46)         (N=55)                 (N=106)           
  ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  F                                                                                                                                                                                                                                  
    LOW      6 (9.4%)     4 (6.0%)       1 (1.6%)           3.4 (-5.7 - 12.5)         3 (3.8%)     5 (7.8%)      6 (13.3%)           -4.0 (-11.8 - 3.9)        3 (5.0%)     2 (4.3%)       3 (5.5%)            0.7 (-7.4 - 8.7)      
    MEDIUM   1 (1.6%)     4 (6.0%)       4 (6.5%)           -4.4 (-10.8 - 2.0)        6 (7.7%)     4 (6.2%)       2 (4.4%)            1.4 (-6.9 - 9.8)         4 (6.7%)    5 (10.9%)       4 (7.3%)           -4.2 (-15.2 - 6.8)     
    HIGH     3 (4.7%)     4 (6.0%)       3 (4.8%)           -1.3 (-9.0 - 6.4)         3 (3.8%)     2 (3.1%)          0                0.7 (-5.3 - 6.8)         4 (6.7%)     1 (2.2%)       4 (7.3%)           4.5 (-3.1 - 12.1)      
  M                                                                                                                                                                                                                                  
    LOW      1 (1.6%)     2 (3.0%)       2 (3.2%)           -1.4 (-6.5 - 3.7)         7 (9.0%)     2 (3.1%)       3 (6.7%)           5.8 (-1.8 - 13.5)         4 (6.7%)     1 (2.2%)       1 (1.8%)           4.5 (-3.1 - 12.1)      
    MEDIUM   5 (7.8%)     2 (3.0%)       1 (1.6%)           4.8 (-2.9 - 12.6)         2 (2.6%)     3 (4.7%)       2 (4.4%)           -2.1 (-8.4 - 4.1)         3 (5.0%)     4 (8.7%)       1 (1.8%)           -3.7 (-13.5 - 6.1)     
    HIGH     2 (3.1%)     5 (7.5%)       5 (8.1%)           -4.3 (-11.9 - 3.3)        2 (2.6%)     5 (7.8%)       3 (6.7%)           -5.2 (-12.7 - 2.2)            0        2 (4.3%)       3 (5.5%)           -4.3 (-10.2 - 1.5)
Code
  res
Output
                                                       Risk Difference (%) (95% CI)   Risk Difference (%) (95% CI)
             A: Drug X   B: Placebo   C: Combination     A: Drug X vs. B: Placebo     A: Drug X vs. C: Combination
              (N=202)     (N=177)        (N=162)                 (N=379)                        (N=364)           
  ————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  F                                                                                                               
    LOW      12 (5.9%)   11 (6.2%)      10 (6.2%)           -0.3 (-5.1 - 4.6)              -0.2 (-5.2 - 4.7)      
    MEDIUM   11 (5.4%)   13 (7.3%)      10 (6.2%)           -1.9 (-6.9 - 3.1)              -0.7 (-5.6 - 4.1)      
    HIGH     10 (5.0%)    7 (4.0%)       7 (4.3%)            1.0 (-3.2 - 5.1)               0.6 (-3.7 - 5.0)      
  M                                                                                                               
    LOW      12 (5.9%)    5 (2.8%)       6 (3.7%)            3.1 (-1.0 - 7.2)               2.2 (-2.1 - 6.6)      
    MEDIUM   10 (5.0%)    9 (5.1%)       4 (2.5%)           -0.1 (-4.5 - 4.3)               2.5 (-1.3 - 6.3)      
    HIGH     4 (2.0%)    12 (6.8%)      11 (6.8%)           -4.8 (-9.0 - -0.6)             -4.8 (-9.1 - -0.5)


Try the tern package in your browser

Any scripts or data that you put into this service are public.

tern documentation built on Sept. 24, 2024, 9:06 a.m.