| ternG | R Documentation |
Creates a grouped summary table with optional statistical testing for group
comparisons. Supports numeric and categorical variables; numeric variables
can be treated as ordinal via force_ordinal. Includes options to
calculate P values and odds ratios. For descriptive
(ungrouped) tables, use ternD.
ternG(
data,
vars = NULL,
exclude_vars = NULL,
group_var,
force_ordinal = NULL,
group_order = NULL,
output_xlsx = NULL,
output_docx = NULL,
OR_col = FALSE,
OR_method = "dynamic",
consider_normality = "ROBUST",
print_normality = FALSE,
show_test = FALSE,
p_digits = 3,
round_intg = FALSE,
smart_rename = TRUE,
insert_subheads = TRUE,
factor_order = "mixed",
table_font_size = 9,
methods_doc = TRUE,
methods_filename = "TernTables_methods.docx",
category_start = NULL,
manual_italic_indent = NULL,
manual_underline = NULL,
indent_info_column = FALSE,
show_total = TRUE,
table_caption = NULL,
table_footnote = NULL,
line_break_header = getOption("TernTables.line_break_header", TRUE),
post_hoc = FALSE
)
data |
Tibble containing all variables. |
vars |
Character vector of variables to summarize. Defaults to all except |
exclude_vars |
Character vector of variable(s) to exclude. |
group_var |
Character, the grouping variable (factor or character with >=2 levels). |
force_ordinal |
Character vector of variables to treat as ordinal (i.e., use medians/IQR and nonparametric tests). |
group_order |
Optional character vector to specify a custom group level order. |
output_xlsx |
Optional filename to export the table as an Excel file. |
output_docx |
Optional filename to export the table as a Word document. |
OR_col |
Logical; if |
OR_method |
Character; controls how odds ratios are calculated when |
consider_normality |
Character or logical; controls how continuous variables are routed to
parametric vs. non-parametric tests.
|
print_normality |
Logical; if |
show_test |
Logical; if |
p_digits |
Integer; number of decimal places for P values (default 3). |
round_intg |
Logical; if |
smart_rename |
Logical; if |
insert_subheads |
Logical; if |
factor_order |
Character; controls the ordering of factor levels in the output.
|
table_font_size |
Numeric; font size for Word document output tables. Default is 9. |
methods_doc |
Logical; if |
methods_filename |
Character; filename for the methods document. Default is |
category_start |
Named character vector specifying where to insert category headers.
Names are the header label text to display; values are the anchor variable – either the
original column name (e.g. |
manual_italic_indent |
Character vector of display variable names (post-cleaning) that should be
formatted as italicized and indented in Word output – matching the appearance of factor sub-category
rows. Has no effect on the returned tibble; only applies when |
manual_underline |
Character vector of display variable names (post-cleaning) that should be
formatted as underlined in Word output – matching the appearance of multi-category variable headers.
Has no effect on the returned tibble; only applies when |
indent_info_column |
Logical; if |
show_total |
Logical; if |
table_caption |
Optional character string for a table caption to display above the table in
the Word document. Rendered as size 11 Arial bold, single-spaced with a small gap before the table.
Default is |
table_footnote |
Optional character string for a footnote to display below the table in the
Word document. Rendered as size 6 Arial italic with a double-bar border above and below.
Default is |
line_break_header |
Logical; if |
post_hoc |
Logical; if |
A tibble with one row per variable (multi-row for multi-level factors), showing summary statistics by group, P values, test type, and optionally odds ratios and total summary column.
data(tern_colon)
# 2-group comparison
ternG(tern_colon, exclude_vars = c("ID"), group_var = "Recurrence",
methods_doc = FALSE)
# 2-group comparison with odds ratios
ternG(tern_colon, exclude_vars = c("ID"), group_var = "Recurrence",
OR_col = TRUE, methods_doc = FALSE)
# 3-group comparison
ternG(tern_colon, exclude_vars = c("ID"), group_var = "Treatment_Arm",
group_order = c("Observation", "Levamisole", "Levamisole + 5FU"),
methods_doc = FALSE)
# Export to Word (writes a file to tempdir)
ternG(tern_colon,
exclude_vars = c("ID"),
group_var = "Recurrence",
OR_col = TRUE,
methods_doc = FALSE,
output_docx = file.path(tempdir(), "comparison.docx"),
category_start = c("Patient Demographics" = "Age (yr)",
"Tumor Characteristics" = "Positive Lymph Nodes (n)"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.