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.
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 8 0.08 12 0.12 6 0.06
#> 2 b 12 0.12 10 0.1 13 0.13
#> 3 c 9 0.09 8 0.08 13 0.13
#> 4 d 6 0.06 10 0.1 9 0.09
#> 5 a & b 3 0.03 3 0.03 2 0.02
#> 6 a & c 4 0.04 3 0.03 2 0.02
#> 7 b & c 4 0.04 1 0.01 1 0.01
#> 8 a & d 0 0 2 0.02 1 0.01
#> 9 b & d 1 0.01 4 0.04 3 0.03
#> 10 c & d 2 0.02 3 0.03 3 0.03
#> 11 a & b & c 0 0 0 0 1 0.01
#> 12 a & c & d 0 0 1 0.01 0 0
#> 13 b & c & d 1 0.01 0 0 3 0.03
#> 14 a & b & c … 1 0.01 0 0 0 0
#> 15 None 49 0.49 43 0.43 43 0.43
nsSank::sankey_table_maker(id_data, cohort, wide = F)
#> # A tibble: 45 × 4
#> state stage n pct
#> <fct> <chr> <dbl> <dbl>
#> 1 a 0 8 0.08
#> 2 a 90 12 0.12
#> 3 a 180 6 0.06
#> 4 b 0 12 0.12
#> 5 b 90 10 0.1
#> 6 b 180 13 0.13
#> 7 c 0 9 0.09
#> 8 c 90 8 0.08
#> 9 c 180 13 0.13
#> 10 d 0 6 0.06
#> # … with 35 more rows
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 11 0.11 14 0.14 3 0.03
#> 2 b 18 0.18 9 0.09 11 0.11
#> 3 c 14 0.14 8 0.08 11 0.11
#> 4 d 8 0.08 11 0.11 7 0.07
#> 5 None 49 0.49 35 0.35 26 0.26
#> 6 Death 0 0 9 0.09 14 0.14
#> 7 Admin Censo… 0 0 14 0.14 28 0.28