lyt <-basic_table(show_colcounts =TRUE) %>%split_cols_by("ACTARM", split_fun =add_overall_level("All Patients", first =FALSE)) %>%count_values("DTHFL",values ="Y",.labels =c(count_fraction ="Total number of deaths"),.formats =c(count_fraction ="xx (xx.x%)") ) %>%analyze_vars(vars =c("DTHCAT"), var_labels =c("Primary Cause of Death"))result <-build_table(lyt, df = adsl)result
A: Drug X B: Placebo C: Combination All Patients
(N=134) (N=134) (N=132) (N=400)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Total number of deaths 25 (18.7%) 23 (17.2%) 22 (16.7%) 70 (17.5%)
Primary Cause of Death
n 25 23 22 70
ADVERSE EVENT 9 (36%) 7 (30.4%) 10 (45.5%) 26 (37.1%)
PROGRESSIVE DISEASE 8 (32%) 6 (26.1%) 6 (27.3%) 20 (28.6%)
OTHER 8 (32%) 10 (43.5%) 6 (27.3%) 24 (34.3%)
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
lyt <-basic_table(show_colcounts =TRUE) %>%split_cols_by("ACTARM", split_fun =add_overall_level("All Patients", first =FALSE)) %>%count_values("DTHFL",values ="Y",.labels =c(count_fraction ="Total number of deaths"),.formats =c(count_fraction ="xx (xx.x%)") ) %>%analyze_vars(vars =c("DTHCAT"), var_labels =c("Primary Cause of Death")) %>%split_rows_by("DTHCAT", split_fun =keep_split_levels("OTHER"), child_labels ="hidden") %>%analyze_vars("DTHCAUS",.stats ="count_fraction",.indent_mods =c("count_fraction"=2L),show_labels ="hidden" ) %>%analyze_vars(vars ="LDDTHGR1",nested =FALSE,var_labels ="Days from last drug administration",show_labels ="visible" ) %>%split_rows_by("LDDTHGR1",split_fun =remove_split_levels("<Missing>"),split_label ="Primary cause by days from last study drug administration",label_pos ="visible" ) %>%analyze_vars("DTHCAT")result <-build_table(lyt, df = adsl) %>%prune_table()result
A: Drug X B: Placebo C: Combination All Patients
(N=134) (N=134) (N=132) (N=400)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Total number of deaths 25 (18.7%) 23 (17.2%) 22 (16.7%) 70 (17.5%)
Primary Cause of Death
n 25 23 22 70
ADVERSE EVENT 9 (36%) 7 (30.4%) 10 (45.5%) 26 (37.1%)
PROGRESSIVE DISEASE 8 (32%) 6 (26.1%) 6 (27.3%) 20 (28.6%)
OTHER 8 (32%) 10 (43.5%) 6 (27.3%) 24 (34.3%)
LOST TO FOLLOW UP 2 (25%) 2 (20%) 2 (33.3%) 6 (25%)
MISSING 2 (25%) 3 (30%) 2 (33.3%) 7 (29.2%)
Post-study reporting of death 1 (12.5%) 2 (20%) 1 (16.7%) 4 (16.7%)
SUICIDE 2 (25%) 2 (20%) 1 (16.7%) 5 (20.8%)
UNKNOWN 1 (12.5%) 1 (10%) 0 2 (8.3%)
Days from last drug administration
n 25 23 22 70
<=30 14 (56%) 11 (47.8%) 14 (63.6%) 39 (55.7%)
>30 11 (44%) 12 (52.2%) 8 (36.4%) 31 (44.3%)
Primary cause by days from last study drug administration
<=30
n 14 11 14 39
ADVERSE EVENT 4 (28.6%) 2 (18.2%) 6 (42.9%) 12 (30.8%)
PROGRESSIVE DISEASE 6 (42.9%) 3 (27.3%) 4 (28.6%) 13 (33.3%)
OTHER 4 (28.6%) 6 (54.5%) 4 (28.6%) 14 (35.9%)
>30
n 11 12 8 31
ADVERSE EVENT 5 (45.5%) 5 (41.7%) 4 (50%) 14 (45.2%)
PROGRESSIVE DISEASE 2 (18.2%) 3 (25%) 2 (25%) 7 (22.6%)
OTHER 4 (36.4%) 4 (33.3%) 2 (25%) 10 (32.3%)
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
dthcaus_levels <-levels(adsl[adsl$DTHCAT =="OTHER", ]$DTHCAUS)lyt <-basic_table(show_colcounts =TRUE) %>%split_cols_by("ACTARM", split_fun =add_overall_level("All Patients", first =FALSE)) %>%count_values("DTHFL",values ="Y",.labels =c(count_fraction ="Total number of deaths"),.formats =c(count_fraction ="xx (xx.x%)") ) %>%analyze_vars(vars =c("DTHCAT"),var_labels =c("Primary Cause of Death"),table_names ="primary_cause" ) %>%split_rows_by("DTHCAT",split_fun =keep_split_levels("OTHER"),child_labels ="hidden" ) %>%count_values("DTHCAUS",values = dthcaus_levels[5],.labels =c(count_fraction ="Post-study reportings of death"),.formats =c(count_fraction ="xx (xx.x%)"),.indent_mods =c(count_fraction =2L),table_names ="post_study_deaths" ) %>%count_values("DTHCAUS",values = dthcaus_levels[-5],.labels =c(count_fraction ="All other causes"),.formats =c(count_fraction ="xx (xx.x%)"),.indent_mods =c(count_fraction =2L),table_names ="all_other_causes" )result <-build_table(lyt, df = adsl)result
A: Drug X B: Placebo C: Combination All Patients
(N=134) (N=134) (N=132) (N=400)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Total number of deaths 25 (18.7%) 23 (17.2%) 22 (16.7%) 70 (17.5%)
Primary Cause of Death
n 25 23 22 70
ADVERSE EVENT 9 (36%) 7 (30.4%) 10 (45.5%) 26 (37.1%)
PROGRESSIVE DISEASE 8 (32%) 6 (26.1%) 6 (27.3%) 20 (28.6%)
OTHER 8 (32%) 10 (43.5%) 6 (27.3%) 24 (34.3%)
Post-study reportings of death 1 (12.5%) 2 (20.0%) 1 (16.7%) 4 (16.7%)
All other causes 7 (87.5%) 8 (80.0%) 5 (83.3%) 20 (83.3%)
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
dthcaus_levels <-levels(adsl[adsl$DTHCAT =="OTHER", ]$DTHCAUS)# create a helper variable DTHCAUS_otheradsl <- adsl %>%mutate(DTHCAUS_other =factor(ifelse( DTHCAT =="OTHER"& DTHCAUS !="Post-study reporting of death", as.character(DTHCAUS), NA ), levels =c("LOST TO FOLLOW UP", "SUICIDE", "UNKNOWN", "MISSING")) %>%explicit_na() )lyt <-basic_table(show_colcounts =TRUE) %>%split_cols_by("ACTARM", split_fun =add_overall_level("All Patients", first =FALSE)) %>%count_values("DTHFL",values ="Y",.labels =c(count_fraction ="Total number of deaths"),.formats =c(count_fraction ="xx (xx.x%)") ) %>%analyze_vars(vars =c("DTHCAT"),var_labels =c("Primary Cause of Death"),table_names ="primary_cause" ) %>%split_rows_by("DTHCAT", split_fun =keep_split_levels("OTHER"), child_labels ="hidden") %>%count_values("DTHCAUS",values = dthcaus_levels[5],.labels =c(count_fraction ="Post-study reportings of death"),.formats =c(count_fraction ="xx (xx.x%)"),.indent_mods =c(count_fraction =2L),table_names ="post_study_deaths" ) %>%count_values("DTHCAUS",values = dthcaus_levels[-5],.labels =c(count_fraction ="All other causes"),.formats =c(count_fraction ="xx (xx.x%)"),.indent_mods =c(count_fraction =2L),table_names ="all_other_causes" ) %>%analyze_vars("DTHCAUS_other",.stats ="count_fraction",.indent_mods =c("count_fraction"=3L),show_labels ="hidden" )result <-build_table(lyt, df = adsl)result
A: Drug X B: Placebo C: Combination All Patients
(N=134) (N=134) (N=132) (N=400)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Total number of deaths 25 (18.7%) 23 (17.2%) 22 (16.7%) 70 (17.5%)
Primary Cause of Death
n 25 23 22 70
ADVERSE EVENT 9 (36%) 7 (30.4%) 10 (45.5%) 26 (37.1%)
PROGRESSIVE DISEASE 8 (32%) 6 (26.1%) 6 (27.3%) 20 (28.6%)
OTHER 8 (32%) 10 (43.5%) 6 (27.3%) 24 (34.3%)
Post-study reportings of death 1 (12.5%) 2 (20.0%) 1 (16.7%) 4 (16.7%)
All other causes 7 (87.5%) 8 (80.0%) 5 (83.3%) 20 (83.3%)
LOST TO FOLLOW UP 2 (28.6%) 2 (25%) 2 (40%) 6 (30%)
SUICIDE 2 (28.6%) 2 (25%) 1 (20%) 5 (25%)
UNKNOWN 1 (14.3%) 1 (12.5%) 0 2 (10%)
MISSING 2 (28.6%) 3 (37.5%) 2 (40%) 7 (35%)
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
Code
library(tern)library(dplyr)adsl <- random.cdisc.data::cadsl# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.adsl <-df_explicit_na(adsl) %>%filter(SAFFL =="Y")# Reorder the levels in "DTHCAT" to put Other category at the end.adsl$DTHCAT <-factor(adsl$DTHCAT, levels =c("ADVERSE EVENT", "PROGRESSIVE DISEASE", "OTHER", "<Missing>"))