Summary numeric variables in columns
Source:R/summarize_variables_in_cols.R
summarize_variables_in_columns.Rd
Usage
summary_in_cols(x, labelstr = "", custom_label = NULL)
# S3 method for numeric
summary_in_cols(x, labelstr = "", custom_label = NULL, ...)
# S3 method for factor
summary_in_cols(x, labelstr = "", custom_label = NULL, ...)
# S3 method for character
summary_in_cols(x, labelstr = "", custom_label = NULL, ...)
# S3 method for logical
summary_in_cols(x, labelstr = "", custom_label = NULL, ...)
summarize_vars_in_cols(
lyt,
var,
var_type = "numeric",
...,
.stats = c("n", "mean", "sd", "se", "cv", "geom_cv"),
.labels = c(n = "n", mean = "Mean", sd = "SD", se = "SE", cv = "CV (%)", geom_cv =
"CV % Geometric Mean"),
.formats = NULL,
.indent_mods = NULL,
col_split = TRUE
)
Arguments
- x
(
numeric
)
vector of numbers we want to analyze.- labelstr
(
character
)
label of the level of the parent split currently being summarized (must be present as second argument in Content Row Functions).- custom_label
(
string
orNULL
)
if provided andlabelstr
is empty then this will be used as the row label.- ...
additional arguments for the lower level functions.
- lyt
(
layout
)
input layout where analyses will be added to.- var
(
string
)
single variable name that is passed byrtables
when requested by a statistics function.- var_type
Variable type, "numeric" by default.
- .stats
(
character
)
statistics to select for the table.- .labels
(named
character
)
labels for the statistics (without indent).- .formats
(named
character
orlist
)
formats for the statistics.- .indent_mods
(named
integer
)
indent modifiers for the labels.- col_split
(
flag
)
whether the columns should be split.
Value
A named list of all statistics returned by s_summary.numeric()
.
See s_summary.numeric()
to be aware of all available statistics.
A named list of all statistics returned by s_summary.factor()
.
See s_summary.factor()
to be aware of all available statistics.
A named list of all statistics returned by s_summary.character()
.
See s_summary.character()
to be aware of all available statistics.
A named list of all statistics returned by s_summary.logical()
.
See s_summary.logical()
to be aware of all available statistics.
Functions
summary_in_cols()
:summary_in_cols
is a S3 generic function to produce an object description.summary_in_cols(numeric)
: a wrapper ofs_summary.numeric()
function that produces a named list of statistics to include as columns.summary_in_cols(factor)
: a wrapper ofs_summary.factor()
function that produces a named list of statistics to include as columns.summary_in_cols(character)
: a wrapper ofs_summary.character()
function that produces a named list of statistics to include as columns.summary_in_cols(logical)
: a wrapper ofs_summary.logical()
function that produces a named list of statistics to include as columns.summarize_vars_in_cols()
: Layout creating function which can be used for creating summary tables in columns, primarily used for PK data sets.
Examples
library(scda)
library(dplyr)
ADPP <- scda::synthetic_cdisc_data("latest")$adpp %>% h_pkparam_sort()
summary_in_cols(ADPP$AGE, custom_label = "stats")
#> $n
#> n
#> 26268
#> attr(,"label")
#> [1] "stats"
#>
#> $sum
#> sum
#> 916014
#> attr(,"label")
#> [1] "stats"
#>
#> $mean
#> mean
#> 34.87186
#> attr(,"label")
#> [1] "stats"
#>
#> $sd
#> sd
#> 7.364059
#> attr(,"label")
#> [1] "stats"
#>
#> $se
#> se
#> 0.04543638
#> attr(,"label")
#> [1] "stats"
#>
#> $mean_sd
#> mean sd
#> 34.871859 7.364059
#> attr(,"label")
#> [1] "stats"
#>
#> $mean_se
#> mean se
#> 34.87185930 0.04543638
#> attr(,"label")
#> [1] "stats"
#>
#> $mean_ci
#> mean_ci_lwr mean_ci_upr
#> 34.78280 34.96092
#> attr(,"label")
#> [1] "stats"
#>
#> $mean_sei
#> mean_sei_lwr mean_sei_upr
#> 34.82642 34.91730
#> attr(,"label")
#> [1] "stats"
#>
#> $mean_sdi
#> mean_sdi_lwr mean_sdi_upr
#> 27.50780 42.23592
#> attr(,"label")
#> [1] "stats"
#>
#> $mean_pval
#> p_value
#> 0
#> attr(,"label")
#> [1] "stats"
#>
#> $median
#> median
#> 34
#> attr(,"label")
#> [1] "stats"
#>
#> $mad
#> mad
#> 0
#> attr(,"label")
#> [1] "stats"
#>
#> $median_ci
#> median_ci_lwr median_ci_upr
#> 34 34
#> attr(,"conf_level")
#> [1] 0.9509612
#> attr(,"label")
#> [1] "stats"
#>
#> $quantiles
#> quantile_0.25 quantile_0.75
#> 30 39
#> attr(,"label")
#> [1] "stats"
#>
#> $iqr
#> iqr
#> 9
#> attr(,"label")
#> [1] "stats"
#>
#> $range
#> min max
#> 20 69
#> attr(,"label")
#> [1] "stats"
#>
#> $min
#> min
#> 20
#> attr(,"label")
#> [1] "stats"
#>
#> $max
#> max
#> 69
#> attr(,"label")
#> [1] "stats"
#>
#> $cv
#> cv
#> 21.11748
#> attr(,"label")
#> [1] "stats"
#>
#> $geom_mean
#> geom_mean
#> 34.13964
#> attr(,"label")
#> [1] "stats"
#>
#> $geom_mean_ci
#> mean_ci_lwr mean_ci_upr
#> 34.05518 34.22432
#> attr(,"label")
#> [1] "stats"
#>
#> $geom_cv
#> geom_cv
#> 20.7003
#> attr(,"label")
#> [1] "stats"
#>
lyt <- basic_table() %>%
split_rows_by(var = "ARM", label_pos = "topleft") %>%
split_rows_by(var = "SEX", label_pos = "topleft") %>%
summarize_vars_in_cols(var = "AGE", col_split = TRUE)
result <- build_table(lyt = lyt, df = ADPP)
result
#> ARM
#> SEX n Mean SD SE CV (%) CV % Geometric Mean
#> ———————————————————————————————————————————————————————————————————————
#> A: Drug X
#> F 5214 32.8 6.0 0.1 18.5 18.7
#> M 3630 35.2 6.9 0.1 19.6 19.7
#> B: Placebo
#> F 0 NA NA NA NA NA
#> M 0 NA NA NA NA NA
#> C: Combination
#> F 9240 35.2 7.3 0.1 20.8 20.4
#> M 8184 35.7 8.1 0.1 22.7 21.9
# By selecting just some statistics and ad-hoc labels
lyt <- basic_table() %>%
split_rows_by(var = "ARM", label_pos = "topleft") %>%
split_rows_by(var = "SEX", label_pos = "topleft") %>%
summarize_vars_in_cols(
var = "AGE",
.stats = c("n", "cv", "geom_mean", "mean_ci", "median", "min", "max"),
.labels = c(
n = "myN",
cv = "myCV",
geom_mean = "myGeomMean",
mean_ci = "Mean (95%CI)",
median = "Median",
min = "Minimum",
max = "Maximum"
),
col_split = TRUE
)
result <- build_table(lyt = lyt, df = ADPP)
result
#> ARM
#> SEX myN myCV myGeomMean Mean (95%CI) Median Minimum Maximum
#> ———————————————————————————————————————————————————————————————————————————————————————
#> A: Drug X
#> F 5214 18.5 32.2 (32.60, 32.92) 32.0 21.0 47.0
#> M 3630 19.6 34.6 (34.99, 35.44) 34.0 23.0 50.0
#> B: Placebo
#> F 0 NA NA NA NA NA NA
#> M 0 NA NA NA NA NA NA
#> C: Combination
#> F 9240 20.8 34.5 (35.05, 35.35) 35.0 21.0 64.0
#> M 8184 22.7 34.8 (35.52, 35.87) 35.0 20.0 69.0
lyt <- basic_table() %>%
summarize_vars_in_cols(
var = "AGE",
col_split = TRUE,
custom_label = "some custom label"
)
result <- build_table(lyt, df = ADPP)
result
#> n Mean SD SE CV (%) CV % Geometric Mean
#> ———————————————————————————————————————————————————————————————————————————
#> some custom label 26268 34.9 7.4 0.0 21.1 20.7
# PKPT03
lyt <- basic_table() %>%
split_rows_by(var = "TLG_DISPLAY", split_label = "PK Parameter", label_pos = "topleft") %>%
summarize_vars_in_cols(
var = "AVAL",
col_split = TRUE,
.stats = c("n", "mean", "sd", "cv", "geom_mean", "geom_cv", "median", "min", "max"),
.labels = c(
n = "n",
mean = "Mean",
sd = "SD",
cv = "CV (%)",
geom_mean = "Geometric Mean",
geom_cv = "CV % Geometric Mean",
median = "Median",
min = "Minimum",
max = "Maximum"
)
)
result <- build_table(lyt, df = ADPP)
result
#> PK Parameter n Mean SD CV (%) Geometric Mean CV % Geometric Mean Median Minimum Maximum
#> ———————————————————————————————————————————————————————————————————————————————————————————————————————————————
#> Cmax 2388 30.1 6.1 20.4 29.5 22.0 30.1 10.1 48.9
#> AUCinf obs 2388 199.3 39.8 19.9 195.1 21.3 198.6 71.5 323.5
#> CL obs 2388 5.0 1.0 20.0 4.9 21.4 5.0 1.3 8.4
#> Ae 4776 1.6 0.3 20.0 1.5 21.0 1.6 0.6 2.6
#> Fe 4776 15.6 3.1 19.9 15.3 21.2 15.6 4.3 26.4
#> CLR 2388 0.0 0.0 20.2 0.0 21.9 0.0 0.0 0.1
#> Rmax 2388 10.0 2.0 19.5 9.8 20.7 10.0 3.2 17.3
#> Tonset 2388 3.0 0.6 19.8 2.9 21.2 3.0 1.1 5.0
#> RENALCLD 2388 0.0 0.0 19.6 0.0 21.3 0.0 0.0 0.0