Summary Tables
You can make different summary tables of your data using the package SummaryTables
. SummaryTables
supports HTML and LaTeX output.
To write an output from a SummaryTables
function to a file, you can show
it with the correct MIME
type:
tbl = table_one(...)
# save as HTML
open("tbl.html", "w") do io
show(io, MIME"text/html"(), tbl)
end
# save as LaTeX code
open("tbl.tex", "w") do io
show(io, MIME"text/latex"(), tbl)
end
table_one
SummaryTables.table_one
— Functiontable_one(table, analyses; keywords...)
Construct a "Table 1" which summarises the patient baseline characteristics from the provided table
dataset. This table is commonly used in biomedical research papers.
It can handle both continuous and categorical columns in table
and summary statistics and hypothesis testing are able to be customised by the user. Tables can be stratified by one, or more, variables using the groupby
keyword.
Keywords
groupby
: Which columns to stratify the dataset with, as aVector{Symbol}
.nonnormal
: A vector of column names where hypothesis tests for the:nonnormal
type are chosen.minmax
: A vector of column names where hypothesis tests for the:minmax
type are chosen.tests
: aNamedTuple
of hypothesis test types to use forcategorical
,nonnormal
,minmax
, andnormal
variables.combine
: an object fromMultipleTesting
to use when combining p-values.show_overall
: display the "Overall" column summary. Default istrue
.show_n
: Display the number of rows for each group key next to its label.show_pvalues
: display theP-Value
column. Default isfalse
.show_testnames
: display theTest
column. Default isfalse
.show_confints
: display theCI
column. Default isfalse
.sort
: Sort the input table before grouping. Default istrue
. Pre-sort as desired and set tofalse
when you want to maintain a specific group order or are using non-sortable objects as group keys.
All other keywords are forwarded to the Table
constructor, refer to its docstring for details.
Example with table_one
using SummaryTables
using Statistics
tbl = [
:id => [1, 2, 3, 4, 5, 6, 7, 8],
:sex => ["m", "f", "m", "f", "m", "f", "m", "f"],
:age => [14, 36, 35, 63, 83, 23, 24, 26],
:wgt => [52.3, 65.8, missing, 34.2, 80.2, 77.9, 55.0, 66.7],
:dose => [50, 50, 50, 50, 100, 100, 100, 100],
:group => [1, 1, 1, 1, 2, 2, 2, 2],
]
table_one(
tbl,
[:sex => "Sex", :age => "Age (years)", :wgt => "Weight (kg)"];
groupby = :group,
)
group | |||
Overall | 1 | 2 | |
Sex | |||
f | 4 (50%) | 2 (50%) | 2 (50%) |
m | 4 (50%) | 2 (50%) | 2 (50%) |
Age (years) | |||
Mean (SD) | 38 (23.3) | 37 (20.1) | 39 (29.4) |
Median [Min, Max] | 30.5 [14, 83] | 35.5 [14, 63] | 25 [23, 83] |
Weight (kg) | |||
Mean (SD) | 61.7 (16) | 50.8 (15.9) | 70 (11.6) |
Median [Min, Max] | 65.8 [34.2, 80.2] | 52.3 [34.2, 65.8] | 72.3 [55, 80.2] |
Missing | 1 (12.5%) | 1 (25%) | 0 (0%) |
listingtable
SummaryTables.listingtable
— Functionlistingtable(table, variable;
rows = [],
cols = [],
summarize_rows = [],
summarize_cols = [],
variable_header = true,
celltable_kws...
)
Create a listing table Table
from table
which displays raw values from column variable
.
Arguments
table
: Data source which must be convertible to aDataFrames.DataFrame
.variable
: Determines which variable's raw values are shown. Can either be aSymbol
such as:ColumnA
, or alternatively aPair
where the second element is the display name, such as:ColumnA => "Column A"
.
Keyword arguments
rows = []
: Grouping structure along the rows. Should be aVector
where each element is a grouping variable, specified as aSymbol
such as:Column1
, or aPair
, where the first element is the symbol and the second a display name, such as:Column1 => "Column 1"
. Specifying multiple grouping variables creates nested groups, with the last variable changing the fastest.cols = []
: Grouping structure along the columns. Follows the same structure asrows
.summarize_rows = []
: Specifies functions to summarizevariable
with along the rows. Should be aVector
, where each entry is one separate summary. Each summary can be given as aFunction
such asmean
ormaximum
, in which case the display name is the function's name. Alternatively, a display name can be given using the pair syntax, such asmean => "Average"
. By default, one summary is computed over all groups. You can also passSymbol => [...]
whereSymbol
is a grouping column, to compute one summary for each level of that group.summarize_cols = []
: Specifies functions to summarizevariable
with along the columns. Follows the same structure assummarize_rows
.variable_header = true
: Controls if the cell with the name of the summarizedvariable
is shown.sort = true
: Sort the input table before grouping. Pre-sort as desired and set tofalse
when you want to maintain a specific group order or are using non-sortable objects as group keys.
All other keywords are forwarded to the Table
constructor, refer to its docstring for details.
Example
using Statistics
tbl = [
:Apples => [1, 2, 3, 4, 5, 6, 7, 8],
:Batch => [1, 1, 1, 1, 2, 2, 2, 2],
:Checked => [true, false, true, false, true, false, true, false],
:Delivery => ['a', 'a', 'b', 'b', 'a', 'a', 'b', 'b'],
]
listingtable(
tbl,
:Apples => "Number of apples",
rows = [:Batch, :Checked => "Checked for spots"],
cols = [:Delivery],
summarize_cols = [sum => "overall"],
summarize_rows = :Batch => [mean => "average", sum]
)
Example with listingtable
listingtable(
tbl,
:wgt => "Weight (kg)";
rows = [:dose => "Dose (mg)", :sex => "Sex", :id => "ID"],
summarize_rows = :sex =>
[mean ∘ skipmissing => "Mean", (x -> count(!ismissing, x)) => "Nonmissing"],
)
Dose (mg) | Sex | ID | Weight (kg) |
50 | f | 2 | 65.8 |
4 | 34.2 | ||
Mean | 50 | ||
Nonmissing | 2 | ||
50 | m | 1 | 52.3 |
3 | missing | ||
Mean | 52.3 | ||
Nonmissing | 1 | ||
100 | f | 6 | 77.9 |
8 | 66.7 | ||
Mean | 72.3 | ||
Nonmissing | 2 | ||
100 | m | 5 | 80.2 |
7 | 55 | ||
Mean | 67.6 | ||
Nonmissing | 2 | ||
summarytable
SummaryTables.summarytable
— Functionsummarytable(table, variable;
rows = [],
cols = [],
summary = [],
variable_header = true,
celltable_kws...
)
Create a summary table Table
from table
, which summarizes values from column variable
.
Arguments
table
: Data source which must be convertible to aDataFrames.DataFrame
.variable
: Determines which variable fromtable
is summarized. Can either be aSymbol
such as:ColumnA
, or alternatively aPair
where the second element is the display name, such as:ColumnA => "Column A"
.
Keyword arguments
rows = []
: Grouping structure along the rows. Should be aVector
where each element is a grouping variable, specified as aSymbol
such as:Column1
, or aPair
, where the first element is the symbol and the second a display name, such as:Column1 => "Column 1"
. Specifying multiple grouping variables creates nested groups, with the last variable changing the fastest.cols = []
: Grouping structure along the columns. Follows the same structure asrows
.summary = []
: Specifies functions to summarizevariable
with. Should be aVector
, where each entry is one separate summary. Each summary can be given as aFunction
such asmean
ormaximum
, in which case the display name is the function's name. Alternatively, a display name can be given using the pair syntax, such asmean => "Average"
. By default, one summary is computed over all groups. You can also passSymbol => [...]
whereSymbol
is a grouping column, to compute one summary for each level of that group.variable_header = true
: Controls if the cell with the name of the summarizedvariable
is shown.sort = true
: Sort the input table before grouping. Pre-sort as desired and set tofalse
when you want to maintain a specific group order or are using non-sortable objects as group keys.
All other keywords are forwarded to the Table
constructor, refer to its docstring for details.
Example
using Statistics
tbl = [
:Apples => [1, 2, 3, 4, 5, 6, 7, 8],
:Batch => [1, 1, 1, 1, 2, 2, 2, 2],
:Delivery => ['a', 'a', 'b', 'b', 'a', 'a', 'b', 'b'],
]
summarytable(
tbl,
:Apples => "Number of apples",
rows = [:Batch],
cols = [:Delivery],
summary = [length => "N", mean => "average", sum]
)
Example with summarytable
summarytable(
tbl,
:wgt => "Weight (kg)";
rows = [:sex => "Sex"],
cols = [:dose => "Dose (mg)"],
summary = [mean ∘ skipmissing => "Mean", (x -> count(!ismissing, x)) => "Nonmissing"],
)
Dose (mg) | |||
50 | 100 | ||
Sex | Weight (kg) | ||
f | Mean | 50 | 72.3 |
Nonmissing | 2 | 2 | |
m | Mean | 52.3 | 67.6 |
Nonmissing | 1 | 2 | |