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               10       0.1         14        0.14          5         0.05
#>  2 b                7       0.07         6        0.06          7         0.07
#>  3 c                9       0.09        13        0.13          9         0.09
#>  4 d                8       0.08         5        0.05         12         0.12
#>  5 a & b            1       0.01         4        0.04          2         0.02
#>  6 a & c            1       0.01         2        0.02          1         0.01
#>  7 b & c            2       0.02         0        0             2         0.02
#>  8 a & d            5       0.05         0        0             2         0.02
#>  9 b & d            1       0.01         4        0.04          2         0.02
#> 10 c & d            6       0.06         1        0.01          0         0   
#> 11 a & b & c        1       0.01         0        0             4         0.04
#> 12 a & b & d        3       0.03         1        0.01          0         0   
#> 13 a & c & d        2       0.02         0        0             3         0.03
#> 14 b & c & d        0       0            2        0.02          0         0   
#> 15 None            44       0.44        48        0.48         51         0.51

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        10  0.1 
#>  2 a     90       14  0.14
#>  3 a     180       5  0.05
#>  4 b     0         7  0.07
#>  5 b     90        6  0.06
#>  6 b     180       7  0.07
#>  7 c     0         9  0.09
#>  8 c     90       13  0.13
#>  9 c     180       9  0.09
#> 10 d     0         8  0.08
#> # ℹ 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        15        0.15         10         0.1 
#> 2 b                  11       0.11         6        0.06         10         0.1 
#> 3 c                  16       0.16        10        0.1           2         0.02
#> 4 d                  14       0.14        10        0.1           9         0.09
#> 5 None               44       0.44        34        0.34         23         0.23
#> 6 Death               0       0            5        0.05          8         0.08
#> 7 Admin Censo…        0       0           20        0.2          38         0.38