Counting Patients Summing Exposure Across All Patients in Columns
Source:R/summarize_patients_exposure_in_cols.R
summarize_patients_exposure_in_cols.Rd
Counting the number of patients and summing analysis value (i.e exposure values) across all patients when a column table layout is required.
Usage
s_count_patients_sum_exposure(
df,
.var = "AVAL",
id = "USUBJID",
labelstr = "",
.N_col,
custom_label = NULL
)
summarize_patients_exposure_in_cols(
lyt,
var,
...,
.stats = c("n_patients", "sum_exposure"),
.labels = c(n_patients = "Patients", sum_exposure = "Person time"),
.indent_mods = NULL,
col_split = TRUE
)
Arguments
- df
(
data.frame
)
data set containing all analysis variables.- .var, var
(
string
)
single variable name that is passed byrtables
when requested by a statistics function.- id
(
string
)
subject variable name.- labelstr
(
character
)
label of the level of the parent split currently being summarized (must be present as second argument in Content Row Functions).- .N_col
(
count
)
row-wise N (row group count) for the group of observations being analyzed (i.e. with no column-based subsetting) that is passed byrtables
.- custom_label
(
string
orNULL
)
if provided andlabelstr
is empty then this will be used as label.- lyt
(
layout
)
input layout where analyses will be added to.- ...
additional arguments for the lower level functions.
- .stats
(
character
)
statistics to select for the table.- .labels
(named
character
)
labels for the statistics (without indent).- .indent_mods
(named
integer
)
indent modifiers for the labels.- col_split
(
flag
)
whether the columns should be split. Set toFALSE
when the required column split has been done already earlier in the layout pipe.
Value
s_count_patients_sum_exposure()
returns a list with the statistics:
- n_patients
number of unique patients in
df
.- sum_exposure
sum of
.var
across all patients indf
.
Functions
s_count_patients_sum_exposure()
: Statistics function which counts numbers of patients and the sum of exposure across all patients.summarize_patients_exposure_in_cols()
: Layout creating function which adds the count statistics of patients and the sum of analysis value in the column layout as content rows.
Examples
set.seed(1)
df <- data.frame(
USUBJID = c(paste("id", seq(1, 12), sep = "")),
ARMCD = c(rep("ARM A", 6), rep("ARM B", 6)),
SEX = c(rep("Female", 6), rep("Male", 6)),
AVAL = as.numeric(sample(seq(1, 20), 12)),
stringsAsFactors = TRUE
)
adsl <- data.frame(
USUBJID = c(paste("id", seq(1, 12), sep = "")),
ARMCD = c(rep("ARM A", 2), rep("ARM B", 2)),
SEX = c(rep("Female", 2), rep("Male", 2)),
stringsAsFactors = TRUE
)
# Internal function - s_count_patients_sum_exposure
if (FALSE) {
s_count_patients_sum_exposure(df = df, .N_col = nrow(adsl))
s_count_patients_sum_exposure(
df = df,
.N_col = nrow(adsl),
custom_label = "some user's custom label"
)
}
lyt <- basic_table() %>%
split_cols_by("ARMCD", split_fun = add_overall_level("Total", first = FALSE)) %>%
summarize_patients_exposure_in_cols(var = "AVAL", col_split = TRUE) %>%
split_rows_by("SEX") %>%
summarize_patients_exposure_in_cols(var = "AVAL", col_split = FALSE)
result <- build_table(lyt, df = df, alt_counts_df = adsl)
result
#> ARM A ARM B Total
#> Patients Person time Patients Person time Patients Person time
#> ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
#> Total patients numbers/person time 6 (100.0%) 46 6 (100.0%) 68 12 (100.0%) 114
#> Female 6 (100.0%) 46 0 (0.0%) 0 6 (50.0%) 46
#> Male 0 (0.0%) 0 6 (100.0%) 68 6 (50.0%) 68
lyt2 <- basic_table() %>%
split_cols_by("ARMCD", split_fun = add_overall_level("Total", first = FALSE)) %>%
summarize_patients_exposure_in_cols(
var = "AVAL", col_split = TRUE,
.stats = "n_patients", custom_label = "some custom label"
) %>%
split_rows_by("SEX") %>%
summarize_patients_exposure_in_cols(var = "AVAL", col_split = FALSE)
result2 <- build_table(lyt2, df = df, alt_counts_df = adsl)
result2
#> ARM A ARM B Total
#> Patients Patients Patients
#> —————————————————————————————————————————————————————————
#> some custom label 6 (100.0%) 6 (100.0%) 12 (100.0%)
#> Female 6 (100.0%) 0 6 (50.0%)
#> Male 0 (0.0%) 68 6 (50.0%)
lyt3 <- basic_table() %>%
summarize_patients_exposure_in_cols(var = "AVAL", col_split = TRUE)
result3 <- build_table(lyt3, df = df, alt_counts_df = adsl)
result3
#> Patients Person time
#> ——————————————————————————————————————————————————————————————
#> Total patients numbers/person time 12 (100.0%) 114
lyt4 <- basic_table() %>%
summarize_patients_exposure_in_cols(var = "AVAL", col_split = TRUE, .stats = "sum_exposure")
result4 <- build_table(lyt4, df = df, alt_counts_df = adsl)
result4
#> Person time
#> ————————————————————————————————————————————————
#> Total patients numbers/person time 114