Skip to contents

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               11       0.11        14        0.14         11         0.11
#>  2 b                9       0.09         9        0.09         10         0.1 
#>  3 c                9       0.09         7        0.07         13         0.13
#>  4 d                9       0.09        11        0.11          8         0.08
#>  5 a & b            4       0.04         3        0.03          0         0   
#>  6 a & c            2       0.02         3        0.03          1         0.01
#>  7 b & c            1       0.01         3        0.03          4         0.04
#>  8 a & d            2       0.02         1        0.01          1         0.01
#>  9 b & d            2       0.02         1        0.01          1         0.01
#> 10 c & d            0       0            3        0.03          0         0   
#> 11 a & b & c        1       0.01         1        0.01          2         0.02
#> 12 a & b & d        1       0.01         0        0             1         0.01
#> 13 a & c & d        2       0.02         0        0             0         0   
#> 14 b & c & d        2       0.02         2        0.02          3         0.03
#> 15 None            45       0.45        42        0.42         45         0.45

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        11  0.11
#>  2 a     90       14  0.14
#>  3 a     180      11  0.11
#>  4 b     0         9  0.09
#>  5 b     90        9  0.09
#>  6 b     180      10  0.1 
#>  7 c     0         9  0.09
#>  8 c     90        7  0.07
#>  9 c     180      13  0.13
#> 10 d     0         9  0.09
#> # ℹ 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                  15       0.15        14        0.14          7         0.07
#> 2 b                  16       0.16         8        0.08          8         0.08
#> 3 c                  11       0.11        12        0.12         10         0.1 
#> 4 d                  13       0.13        11        0.11          6         0.06
#> 5 None               45       0.45        30        0.3          22         0.22
#> 6 Death               0       0            5        0.05         10         0.1 
#> 7 Admin Censo…        0       0           20        0.2          37         0.37