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: 15 × 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                 15       0.15         9        0.09         10         0.1 
#>  2 b                  5       0.05        11        0.11         14         0.14
#>  3 c                  6       0.06        11        0.11          7         0.07
#>  4 d                  6       0.06        11        0.11          4         0.04
#>  5 a & b              2       0.02         6        0.06          2         0.02
#>  6 a & c              3       0.03         0        0             2         0.02
#>  7 b & c              3       0.03         2        0.02          1         0.01
#>  8 a & d              0       0            2        0.02          2         0.02
#>  9 b & d              1       0.01         0        0             0         0   
#> 10 c & d              1       0.01         2        0.02          1         0.01
#> 11 a & b & c          0       0            1        0.01          3         0.03
#> 12 a & b & d          1       0.01         0        0             0         0   
#> 13 b & c & d          1       0.01         0        0             0         0   
#> 14 a & b & c …        1       0.01         0        0             0         0   
#> 15 None              55       0.55        45        0.45         54         0.54

Long

nsSank::sankey_table_maker(id_data, cohort, wide = F)
#> # A tibble: 45 × 4
#>    state stage     n   pct
#>    <fct> <chr> <dbl> <dbl>
#>  1 a     0        15  0.15
#>  2 a     90        9  0.09
#>  3 a     180      10  0.1 
#>  4 b     0         5  0.05
#>  5 b     90       11  0.11
#>  6 b     180      14  0.14
#>  7 c     0         6  0.06
#>  8 c     90       11  0.11
#>  9 c     180       7  0.07
#> 10 d     0         6  0.06
#> # … with 35 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                  20       0.2          7        0.07          7         0.07
#> 2 b                   8       0.08        12        0.12          9         0.09
#> 3 c                   9       0.09        11        0.11          2         0.02
#> 4 d                   8       0.08         7        0.07          3         0.03
#> 5 None               55       0.55        34        0.34         29         0.29
#> 6 Death               0       0            5        0.05          9         0.09
#> 7 Admin Censo…        0       0           24        0.24         41         0.41