Compute summary statistics for a specific dataset and variables of interest
computeSummaryStatisticsTable(
data,
var = NULL,
varFlag = NULL,
varInclude0 = FALSE,
varLab = NULL,
varLabInclude = length(var) > 1,
varGeneralLab = "Variable",
varSubgroupLab = "Variable group",
varIgnore = NULL,
varIncludeTotal = FALSE,
varTotalInclude = FALSE,
varTotalInSepRow = FALSE,
colVar = NULL,
colVarDataLevels = NULL,
colVarTotal = colVar,
colVarTotalPerc = colVarTotal,
colTotalInclude = FALSE,
colTotalLab = "Total",
colInclude0 = FALSE,
rowVar = NULL,
rowVarDataLevels = NULL,
rowVarLab = NULL,
rowOrder = "auto",
rowOrderTotalFilterFct = NULL,
rowOrderCatLast = NULL,
rowVarTotalInclude = NULL,
rowVarTotalInSepRow = NULL,
rowVarTotalByVar = NULL,
rowVarTotalPerc = NULL,
rowInclude0 = FALSE,
type = "auto",
subjectVar = "USUBJID",
dataTotal = NULL,
dataTotalPerc = dataTotal,
dataTotalRow = NULL,
dataTotalCol = NULL,
stats = NULL,
statsVarBy = NULL,
statsExtra = NULL,
statsGeneralLab = "Statistic",
statsPerc = c("statN", "statm"),
filterFct = NULL,
labelVars = NULL,
byVar = NULL,
byVarLab = NULL,
checkVarDiffBySubj = "error"
)
An object summaryTable
or list of such objects if
byVar
is specified.
Data.frame with dataset to consider for the summary table.
Character vector with variable(s) of data
,
to compute statistics on.
If NULL (by default), counts by row/column variable(s) are computed.
To also return counts of the rowVar
in case other var
are specified, you can include: 'all' in the var
.
Missing values, if present, are filtered
(also for the report of number of subjects/records).
Character vector, subset of var
with variable(s)
of type 'flag' (with 'Y', 'N' or '' for empty/non specified value).
Only the counts for records flagged (with 'Y') are retained.
Logical, should rows with no counts
for the count var
or varFlag
variable(s)
be included in the table?
Either:
logical of length 1, if TRUE (FALSE by default)
rows with no count are included for all var
a character vector containing categorical var
for which zero counts rows should be included
Named character vector with label for each variable
specified in var
.
By default, extracted from the labelVars
.
if not available, var
is used.
Logical, if TRUE
the name of the summary statistic variable(s) (var
)
are included in the table.
This is automatically set to TRUE if more than one variable(s)
and is specified, and FALSE if only one variable is specified.
String with general label for variable specified in var
.
In case of multiple variable in var
, this will be included in the table header
(see 'rowVarLab' attribute of the output).
String with general label for sub-group of categorical variable(s) for count table, 'Variable group' by default. This will be included in the final table header (see 'rowVarLab' attribute of the output).
Vector with elements to ignore in the var
variable(s).
The data
records with such elements in var
are filtered from the data
at the start of the workflow.
This argument is deprecated, please use: 'varTotalInclude' instead.
Should the total across all categories of var
be included for the count table?
Only used for categorical variables (and var
not 'all').
Either:
logical of length 1, if TRUE (FALSE by default) include the total for all categorical var
a character vector containing categorical var
for which the total should be included
Logical, should the total per variable be included in a separated row (by default) or in the row containing the header of the variable?
Character vector with variable(s) to be included in columns.
If multiple variables are specified, the variables should
be sorted in hierarchical order,
and are included in multi-columns layout.
Use: 'variable' to include the variables to summarize: var
(if multiple) in different columns.
Data.frame with unique combinations of colVar
to be included in columns.
Each column should correspond to colVar
and as factor
if the elements should be ordered in the final table.
String with column(s) considered to compute the total by,
reported in the header of the table, by default same as colVar
.
Use: 'variable' to compute total by var
(if multiple).
String with column(s) considered to compute the total by,
used as denominator for the percentage computation, by default same as colVarTotal
.
Use: 'variable' to compute total by var
(if multiple).
Logical, if TRUE (FALSE by default) include the summary statistics across columns in a separated column.
String, label for the total column 'Total' by default.
Logical, if TRUE (FALSE by default),
include columns with no records, based on all combinations
of the columnVar
(assuming nested variable(s)).
If variable(s) are not nested, possible combinations
can be specified via colVarDataLevels
.
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table.
Data.frame with unique combinations of rowVar
to be included in columns.
Each column should correspond to colVar
and as factor
if the elements should be ordered in the final table.
Named character vector with
label for the rowVar
variable(s).
Specify how the rows should be ordered in the final table, either a:
String among:
'auto' (by default): if the variable is a factor, keep its order, otherwise order alphabetically
'alphabetical': order alphabetically
'total': order rows in decreasing order of the total number of subjects across all columns for this specific category.
Function with input the summary table and output the ordered elements of the rowVar
To specify different ordering methods for different rowVar
, specify a list
of such elements, named with the rowVar
variable.
For the table output of computeSummaryStatisticsTable
(long format),
this order is also reflected in the levels
of the row factor variable.
Function used to filter the data used to order the rows
based on total counts (in case rowOrder
is 'total'),
To order rows based on one specific column category,
e.g. to order based on the counts in the treatment column:
function(x) subset(x, TRTP == "treatmentX")
String with category to be printed in the last
row of each rowVar
(if any, set to NULL if none).
Character vector with rowVar
for which the total should be reported.
If the higher row variable is specified, the total across all rows
is reported.
For the export, these variable(s) are formatted as factor with
'Total' as the first level.
Character vector with rowVarTotalInclude
(not in rowVarInSepCol
) for which the total should be included in a separated row labelled 'Total'.
Otherwise (by default) the total is included in the header row of each category.
Character vector with a row variable
used to categorize the row total.
Note that this is only used if row total(s) is/are requested via rowVarTotalInclude
,
and this variable should also be included in rowVar
.
This can be specified also for a specific row variable if the vector is named.
For example: c(ADECOD = "AESEV")
to compute total by severity
for row adverse event term in a typical adverse event count table
(by System Organ Class and Adverse Event Term).
Character vector with row variables by which the total
should be computed for the denominator for the percentage computation.
By default the total is only computed only by column (NULL by default).
If the total should be based on the total number of records per variable,
rowVarTotalPerc
should be set to 'variable'.
Logical, if TRUE (FALSE by default),
include rows with no records, based on all combinations
of the rowVar
(assuming nested variable(s)).
String with type of table:
'summaryTable': summary table with statistics for numeric variable
'countTable': count table
'auto' (by default): 'summaryTable' if the variable is numeric, 'countTable' otherwise
String, variable of data
with subject ID,
'USUBJID' by default.
Data.frame used to extract the Total number of subject
per column in column header ('N = [X]').
It should contain the variables specified by colVarTotal
.
If not specified, the total number of subjects is extracted from the data
.
Data.frame used to extract the total counts per column
for the computation of the percentage.
By default, dataTotal
is used.
It should contain the variables specified by colVarTotalPerc
.
Data.frame used to extract the total count across all
elements of the row
variable, list of such data.frame for each rowVar
variable.
If the dataset is specified by row variable, the list should be named with:
variable X if the total across elements of variable X should be included.
By default, data
is used.
Data.frame from which the total across columns is
extracted (in case colTotalInclude
is TRUE)
or list of such data.frame for each rowVar
variable.
If the dataset is specified by row variable, the list should be named with:
with:
last row variable: for the dataset used in the total column for the most nested row variable
higher row variable (X+1): for the dataset used for the total column and row total of X
'total': for the dataset used for the total column and general row total
If only a subset of the variables is specified in this list,
data
is used for the remaining variable(s) (or 'total') if needed.
This dataset (the one for 'total' if a list) is also used for:
the header of the total column in case dataTotal
is
not specified
the denominator of the percentages in the total column
in case dataTotalPerc
is not specified
By default, data
is used.
(optional) Statistic(s) of interest to compute, either:
string with the name of a default set of statistics
available in the package,
see section 'Formatted statistics' in
in-text table statistics
.
See the corresponding type
parameter of the
getStatsData
for more information
on how the statistic is internally extracted.
(expert mode) named list of language object (see is.language
)
of base summary statistics of interest, see section:
'Base statistics' in
in-text table statistics
.
The names are reported in the header.
If stats
if of length 1, the name of the summary statistic is not included
in the table.
The statistics can be specified separately:
for each var
(if multiple),
by naming each element of the list:
list(varName1 = list(...), varName2 = list())
and/or for each element in:
statsVarBy
, by naming each sublist.
String with variable in rowVar
/colVar
which the statistics should be computed by.
In this case, stats
(nested list or not) should be additionally nested
to specify the statistics for each element in statsVarBy
.
(optional) Named list with functions for additional custom
statistics to be computed.
Each function:
has as parameter, either: 'x': the variable (var
) to compute
the summary statistic on or 'data': the entire dataset
returns the corresponding summary statistic as a numeric vector
For example, to additionally compute the coefficient of variation, this can be set to:
list(statCVPerc = function(x) sd(x)/mean(x)*100)
(or cv
).
String with general label for statistics, 'Statistic' by default.
Only included if no statsVar
if longer than 1.
String with 'base statistical variable' used to compute the percentage, either:
'statN' (by default): the number of subjects
'statm': the number of records
(optional) Function taking as input
the summary table with computed statistics and returning a subset
of the summary table.
Note: The filtering function should also handle records with :
total for the column header: isTotal
set to TRUE,
and colVar
/rowVar
is NA.
For example: filterFct = function(data) subset(data, isTotal & myColVar == "group 1")
rowVar
/colVar
set to 'Total'/colTotalLab
if rowVarTotalInclude
/colTotalInclude
is specified
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize.
Labels specified via dedicated parameter: e.g.
rowVarLab
, colVarLab
, varLab
have priority on this parameter.
Variable(s) of data
for which separated table(s)
should be created.
String with label for byVar
, used to set the names
of the output list of table(s).
String, 'error' (default), 'warning',
or 'none'.
Should an error, a warning, or nothing be produced
if a continuous variable (var
) contains
different values for the same subject (by row/column)?
Laure Cougnaud