Summary Tables
You can make different summary tables of your data using the package SummaryTables.jl. SummaryTables.jl 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)
endtable_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:nonnormaltype are chosen.minmax: A vector of column names where hypothesis tests for the:minmaxtype are chosen.tests: aNamedTupleof hypothesis test types to use forcategorical,nonnormal,minmax, andnormalvariables.combine: an object fromMultipleTestingto 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-Valuecolumn. Default isfalse.show_testnames: display theTestcolumn. Default isfalse.show_confints: display theCIcolumn. Default isfalse.
All other keywords are forwarded to the CellTable constructor, refer to its docstring for details.
Example
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 CellTable 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 aSymbolsuch as:ColumnA, or alternatively aPairwhere the second element is the display name, such as:ColumnA => "Column A".
Keyword arguments
rows = []: Grouping structure along the rows. Should be aVectorwhere each element is a grouping variable, specified as aSymbolsuch 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 summarizevariablewith along the rows. Should be aVector, where each entry is one separate summary. Each summary can be given as aFunctionsuch asmeanormaximum, 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 => [...]whereSymbolis a grouping column, to compute one summary for each level of that group.summarize_cols = []: Specifies functions to summarizevariablewith along the columns. Follows the same structure assummarize_rows.variable_header = true: Controls if the cell with the name of the summarizedvariableis shown.
All other keywords are forwarded to the CellTable 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
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 CellTable from table, which summarizes values from column variable.
Arguments
table: Data source which must be convertible to aDataFrames.DataFrame.variable: Determines which variable fromtableis summarized. Can either be aSymbolsuch as:ColumnA, or alternatively aPairwhere the second element is the display name, such as:ColumnA => "Column A".
Keyword arguments
rows = []: Grouping structure along the rows. Should be aVectorwhere each element is a grouping variable, specified as aSymbolsuch 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 summarizevariablewith. Should be aVector, where each entry is one separate summary. Each summary can be given as aFunctionsuch asmeanormaximum, 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 => [...]whereSymbolis 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 summarizedvariableis shown.
All other keywords are forwarded to the CellTable 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
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 | |