Overview

The sankey_table_maker function returns all combinations of states present in the data with corresponing counts and formatted percentages. The table can either be returned two ways:

  • “wide” (wide = TRUE): separate columns for each time point’s denominator, n, and formatted percentage.

  • “long” (wide = FALSE): the combinations at each time point are stacked together with a column indicating which ordered time point, and with overall columns for denominator, n, and formatted percentage.

Wide


id_data <- sankey_id_events(cohort, events, stages = c(0, 90, 180))

nsSank::sankey_table_maker(id_data, cohort)
#> # A tibble: 16 × 7
#>    state       time_0_n time_0_pct time_90_n time_90_pct time_180_n time_180_pct
#>    <fct>          <dbl>      <dbl>     <dbl>       <dbl>      <dbl>        <dbl>
#>  1 a                  9       0.09         9        0.09         18         0.18
#>  2 b                 11       0.11        10        0.1           4         0.04
#>  3 c                 19       0.19         6        0.06         10         0.1 
#>  4 d                  7       0.07        14        0.14          9         0.09
#>  5 a & b              5       0.05         4        0.04          2         0.02
#>  6 a & c              1       0.01         3        0.03          2         0.02
#>  7 b & c              2       0.02         3        0.03          3         0.03
#>  8 a & d              2       0.02         2        0.02          4         0.04
#>  9 b & d              2       0.02         5        0.05          3         0.03
#> 10 c & d              3       0.03         2        0.02          2         0.02
#> 11 a & b & c          1       0.01         1        0.01          1         0.01
#> 12 a & b & d          3       0.03         0        0             1         0.01
#> 13 a & c & d          0       0            1        0.01          2         0.02
#> 14 b & c & d          0       0            0        0             2         0.02
#> 15 a & b & c …        1       0.01         0        0             0         0   
#> 16 None              34       0.34        40        0.4          37         0.37

Long

nsSank::sankey_table_maker(id_data, cohort, wide = F)
#> # A tibble: 48 × 4
#>    state stage     n   pct
#>    <fct> <chr> <dbl> <dbl>
#>  1 a     0         9  0.09
#>  2 a     90        9  0.09
#>  3 a     180      18  0.18
#>  4 b     0        11  0.11
#>  5 b     90       10  0.1 
#>  6 b     180       4  0.04
#>  7 c     0        19  0.19
#>  8 c     90        6  0.06
#>  9 c     180      10  0.1 
#> 10 d     0         7  0.07
#> # … with 38 more rows

Censoring and absorbing

Can also specify whether to include censoring or “absorbing” states


id_data <- sankey_id_events(cohort, events, stages = c(0, 90, 180), select_event = "last")

nsSank::sankey_table_maker(id_data, cohort, 
                           censor_vars = c("Admin Censored" = "censor_date"), 
                           absorbing_vars = c("Death" = "death_date"))
#> # A tibble: 7 × 7
#>   state        time_0_n time_0_pct time_90_n time_90_pct time_180_n time_180_pct
#>   <fct>           <dbl>      <dbl>     <dbl>       <dbl>      <dbl>        <dbl>
#> 1 a                  14       0.14         9        0.09         11         0.11
#> 2 b                  20       0.2         10        0.1           3         0.03
#> 3 c                  22       0.22         6        0.06         10         0.1 
#> 4 d                  10       0.1         14        0.14         10         0.1 
#> 5 None               34       0.34        30        0.3          21         0.21
#> 6 Death               0       0            6        0.06          9         0.09
#> 7 Admin Censo…        0       0           25        0.25         36         0.36