One call in place of the usual multi-step rtables/tern pipeline: split adsl into columns by treatment, add the population denominator, and summarise each variable with the statistics appropriate to its type – n / mean (SD) / median / range for numeric variables, count and percent for categorical ones – decided automatically by tern::analyze_vars().

tab_demographics(adsl, by = "TRT01P", vars = NULL, ...)

Arguments

adsl

Subject-level analysis dataset (one row per subject). Filter it to the analysis population you want reported (e.g. SAFFL == "Y") before calling this function – the column denominators shown in the table header are exactly nrow(adsl) per by group, taken from adsl and nowhere else.

by

Column in adsl used to split the table into columns. Default "TRT01P".

vars

Character vector of variables to summarise. Default: the intersection of c("AGE", "SEX", "RACE", "ETHNIC") with the columns present in adsl.

...

Passed on to tern::analyze_vars() – the escape hatch for study-specific statistics, formats, or labels (e.g. .stats =).

Value

An object of class c("sasparity_demographics", "sasparity_table") wrapping an rtables::TableTree. Print it to see the table; access $table for the bare rtables object to hand to rtables::as_html(), r2rtf, etc.

SAS equivalent

A %demog (or site-local %basetable) macro: PROC MEANS for continuous variables and PROC FREQ for categorical ones, stacked by treatment group into the classic Table 14.1.x "Demographic and Baseline Characteristics" display. See parity_note().

Examples

adsl <- sasparity_example("adsl")
adsl <- adsl[adsl$SAFFL == "Y", ]
tab_demographics(adsl)
#> 
#> ── Demographics and Baseline Characteristics ──
#> 
#>  SAS equivalent: %demog macro / PROC MEANS + PROC FREQ by treatment group (Table 14.1.x Demographics)
#>  Denominator: n per column = subjects in `adsl` (10 total)
#>                                    A             B        All Patients
#>                                  (N=5)         (N=5)         (N=10)   
#> ——————————————————————————————————————————————————————————————————————
#> AGE                                                                   
#>   n                                5             5             10     
#>   Mean (SD)                   66.2 (6.5)    64.8 (8.5)     65.5 (7.2) 
#>   Median                         66.0          63.0           64.5    
#>   Min - Max                   58.0 - 74.0   55.0 - 77.0   55.0 - 77.0 
#> SEX                                                                   
#>   n                                5             5             10     
#>   F                             3 (60%)       2 (40%)       5 (50%)   
#>   M                             2 (40%)       3 (60%)       5 (50%)   
#> RACE                                                                  
#>   n                                5             5             10     
#>   ASIAN                         1 (20%)       1 (20%)       2 (20%)   
#>   BLACK OR AFRICAN AMERICAN     1 (20%)       1 (20%)       2 (20%)   
#>   WHITE                         3 (60%)       3 (60%)       6 (60%)   
#> ETHNIC                                                                
#>   n                                5             5             10     
#>   HISPANIC OR LATINO            1 (20%)       1 (20%)       2 (20%)   
#>   NOT HISPANIC OR LATINO        4 (80%)       4 (80%)       8 (80%)   
tab_demographics(adsl, vars = c("AGE", "SEX"))
#> 
#> ── Demographics and Baseline Characteristics ──
#> 
#>  SAS equivalent: %demog macro / PROC MEANS + PROC FREQ by treatment group (Table 14.1.x Demographics)
#>  Denominator: n per column = subjects in `adsl` (10 total)
#>                    A             B        All Patients
#>                  (N=5)         (N=5)         (N=10)   
#> ——————————————————————————————————————————————————————
#> AGE                                                   
#>   n                5             5             10     
#>   Mean (SD)   66.2 (6.5)    64.8 (8.5)     65.5 (7.2) 
#>   Median         66.0          63.0           64.5    
#>   Min - Max   58.0 - 74.0   55.0 - 77.0   55.0 - 77.0 
#> SEX                                                   
#>   n                5             5             10     
#>   F             3 (60%)       2 (40%)       5 (50%)   
#>   M             2 (40%)       3 (60%)       5 (50%)